Add support for 'basic' service

This commit is contained in:
Adrian Jagielak 2025-07-23 22:47:58 +02:00
parent 1c6407f0c2
commit 0a945b679a
No known key found for this signature in database
GPG Key ID: 0818CF7AF6C62BFB
4 changed files with 62 additions and 3 deletions

View File

@ -52,7 +52,7 @@ todo periodical refresh of state
| alarm_weather | | | | alarm_weather | | |
| appliance | | | | appliance | | |
| barrier_ctrl | | | | barrier_ctrl | | |
| basic | | | | basic | | |
| battery | | ✅ | | battery | | ✅ |
| blinds | | | | blinds | | |
| boiler | | | | boiler | | |
@ -137,7 +137,8 @@ todo periodical refresh of state
| indicator_ctrl | | | | indicator_ctrl | | |
| ota | | | | ota | | |
| parameters | | | | parameters | | |
| dev_sys | | |
| technology_specific | | | | technology_specific | | |
| time | | | | time | | |
| version | | | | version | | |
| dev_sys | | |

View File

@ -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.19" version: "0.0.20"
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"

View File

@ -1,6 +1,7 @@
import { InclusionReport } from "../fimp/inclusion_report"; import { InclusionReport } from "../fimp/inclusion_report";
import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device"; import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device";
import { log } from "../logger"; import { log } from "../logger";
import { basic__components } from "../services/basic";
import { battery__components } from "../services/battery"; import { battery__components } from "../services/battery";
import { out_bin_switch__components } from "../services/out_bin_switch"; import { out_bin_switch__components } from "../services/out_bin_switch";
import { out_lvl_switch__components } from "../services/out_lvl_switch"; import { out_lvl_switch__components } from "../services/out_lvl_switch";
@ -157,6 +158,7 @@ export type CommandHandlers = { [topic: string]: (payload: string) => Promise<vo
const serviceHandlers: { const serviceHandlers: {
[name: string]: (topicPrefix: string, device: VinculumPd7Device, svc: VinculumPd7Service) => ServiceComponentsCreationResult | undefined [name: string]: (topicPrefix: string, device: VinculumPd7Device, svc: VinculumPd7Service) => ServiceComponentsCreationResult | undefined
} = { } = {
basic: basic__components,
battery: battery__components, battery: battery__components,
out_bin_switch: out_bin_switch__components, out_bin_switch: out_bin_switch__components,
out_lvl_switch: out_lvl_switch__components, out_lvl_switch: out_lvl_switch__components,

View File

@ -0,0 +1,56 @@
// Maps a Futurehome “basic” service to one MQTT *number* entity.
// ───────────────────────────────────────────────────────────────
// FIMP ➞ HA state path used by the template
// value_json[svc.addr].lvl current level (0-255)
//
// HA ➞ FIMP commands
// command_topic → cmd.lvl.set
// ───────────────────────────────────────────────────────────────
import { sendFimpMsg } from "../fimp/fimp";
import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device";
import { ServiceComponentsCreationResult } from "../ha/publish_device";
export function basic__components(
topicPrefix: string,
_device: VinculumPd7Device,
svc: VinculumPd7Service
): ServiceComponentsCreationResult | undefined {
// MQTT topic that HA will publish commands to
const cmdTopic = `${topicPrefix}${svc.addr}/command`;
// Z-Wave “Basic” uses a 0-255 range (0 = off, 255 = on, 1-254 = dim level)
const MIN_LVL = 0;
const MAX_LVL = 255;
return {
components: {
[svc.addr]: {
unique_id: svc.addr,
p: "number",
min: MIN_LVL,
max: MAX_LVL,
step: 1,
command_topic: cmdTopic,
optimistic: true,
value_template: `{{ value_json['${svc.addr}'].lvl }}`,
},
},
// ─────── HA → FIMP bridge ───────
commandHandlers: {
[cmdTopic]: async (payload: string) => {
const lvl = parseInt(payload, 10);
if (Number.isNaN(lvl)) return;
await sendFimpMsg({
address: svc.addr!,
service: "basic",
cmd: "cmd.lvl.set",
val_t: "int",
val: lvl,
});
},
},
};
}