From 3cbf43f358d7282ff1777157f1d85f65e652b541 Mon Sep 17 00:00:00 2001 From: Adrian Jagielak Date: Wed, 23 Jul 2025 20:38:17 +0200 Subject: [PATCH] lint & format --- futurehome/eslint.config.mjs | 7 +++++++ futurehome/package.json | 2 +- futurehome/src/client.ts | 7 ++++--- futurehome/src/fimp/fimp.ts | 6 +++--- futurehome/src/fimp/inclusion_report.ts | 2 +- futurehome/src/fimp/vinculum_pd7_device.ts | 2 +- futurehome/src/ha/publish_device.ts | 4 ++-- futurehome/src/ha/update_state.ts | 2 +- futurehome/src/index.ts | 11 ++++------- futurehome/src/mqtt/demo_client.ts | 6 +++--- futurehome/src/mqtt/real_client.ts | 2 +- futurehome/src/services/out_bin_switch.ts | 2 +- 12 files changed, 29 insertions(+), 24 deletions(-) diff --git a/futurehome/eslint.config.mjs b/futurehome/eslint.config.mjs index 480bf7e..7ec083c 100644 --- a/futurehome/eslint.config.mjs +++ b/futurehome/eslint.config.mjs @@ -21,6 +21,13 @@ export default defineConfig([ }, rules: { "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + }, + ], }, }, ]); diff --git a/futurehome/package.json b/futurehome/package.json index a21a020..2bceb70 100644 --- a/futurehome/package.json +++ b/futurehome/package.json @@ -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" }, diff --git a/futurehome/src/client.ts b/futurehome/src/client.ts index 8212fca..05d6a1f 100644 --- a/futurehome/src/client.ts +++ b/futurehome/src/client.ts @@ -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 { const url = `mqtt://${opts.hubIp || "futurehome-smarthub.local"}`; +export function connectHub(opts: { hubIp: string; username: string; password: string; demo: boolean; }): Promise { + 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 }; } diff --git a/futurehome/src/fimp/fimp.ts b/futurehome/src/fimp/fimp.ts index 61b8407..7a19526 100644 --- a/futurehome/src/fimp/fimp.ts +++ b/futurehome/src/fimp/fimp.ts @@ -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; diff --git a/futurehome/src/fimp/inclusion_report.ts b/futurehome/src/fimp/inclusion_report.ts index d32d6e6..9ebdfde 100644 --- a/futurehome/src/fimp/inclusion_report.ts +++ b/futurehome/src/fimp/inclusion_report.ts @@ -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) } } diff --git a/futurehome/src/fimp/vinculum_pd7_device.ts b/futurehome/src/fimp/vinculum_pd7_device.ts index 2e7cfa0..04aea72 100644 --- a/futurehome/src/fimp/vinculum_pd7_device.ts +++ b/futurehome/src/fimp/vinculum_pd7_device.ts @@ -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 | null; type?: { // User-defined device type (e.g. "sensor", "chargepoint", or "light") diff --git a/futurehome/src/ha/publish_device.ts b/futurehome/src/ha/publish_device.ts index aac3ba0..7bf7f0c 100644 --- a/futurehome/src/ha/publish_device.ts +++ b/futurehome/src/ha/publish_device.ts @@ -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 diff --git a/futurehome/src/ha/update_state.ts b/futurehome/src/ha/update_state.ts index 3412789..08281e6 100644 --- a/futurehome/src/ha/update_state.ts +++ b/futurehome/src/ha/update_state.ts @@ -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: diff --git a/futurehome/src/index.ts b/futurehome/src/index.ts index 82eed36..a4405a6 100644 --- a/futurehome/src/index.ts +++ b/futurehome/src/index.ts @@ -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', diff --git a/futurehome/src/mqtt/demo_client.ts b/futurehome/src/mqtt/demo_client.ts index 6526f20..033c0c9 100644 --- a/futurehome/src/mqtt/demo_client.ts +++ b/futurehome/src/mqtt/demo_client.ts @@ -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 { diff --git a/futurehome/src/mqtt/real_client.ts b/futurehome/src/mqtt/real_client.ts index 5bc05f4..dcc0366 100644 --- a/futurehome/src/mqtt/real_client.ts +++ b/futurehome/src/mqtt/real_client.ts @@ -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 { diff --git a/futurehome/src/services/out_bin_switch.ts b/futurehome/src/services/out_bin_switch.ts index 88ad5d2..cbfecae 100644 --- a/futurehome/src/services/out_bin_switch.ts +++ b/futurehome/src/services/out_bin_switch.ts @@ -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 {