Version 1.0 working Entity creation and string generator
This commit is contained in:
43
src/app/_models/mqtt_base.ts
Normal file
43
src/app/_models/mqtt_base.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export class MQTTEntity {
|
||||
name: string = "";
|
||||
stat_t: string = "state/topic";
|
||||
uniq_id: string = "unique_id";
|
||||
dev: MQTTDevice | null = null;
|
||||
// entity_type: ENTITY_TYPE = 0;
|
||||
|
||||
setProperty(name: unknown, value: any): void {
|
||||
if(!this.hasOwnProperty(String(name))) return
|
||||
this[name as keyof this] = value;
|
||||
}
|
||||
|
||||
createString() : string{
|
||||
let string: string = "";
|
||||
for(let property of Object.getOwnPropertyNames(this)){
|
||||
if(this[property as keyof this] == null) continue;
|
||||
string += `"${property}": "${this[property as keyof this]}",`
|
||||
}
|
||||
console.log(string);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
export class MQTTDevice {
|
||||
name: string = "";
|
||||
identifiers: string[] = ["MQTT"];
|
||||
serial_number: string = "";
|
||||
configuration_url: string = "";
|
||||
}
|
||||
|
||||
// export enum ENTITY_TYPE {
|
||||
// light = 0,
|
||||
// switch = 1,
|
||||
// sensor = 2,
|
||||
// binary_sensor = 3,
|
||||
// button = 4,
|
||||
// }
|
||||
|
||||
export enum DEVICE_CLASS {
|
||||
motion = 0,
|
||||
movement = 1,
|
||||
outlet = 2
|
||||
}
|
||||
Reference in New Issue
Block a user