diff --git a/src/app/entity-data/entity-data.component.html b/src/app/entity-data/entity-data.component.html index a38d060..6966270 100644 --- a/src/app/entity-data/entity-data.component.html +++ b/src/app/entity-data/entity-data.component.html @@ -2,18 +2,18 @@

Name

- +

Uniqe ID

-
diff --git a/src/app/entity-data/entity-data.component.ts b/src/app/entity-data/entity-data.component.ts index da3042b..9118c6a 100644 --- a/src/app/entity-data/entity-data.component.ts +++ b/src/app/entity-data/entity-data.component.ts @@ -1,6 +1,5 @@ -import { Component, Input } from '@angular/core'; +import { Component, Input, ViewChild } from '@angular/core'; import { DeviceClass, MQTTEntity } from '../_models/mqtt_base'; -import { EntityService } from '../_services/entity.service'; import { GeneratorService } from '../_services/generator.service'; @Component({ @@ -9,17 +8,18 @@ import { GeneratorService } from '../_services/generator.service'; styleUrl: './entity-data.component.css', }) export class EntityDataComponent { - @Input() entity_type: number = 0; + @Input() entity_type: number = 1; @Input() basemodel!: MQTTEntity; @Input() created: boolean = false; - constructor( - private entityService: EntityService, - public generatorService: GeneratorService - ) { + @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 = ''; diff --git a/src/app/entity/entity.component.ts b/src/app/entity/entity.component.ts index cd6ecec..395be4f 100644 --- a/src/app/entity/entity.component.ts +++ b/src/app/entity/entity.component.ts @@ -49,23 +49,23 @@ export class EntityComponent { } update(model: keyof this = 'stat_t', event: Event | boolean = false): void { - if (this.generatorService.auto_topic == 2) { - this.stat_t = this.updateTopic('stat'); - this.entity_cmd_t = this.updateTopic('cmd'); - this.entity_bri_cmd_t = this.updateTopic('bri_cmd'); - return; - } - if (event instanceof Event) - var value = (event.target as HTMLInputElement).value; - else return; - if (this.generatorService.auto_topic == 1) { - this.sync_topcis(model, value); - } else { - if (!this.hasOwnProperty(model)) return; - if (typeof this[model] === 'string') { - this[model] = value as (typeof this)[keyof this]; - } - } + // if (this.generatorService.auto_topic == 2) { + // this.stat_t = this.updateTopic('stat'); + // this.entity_cmd_t = this.updateTopic('cmd'); + // this.entity_bri_cmd_t = this.updateTopic('bri_cmd'); + // return; + // } + // if (event instanceof Event) + // var value = (event.target as HTMLInputElement).value; + // else return; + // if (this.generatorService.auto_topic == 1) { + // this.sync_topcis(model, value); + // } else { + // if (!this.hasOwnProperty(model)) return; + // if (typeof this[model] === 'string') { + // this[model] = value as (typeof this)[keyof this]; + // } + // } } sync_topcis(model: keyof this, value: string) { @@ -74,7 +74,7 @@ export class EntityComponent { let missing = new_list.filter((item) => old_list.indexOf(item) < 0); if (old_list.filter((item) => new_list.indexOf(item) < 0).length > 1) - return (this.generatorService.auto_topic = 0); + return (this.generatorService.auto_topic = false); if (missing.length == 0) return; //(this.generatorService.auto_topic = 2); if (new_list.indexOf(missing[0]) == new_list.length - 1) { this[model] = value as (typeof this)[keyof this]; @@ -114,38 +114,38 @@ export class EntityComponent { return topic_str; } - select_type(event: unknown) { - let ent_type = entity_types[event as keyof typeof entity_types]; - let ent_class = ent_type[1]; - if (typeof ent_class === 'function' && event != 0) { - this.basemodel = new ent_class(); - this.generatorService.selected_entity = this.basemodel; - if (this.generatorService.has_property('dev_cla')) { - this.entity_dev_cla = this.basemodel.getProperty('dev_cla'); - } - } else this.generatorService.selected_entity = null; - this.entity_type = event as number; - this.update(); - } + select_type(event: unknown) {} + // let ent_type = entity_types[event as keyof typeof entity_types]; + // let ent_class = ent_type[1]; + // if (typeof ent_class === 'function' && event != 0) { + // this.basemodel = new ent_class(); + // this.generatorService.selected_entity = this.basemodel; + // // if (this.generatorService.has_property('dev_cla')) { + // // this.entity_dev_cla = this.basemodel.; + // // } + // } else this.generatorService.selected_entity = null; + // this.entity_type = event as number; + // this.update(); + // } lock_auto_topic() { - this.generatorService.auto_topic = 1; + // this.generatorService.auto_topic = 1; } - create_entity() { - this.basemodel?.setProperty('stat_t', this.stat_t); - this.basemodel?.setProperty('name', this.entity_name); - this.basemodel?.setProperty('cmd_t', this.entity_cmd_t); - this.basemodel?.setProperty('bri_cmd_t', this.entity_bri_cmd_t); - this.basemodel?.setProperty('pl_off', this.entity_pl_off); - this.basemodel?.setProperty('pl_on', this.entity_pl_on); - this.basemodel?.setProperty('unit_of_meas', this.entity_unit_of_meas); - this.basemodel?.setProperty('val_tpl', this.entity_val_tpl); - this.basemodel?.setProperty('dev_cla', this.entity_dev_cla); - this._discoveryTopic = this.discoveryTopic; - this.showDiscovery = true; - return; - } + create_entity() {} + // this.basemodel?.setProperty('stat_t', this.stat_t); + // this.basemodel?.setProperty('name', this.entity_name); + // this.basemodel?.setProperty('cmd_t', this.entity_cmd_t); + // this.basemodel?.setProperty('bri_cmd_t', this.entity_bri_cmd_t); + // this.basemodel?.setProperty('pl_off', this.entity_pl_off); + // this.basemodel?.setProperty('pl_on', this.entity_pl_on); + // this.basemodel?.setProperty('unit_of_meas', this.entity_unit_of_meas); + // this.basemodel?.setProperty('val_tpl', this.entity_val_tpl); + // this.basemodel?.setProperty('dev_cla', this.entity_dev_cla); + // this._discoveryTopic = this.discoveryTopic; + // this.showDiscovery = true; + // return; + // } get discoveryString() { return this.basemodel?.toJSON();