2025-07-24 16:34:58 +02:00
|
|
|
import { sendFimpMsg } from '../fimp/fimp';
|
|
|
|
import {
|
|
|
|
VinculumPd7Device,
|
|
|
|
VinculumPd7Service,
|
|
|
|
} from '../fimp/vinculum_pd7_device';
|
|
|
|
import { ServiceComponentsCreationResult } from '../ha/publish_device';
|
2025-07-22 23:21:34 +02:00
|
|
|
|
2025-07-23 16:26:41 +02:00
|
|
|
export function out_lvl_switch__components(
|
|
|
|
topicPrefix: string,
|
2025-07-23 20:24:14 +02:00
|
|
|
device: VinculumPd7Device,
|
2025-07-24 16:34:58 +02:00
|
|
|
svc: VinculumPd7Service,
|
2025-07-23 16:26:41 +02:00
|
|
|
): ServiceComponentsCreationResult | undefined {
|
2025-07-23 20:24:14 +02:00
|
|
|
const commandTopic = `${topicPrefix}${svc.addr}/command`;
|
2025-07-23 16:26:41 +02:00
|
|
|
|
|
|
|
const minLvl = svc.props?.min_lvl ?? 0;
|
|
|
|
const maxLvl = svc.props?.max_lvl ?? 100;
|
2025-07-22 23:21:34 +02:00
|
|
|
|
|
|
|
return {
|
2025-07-23 15:34:22 +02:00
|
|
|
components: {
|
2025-07-23 20:24:14 +02:00
|
|
|
[svc.addr]: {
|
|
|
|
unique_id: svc.addr,
|
2025-07-24 15:54:47 +02:00
|
|
|
platform: 'number',
|
2025-07-23 16:26:41 +02:00
|
|
|
min: minLvl,
|
|
|
|
max: maxLvl,
|
|
|
|
step: 1,
|
|
|
|
command_topic: commandTopic,
|
|
|
|
optimistic: false,
|
2025-07-23 20:24:14 +02:00
|
|
|
value_template: `{{ value_json['${svc.addr}'].lvl }}`,
|
2025-07-23 16:26:41 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
commandHandlers: {
|
|
|
|
[commandTopic]: async (payload: string) => {
|
|
|
|
const lvl = parseInt(payload, 10);
|
|
|
|
if (Number.isNaN(lvl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await sendFimpMsg({
|
2025-07-23 20:24:14 +02:00
|
|
|
address: svc.addr!,
|
2025-07-24 16:34:58 +02:00
|
|
|
service: 'out_lvl_switch',
|
|
|
|
cmd: 'cmd.lvl.set',
|
2025-07-23 16:26:41 +02:00
|
|
|
val: lvl,
|
2025-07-24 16:34:58 +02:00
|
|
|
val_t: 'int',
|
2025-07-23 16:26:41 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2025-07-22 23:21:34 +02:00
|
|
|
}
|