Add more logging

This commit is contained in:
Adrian Jagielak 2025-07-22 00:25:16 +02:00
parent 77c07fa0ad
commit 6cee45447d
No known key found for this signature in database
GPG Key ID: 0818CF7AF6C62BFB
3 changed files with 19 additions and 6 deletions

View File

@ -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"

View File

@ -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':

View File

@ -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);
}
});