Files
mqtt_creator/src/app/_models/mqtt-switch.ts

58 lines
1.2 KiB
TypeScript

import { DeviceClass, iMQTTEntityBase, MQTTEntity } from './mqtt_base';
export class MqttSwitch extends MQTTEntity {
override ent_type: string = 'switch';
override attrs: Set<string> = new Set([
'name',
'uniq_id',
'stat_t',
'dev_cla',
'cmd_t',
'pl_on',
'pl_off',
]);
get dev_cla(): DeviceClass {
return this._dev_cla;
}
set dev_cla(data: number) {
this._dev_cla.value = data;
}
_dev_cla: DeviceClass = new DeviceClass(['switch', 'outlet']);
cmd_t: string = 'command/topic';
pl_on: string = '1';
pl_off: string = '0';
override set name(name: string) {
super.name = name;
this.topic_updates.next('cmd_t');
}
override set uniq_id(uniq_id: string) {
super.uniq_id = uniq_id;
this.topic_updates.next('cmd_t');
}
override get name() {
return this._name;
}
override get uniq_id() {
return this._uniq_id;
}
override publish_topics(index: number = 1): string[] {
return [
`String stat_topic_${index} = "${this.stat_t}";`,
`String cmd_topic_${index} = "${this.cmd_t}";`,
];
}
}
export interface iMqttSwitch extends iMQTTEntityBase {
cmd_t: string;
pl_on: string;
pl_off: string;
dev_cla: DeviceClass;
}