52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { EventEmitter } from "@angular/core";
|
|
import { hash } from "./mqtt_base";
|
|
|
|
export class MQTTDevice {
|
|
private _name: string = '';
|
|
private _identifier: string = '';
|
|
private _serial_number: string = '';
|
|
// private configuration_url: string = '';
|
|
|
|
topic_updates = new EventEmitter<string>();
|
|
|
|
get name() {
|
|
return this._name;
|
|
}
|
|
|
|
set name(name: string) {
|
|
this._name = name;
|
|
if (name == '') this._serial_number = '';
|
|
else this._serial_number = hash(name);
|
|
this.topic_updates.next('stat_t');
|
|
this.topic_updates.next('cmd_t');
|
|
this.topic_updates.next('bri_cmd_t');
|
|
}
|
|
|
|
get serial_number() {
|
|
return this._serial_number;
|
|
}
|
|
|
|
set serial_number(serial_number: string) {
|
|
this._serial_number = serial_number;
|
|
}
|
|
|
|
get indetifier() {
|
|
this._identifier =
|
|
this._name == '' && this._serial_number == ''
|
|
? ''
|
|
: [this._name, this._serial_number].join('_');
|
|
return this._identifier;
|
|
}
|
|
|
|
toJSON(full: boolean = false): { [key: string]: string } {
|
|
if (full)
|
|
return {
|
|
...this.toJSON(),
|
|
name: this._name,
|
|
serial_number: this._serial_number,
|
|
};
|
|
return {
|
|
ids: this._identifier,
|
|
};
|
|
}
|
|
} |