From 6cee45447d18b6264403dd69ae14f0d2a984456c Mon Sep 17 00:00:00 2001 From: Adrian Jagielak Date: Tue, 22 Jul 2025 00:25:16 +0200 Subject: [PATCH] Add more logging --- futurehome/config.yaml | 2 +- futurehome/src/discovery.ts | 1 + futurehome/src/index.ts | 22 +++++++++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/futurehome/config.yaml b/futurehome/config.yaml index 86b3b89..c539448 100644 --- a/futurehome/config.yaml +++ b/futurehome/config.yaml @@ -1,6 +1,6 @@ # https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config name: Futurehome -version: "0.0.10" +version: "0.0.11" slug: futurehome description: Local Futurehome Smarthub integration url: "https://github.com/adrianjagielak/home-assistant-futurehome" diff --git a/futurehome/src/discovery.ts b/futurehome/src/discovery.ts index dbadb53..cceef8a 100644 --- a/futurehome/src/discovery.ts +++ b/futurehome/src/discovery.ts @@ -6,6 +6,7 @@ import { handleTempSensor } from './parsers/sensor_temp'; // map Futurehome → Home Assistant MQTT Discovery export async function publishDiscovery(client: MqttClient, device: any) { + console.log("Publishing a new device", device); for (const svc of device.services) { switch (svc.name) { case 'battery': diff --git a/futurehome/src/index.ts b/futurehome/src/index.ts index 6f491d7..44b52a4 100644 --- a/futurehome/src/index.ts +++ b/futurehome/src/index.ts @@ -3,34 +3,46 @@ import { connectHub, connectHA } from "./client"; import { publishDiscovery } from "./discovery"; (async () => { - const hubIp = process.env.FH_HUB_IP || ""; - const user = process.env.FH_USERNAME || ""; - const pass = process.env.FH_PASSWORD || ""; + const hubIp = process.env.FH_HUB_IP || ""; + const hubUsername = process.env.FH_USERNAME || ""; + const hubPassword = process.env.FH_PASSWORD || ""; const mqttHost = process.env.MQTT_HOST || ""; const mqttPort = Number(process.env.MQTT_PORT || "1883"); const mqttUsername = process.env.MQTT_USER || ""; const mqttPassword = process.env.MQTT_PWD || ""; + console.log("Debug: hub ip", hubIp) + console.log("Debug: hub username", hubUsername) + console.log("Debug: hub password", hubPassword) + console.log("Debug: mqtt host", mqttHost) + console.log("Debug: mqtt port", mqttPort) + console.log("Debug: mqtt username", mqttUsername) + console.log("Debug: mqtt password", mqttPassword) // 1) Connect to HA broker (for discovery + state) + console.log("Connecting to HA broker..."); const ha = await connectHA({ mqttHost, mqttPort, mqttUsername, mqttPassword, }); + console.log("Connected to HA broker"); // 2) Connect to Futurehome hub (FIMP traffic) - const fimp = await connectHub({ hubIp, username: user, password: pass }); + console.log("Connecting to Futurehome hub..."); + const fimp = await connectHub({ hubIp, username: hubUsername, password: hubPassword }); + console.log("Connected to Futurehome hub"); // -- subscribe to FIMP events ----------------------------------------- fimp.subscribe("#"); fimp.on("message", (topic, buf) => { try { const msg = JSON.parse(buf.toString()); + console.debug("Received a FIMP message", topic, msg); if (msg.type === "evt.pd7.response") { const devices = msg.val?.param?.devices ?? []; devices.forEach((d: any) => publishDiscovery(ha, d)); } // …forward state events as needed… } catch (e) { - console.warn("Bad FIMP JSON", e); + console.warn("Bad FIMP JSON", e, topic, buf); } });