mirror of
https://github.com/adrianjagielak/home-assistant-futurehome.git
synced 2025-09-13 15:47:08 +00:00
Add more logging
This commit is contained in:
parent
77c07fa0ad
commit
6cee45447d
@ -1,6 +1,6 @@
|
|||||||
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
|
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
|
||||||
name: Futurehome
|
name: Futurehome
|
||||||
version: "0.0.10"
|
version: "0.0.11"
|
||||||
slug: futurehome
|
slug: futurehome
|
||||||
description: Local Futurehome Smarthub integration
|
description: Local Futurehome Smarthub integration
|
||||||
url: "https://github.com/adrianjagielak/home-assistant-futurehome"
|
url: "https://github.com/adrianjagielak/home-assistant-futurehome"
|
||||||
|
@ -6,6 +6,7 @@ import { handleTempSensor } from './parsers/sensor_temp';
|
|||||||
|
|
||||||
// map Futurehome → Home Assistant MQTT Discovery
|
// map Futurehome → Home Assistant MQTT Discovery
|
||||||
export async function publishDiscovery(client: MqttClient, device: any) {
|
export async function publishDiscovery(client: MqttClient, device: any) {
|
||||||
|
console.log("Publishing a new device", device);
|
||||||
for (const svc of device.services) {
|
for (const svc of device.services) {
|
||||||
switch (svc.name) {
|
switch (svc.name) {
|
||||||
case 'battery':
|
case 'battery':
|
||||||
|
@ -4,33 +4,45 @@ import { publishDiscovery } from "./discovery";
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const hubIp = process.env.FH_HUB_IP || "";
|
const hubIp = process.env.FH_HUB_IP || "";
|
||||||
const user = process.env.FH_USERNAME || "";
|
const hubUsername = process.env.FH_USERNAME || "";
|
||||||
const pass = process.env.FH_PASSWORD || "";
|
const hubPassword = process.env.FH_PASSWORD || "";
|
||||||
|
|
||||||
const mqttHost = process.env.MQTT_HOST || "";
|
const mqttHost = process.env.MQTT_HOST || "";
|
||||||
const mqttPort = Number(process.env.MQTT_PORT || "1883");
|
const mqttPort = Number(process.env.MQTT_PORT || "1883");
|
||||||
const mqttUsername = process.env.MQTT_USER || "";
|
const mqttUsername = process.env.MQTT_USER || "";
|
||||||
const mqttPassword = process.env.MQTT_PWD || "";
|
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)
|
// 1) Connect to HA broker (for discovery + state)
|
||||||
|
console.log("Connecting to HA broker...");
|
||||||
const ha = await connectHA({ mqttHost, mqttPort, mqttUsername, mqttPassword, });
|
const ha = await connectHA({ mqttHost, mqttPort, mqttUsername, mqttPassword, });
|
||||||
|
console.log("Connected to HA broker");
|
||||||
|
|
||||||
// 2) Connect to Futurehome hub (FIMP traffic)
|
// 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 -----------------------------------------
|
// -- subscribe to FIMP events -----------------------------------------
|
||||||
fimp.subscribe("#");
|
fimp.subscribe("#");
|
||||||
fimp.on("message", (topic, buf) => {
|
fimp.on("message", (topic, buf) => {
|
||||||
try {
|
try {
|
||||||
const msg = JSON.parse(buf.toString());
|
const msg = JSON.parse(buf.toString());
|
||||||
|
console.debug("Received a FIMP message", topic, msg);
|
||||||
if (msg.type === "evt.pd7.response") {
|
if (msg.type === "evt.pd7.response") {
|
||||||
const devices = msg.val?.param?.devices ?? [];
|
const devices = msg.val?.param?.devices ?? [];
|
||||||
devices.forEach((d: any) => publishDiscovery(ha, d));
|
devices.forEach((d: any) => publishDiscovery(ha, d));
|
||||||
}
|
}
|
||||||
// …forward state events as needed…
|
// …forward state events as needed…
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Bad FIMP JSON", e);
|
console.warn("Bad FIMP JSON", e, topic, buf);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user