158 lines
4.0 KiB
TypeScript
158 lines
4.0 KiB
TypeScript
import { Component, Input, ViewChild } from '@angular/core';
|
|
import { DeviceClass, MQTTEntity } from '../_models/mqtt_base';
|
|
import { GeneratorService } from '../_services/generator.service';
|
|
|
|
@Component({
|
|
selector: 'app-entity-data',
|
|
templateUrl: './entity-data.component.html',
|
|
styleUrl: './entity-data.component.css',
|
|
})
|
|
export class EntityDataComponent {
|
|
@Input() entity_type: number = 1;
|
|
@Input() basemodel!: MQTTEntity;
|
|
@Input() created: boolean = false;
|
|
@Input() ent_index: number = 0;
|
|
|
|
@ViewChild('nameinput') nameinput!: any;
|
|
constructor(public generatorService: GeneratorService) {
|
|
if (generatorService.selected_entity) {
|
|
this.basemodel = generatorService.selected_entity;
|
|
}
|
|
}
|
|
ngAfterViewInit() {
|
|
if (!this.created) this.nameinput.nativeElement.focus();
|
|
}
|
|
|
|
_entity_name: string = '';
|
|
_entity_uniq_id: string = '';
|
|
_entity_stat_t: string = '';
|
|
_entity_cmd_t: string = '';
|
|
_entity_bri_cmd_t: string = '';
|
|
_entity_pl_off: string = '';
|
|
_entity_pl_on: string = '';
|
|
_entity_unit_of_meas: string = '';
|
|
_entity_val_tpl: string = '';
|
|
_entity_dev_cla: DeviceClass = new DeviceClass([]);
|
|
|
|
get entity_name() {
|
|
let base = this.basemodel.getProperty('name');
|
|
if (base == '') {
|
|
this.basemodel.setProperty('name', this._entity_name);
|
|
return this._entity_name;
|
|
}
|
|
return base;
|
|
}
|
|
|
|
set entity_name(data: string) {
|
|
this._entity_name = data;
|
|
this.basemodel.setProperty('name', data);
|
|
}
|
|
|
|
get entity_uniq_id() {
|
|
let base = this.basemodel.getProperty('uniq_id');
|
|
if (base == '') {
|
|
this.basemodel.setProperty('uniq_id', this._entity_uniq_id);
|
|
return this._entity_uniq_id;
|
|
}
|
|
return base;
|
|
}
|
|
|
|
set entity_uniq_id(data: string) {
|
|
this._entity_uniq_id = data;
|
|
this.basemodel.setProperty('uniq_id', data);
|
|
}
|
|
|
|
get entity_stat_t() {
|
|
let base = this.basemodel.getProperty('stat_t');
|
|
if (base == 'state/topic') {
|
|
this.basemodel.setProperty('stat_t', this._entity_stat_t);
|
|
return this._entity_stat_t;
|
|
}
|
|
return base;
|
|
}
|
|
|
|
set entity_stat_t(data: string) {
|
|
this._entity_stat_t = data;
|
|
this.basemodel.setProperty('stat_t', data);
|
|
}
|
|
|
|
get entity_cmd_t() {
|
|
let base = this.basemodel.getProperty('cmd_t');
|
|
if (base == 'command/topic') {
|
|
this.basemodel.setProperty('cmd_t', this._entity_cmd_t);
|
|
return this._entity_cmd_t;
|
|
}
|
|
return base;
|
|
}
|
|
|
|
set entity_cmd_t(data: string) {
|
|
this._entity_cmd_t = data;
|
|
this.basemodel.setProperty('cmd_t', data);
|
|
}
|
|
|
|
get entity_bri_cmd_t() {
|
|
let base = this.basemodel.getProperty('bri_cmd_t');
|
|
if (base == 'brightness/command/topic') {
|
|
this.basemodel.setProperty('bri_cmd_t', this._entity_bri_cmd_t);
|
|
return this._entity_bri_cmd_t;
|
|
}
|
|
return base;
|
|
}
|
|
|
|
set entity_bri_cmd_t(data: string) {
|
|
this._entity_bri_cmd_t = data;
|
|
this.basemodel.setProperty('bri_cmd_t', data);
|
|
}
|
|
|
|
get entity_pl_off() {
|
|
return this._entity_pl_off;
|
|
}
|
|
|
|
set entity_pl_off(data: string) {
|
|
this._entity_pl_off = data;
|
|
this.basemodel.setProperty('pl_off', data);
|
|
}
|
|
|
|
get entity_pl_on() {
|
|
return this._entity_pl_on;
|
|
}
|
|
|
|
set entity_pl_on(data: string) {
|
|
this._entity_pl_on = data;
|
|
this.basemodel.setProperty('pl_on', data);
|
|
}
|
|
|
|
get entity_unit_of_meas() {
|
|
return this._entity_unit_of_meas;
|
|
}
|
|
|
|
set entity_unit_of_meas(data: string) {
|
|
this._entity_unit_of_meas = data;
|
|
this.basemodel.setProperty('unit_of_meas', data);
|
|
}
|
|
|
|
get entity_val_tpl() {
|
|
return this._entity_val_tpl;
|
|
}
|
|
|
|
set entity_val_tpl(data: string) {
|
|
this._entity_val_tpl = data;
|
|
this.basemodel.setProperty('val_tpl', data);
|
|
}
|
|
|
|
get entity_dev_cla(): number {
|
|
this._entity_dev_cla = this.basemodel.getProperty('dev_cla');
|
|
return this._entity_dev_cla.value;
|
|
}
|
|
|
|
set entity_dev_cla(data: number) {
|
|
data = Number(data);
|
|
this._entity_dev_cla.value = data;
|
|
this.basemodel.setProperty('dev_cla', data);
|
|
}
|
|
|
|
hasProperty(property: string) {
|
|
return this.basemodel.attrs.has(property);
|
|
}
|
|
}
|