lint & format

This commit is contained in:
Adrian Jagielak 2025-07-23 20:38:17 +02:00
parent 8a3f7e72bb
commit 3cbf43f358
No known key found for this signature in database
GPG Key ID: 0818CF7AF6C62BFB
12 changed files with 29 additions and 24 deletions

View File

@ -21,6 +21,13 @@ export default defineConfig([
},
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
},
},
]);

View File

@ -4,7 +4,7 @@
"description": "Home Assistant add-on talking to Futurehome Smarthub via FIMP",
"main": "dist/index.js",
"scripts": {
"lint": "eslint src/**.ts",
"lint": "eslint src/**/*.ts",
"build": "rimraf ./dist && tsc",
"start": "node dist/index.js"
},

View File

@ -2,14 +2,15 @@ import { DemoFimpMqttClient } from "./mqtt/demo_client";
import { IMqttClient } from "./mqtt/interface";
import { RealMqttClient } from "./mqtt/real_client";
export function connectHub(opts: { hubIp: string; username: string; password: string; demo: boolean; }): Promise<IMqttClient> { const url = `mqtt://${opts.hubIp || "futurehome-smarthub.local"}`;
export function connectHub(opts: { hubIp: string; username: string; password: string; demo: boolean; }): Promise<IMqttClient> {
const url = `mqtt://${opts.hubIp}`;
return makeClient(url, 1884, opts.username, opts.password, opts.demo);
}
export async function connectHA(opts: { mqttHost: string; mqttPort: number; mqttUsername: string; mqttPassword: string; }): Promise<{ ha: IMqttClient; retainedMessages: RetainedMessage[] }> {
const url = `mqtt://${opts.mqttHost}`;
let ha = await makeClient(url, opts.mqttPort, opts.mqttUsername, opts.mqttPassword, false);
let retainedMessages = await waitForHARetainedMessages(ha)
const ha = await makeClient(url, opts.mqttPort, opts.mqttUsername, opts.mqttPassword, false);
const retainedMessages = await waitForHARetainedMessages(ha)
return { ha, retainedMessages };
}

View File

@ -60,7 +60,7 @@ export async function sendFimpMsg({
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
fimp?.removeListener('message', onResponse);
let error = new Error(`Timeout waiting for FIMP response (uid: ${uid}, service: ${service}, cmd: ${cmd})`);
const error = new Error(`Timeout waiting for FIMP response (uid: ${uid}, service: ${service}, cmd: ${cmd})`);
log.warn(error.message, error.stack);
reject(error);
}, timeoutMs);
@ -72,7 +72,7 @@ export async function sendFimpMsg({
if (msg.type === 'evt.error.report') {
fimp?.removeListener('message', onResponse);
let error = new Error(`Received FIMP response for message ${uid}: error (evt.error.report) (matched using uid)`);
const error = new Error(`Received FIMP response for message ${uid}: error (evt.error.report) (matched using uid)`);
log.warn(error.message, error.stack);
reject(error);
return;
@ -90,7 +90,7 @@ export async function sendFimpMsg({
if (msg.type === 'evt.error.report') {
fimp?.removeListener('message', onResponse);
let error = new Error(`Received FIMP response for message ${uid}: error (evt.error.report) (matched using topic)`);
const error = new Error(`Received FIMP response for message ${uid}: error (evt.error.report) (matched using topic)`);
log.warn(error.message, error.stack);
reject(error);
return;

View File

@ -33,6 +33,6 @@ export async function getInclusionReport(parameters: { adapterAddress: string; a
return inclusionReport.val;
} catch (e) {
log.error(`Failed getting inclusion report for adapterAddress: ${parameters.adapterAddress}, adapterService: ${parameters.adapterService}, deviceId: ${parameters.deviceId}`)
log.error(`Failed getting inclusion report for adapterAddress: ${parameters.adapterAddress}, adapterService: ${parameters.adapterService}, deviceId: ${parameters.deviceId}`, e)
}
}

View File

@ -8,7 +8,7 @@ export type VinculumPd7Device = {
model?: string | null;
// "Model alias", e.g. "TS0202"
modelAlias?: string | null;
functionality?: 'appliance' | 'climate' | 'energy' | 'ev_charger' | 'lighting' | 'media' | 'other' | 'power' | 'safety' | 'security' | 'shading' | string | null,
functionality?: 'appliance' | 'climate' | 'energy' | 'ev_charger' | 'lighting' | 'media' | 'other' | 'power' | 'safety' | 'security' | 'shading' | string | null;
services?: Record<string, VinculumPd7Service> | null;
type?: {
// User-defined device type (e.g. "sensor", "chargepoint", or "light")

View File

@ -1,4 +1,4 @@
import { InclusionReport, InclusionReportService } from "../fimp/inclusion_report";
import { InclusionReport } from "../fimp/inclusion_report";
import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device";
import { log } from "../logger";
import { battery__components } from "../services/battery";
@ -44,7 +44,7 @@ import { sensor_watflow__components } from "../services/sensor_watflow";
import { sensor_watpressure__components } from "../services/sensor_watpressure";
import { sensor_wattemp__components } from "../services/sensor_wattemp";
import { sensor_weight__components } from "../services/sensor_weight";
import { ha, setHaCommandHandlers } from "./globals";
import { ha } from "./globals";
type HaDeviceConfig = {
// device

View File

@ -82,7 +82,7 @@ const haStateCache: Record<
> = {};
/**
* Publishes the full state of a Futurehome device to Home Assistant and
* Publishes the full state of a Futurehome device to Home Assistant and
* stores a copy in the private cache above.
*
* Example MQTT topic produced for hub 123456 and device id 1:

View File

@ -1,9 +1,6 @@
import { connectHub, connectHA } from "./client";
import { exposeSmarthubTools } from "./admin";
import { log } from "./logger";
import { FimpResponse, sendFimpMsg, setFimp } from "./fimp/fimp";
import { getInclusionReport } from "./fimp/inclusion_report";
import { adapterAddressFromServiceAddress, adapterServiceFromServiceAddress } from "./fimp/helpers";
import { haCommandHandlers, setHa, setHaCommandHandlers } from "./ha/globals";
import { CommandHandlers, haPublishDevice } from "./ha/publish_device";
import { haUpdateState, haUpdateStateSensorReport } from "./ha/update_state";
@ -11,7 +8,7 @@ import { VinculumPd7Device } from "./fimp/vinculum_pd7_device";
import { haUpdateAvailability } from "./ha/update_availability";
(async () => {
const hubIp = process.env.FH_HUB_IP || '';
const hubIp = process.env.FH_HUB_IP || "futurehome-smarthub.local";
const hubUsername = process.env.FH_USERNAME || '';
const hubPassword = process.env.FH_PASSWORD || '';
const demoMode = (process.env.DEMO_MODE || '').toLowerCase().includes('true');
@ -42,7 +39,7 @@ import { haUpdateAvailability } from "./ha/update_availability";
setFimp(fimp);
log.info("Connected to Futurehome hub");
let house = await sendFimpMsg({
const house = await sendFimpMsg({
address: '/rt:app/rn:vinculum/ad:1',
service: 'vinculum',
cmd: 'cmd.pd7.request',
@ -50,9 +47,9 @@ import { haUpdateAvailability } from "./ha/update_availability";
val_t: 'object',
timeoutMs: 30000,
});
let hubId = house.val.param.house.hubId;
const hubId = house.val.param.house.hubId;
let devices = await sendFimpMsg({
const devices = await sendFimpMsg({
address: '/rt:app/rn:vinculum/ad:1',
service: 'vinculum',
cmd: 'cmd.pd7.request',

View File

@ -11,7 +11,7 @@ export class DemoFimpMqttClient implements IMqttClient {
private onceConnectHandlers: (() => void)[] = [];
private onceErrorHandlers: OnErrorCallback[] = [];
connect(url: string, options: {
connect(_url: string, _options: {
port: number;
username: string;
password: string;
@ -23,9 +23,9 @@ export class DemoFimpMqttClient implements IMqttClient {
}
subscribe(topicObject: string, opts?: { qos: 0 | 1 | 2 }, callback?: (err: Error | null) => void): void;
subscribe(topic: string, opts?: any, callback?: any): void { }
subscribe(_topic: string, _opts?: any, _callback?: any): void { }
publish(topic: string, value: string, options: {
publish(topic: string, value: string, _options: {
retain?: boolean;
qos: 0 | 1 | 2;
}): void {

View File

@ -1,4 +1,4 @@
import { connect, IPublishPacket, MqttClient, OnErrorCallback, OnMessageCallback } from 'mqtt';
import { connect, MqttClient, OnErrorCallback, OnMessageCallback } from 'mqtt';
import { IMqttClient } from './interface';
export class RealMqttClient implements IMqttClient {

View File

@ -6,7 +6,7 @@ export function out_bin_switch__components(
topicPrefix: string,
device: VinculumPd7Device,
svc: VinculumPd7Service
): ServiceComponentsCreationResult | undefined {
): ServiceComponentsCreationResult | undefined {
const commandTopic = `${topicPrefix}${svc.addr}/command`;
return {