Files
home-assistant-futurehome/futurehome/src/services/out_bin_switch.ts
Adrian Jagielak 3cbf43f358 lint & format
2025-07-23 20:38:17 +02:00

35 lines
994 B
TypeScript

import { sendFimpMsg } from "../fimp/fimp";
import { VinculumPd7Device, VinculumPd7Service } from "../fimp/vinculum_pd7_device";
import { ServiceComponentsCreationResult } from "../ha/publish_device";
export function out_bin_switch__components(
topicPrefix: string,
device: VinculumPd7Device,
svc: VinculumPd7Service
): ServiceComponentsCreationResult | undefined {
const commandTopic = `${topicPrefix}${svc.addr}/command`;
return {
components: {
[svc.addr]: {
unique_id: svc.addr,
p: 'switch',
command_topic: commandTopic,
optimistic: false,
value_template: `{{ (value_json['${svc.addr}'].binary) | iif('ON', 'OFF') }}`,
},
},
commandHandlers: {
[commandTopic]: async (payload: string) => {
await sendFimpMsg({
address: svc.addr!,
service: 'out_bin_switch',
cmd: 'cmd.binary.set',
val: payload === 'ON',
val_t: 'bool',
});
},
}
};
}