Merge into Main #1
7
src/app/_models/mqtt-device.spec.ts
Normal file
7
src/app/_models/mqtt-device.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { MqttDevice } from './mqtt-device';
|
||||
|
||||
describe('MqttDevice', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new MqttDevice()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
52
src/app/_models/mqtt-device.ts
Normal file
52
src/app/_models/mqtt-device.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user