CHANGE: automatic topic generation in class

This commit is contained in:
2024-07-29 15:33:58 +02:00
parent 56365214b8
commit bbc4dd6e53
5 changed files with 166 additions and 26 deletions

View File

@@ -1,8 +1,43 @@
import { DeviceClass, MQTTEntity } from './mqtt_base';
import { EntityService } from '../_services/entity.service';
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',
]);
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;
}
}
export interface iMqttSwitch extends iMQTTEntityBase {
cmd_t: string;
pl_on: string;
pl_off: string;
dev_cla: DeviceClass;
}