ADD: new deviceclass and toJSON Method
This commit is contained in:
@@ -1,43 +1,55 @@
|
|||||||
export class MQTTEntity {
|
export class MQTTEntity {
|
||||||
name: string = "";
|
name: string = '';
|
||||||
stat_t: string = "state/topic";
|
stat_t: string = '';
|
||||||
uniq_id: string = "unique_id";
|
uniq_id: string = '';
|
||||||
dev: MQTTDevice | null = null;
|
// dev: MQTTDevice | null = null;
|
||||||
// entity_type: ENTITY_TYPE = 0;
|
// entity_type: ENTITY_TYPE = 0;
|
||||||
|
|
||||||
setProperty(name: unknown, value: any): void {
|
setProperty(name: unknown, value: any): void {
|
||||||
if(!this.hasOwnProperty(String(name))) return
|
if (!this.hasOwnProperty(String(name))) return;
|
||||||
this[name as keyof this] = value;
|
this[name as keyof this] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
createString() : string{
|
getProperty(name: string): any {
|
||||||
let string: string = "";
|
if (!this.hasOwnProperty(name)) return;
|
||||||
for(let property of Object.getOwnPropertyNames(this)){
|
return this[name as keyof this];
|
||||||
if(this[property as keyof this] == null) continue;
|
}
|
||||||
string += `"${property}": "${this[property as keyof this]}",`
|
|
||||||
}
|
toJSON(): any {
|
||||||
console.log(string);
|
let jsonObject: { [key: string]: string } = {};
|
||||||
return string;
|
for (let prop_name of Object.getOwnPropertyNames(this)) {
|
||||||
|
let property = this[prop_name as keyof this];
|
||||||
|
if (property == '') continue;
|
||||||
|
jsonObject[prop_name] = String(property);
|
||||||
}
|
}
|
||||||
|
return jsonObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
// toJSON(): any {
|
||||||
|
// return {
|
||||||
|
// name: this.name,
|
||||||
|
// stat_t: this.stat_t,
|
||||||
|
// uniq_id: this.uniq_id,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MQTTDevice {
|
export class MQTTDevice {
|
||||||
name: string = "";
|
name: string = '';
|
||||||
identifiers: string[] = ["MQTT"];
|
identifiers: string[] = ['MQTT'];
|
||||||
serial_number: string = "";
|
serial_number: string = '';
|
||||||
configuration_url: string = "";
|
configuration_url: string = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// export enum ENTITY_TYPE {
|
export class DeviceClass {
|
||||||
// light = 0,
|
value: number = 0;
|
||||||
// switch = 1,
|
choices: string[] = ['None'];
|
||||||
// sensor = 2,
|
|
||||||
// binary_sensor = 3,
|
|
||||||
// button = 4,
|
|
||||||
// }
|
|
||||||
|
|
||||||
export enum DEVICE_CLASS {
|
constructor(choices: string[]) {
|
||||||
motion = 0,
|
this.choices = choices;
|
||||||
movement = 1,
|
}
|
||||||
outlet = 2
|
|
||||||
}
|
toString(): string {
|
||||||
|
return this.choices[this.value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user