From f4eea9bebefcf4946cf9971c294a58bab0c37c1f Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 2 Aug 2024 07:34:09 +0200 Subject: [PATCH] CHANGE: Created seperate output for discovery --- .../entity-output/entity-output.component.css | 5 + .../entity-output.component.html | 13 +- .../entity-output/entity-output.component.ts | 9 +- src/app/entity/entity.component.css | 3 - src/app/entity/entity.component.html | 80 -------- src/app/entity/entity.component.spec.ts | 23 --- src/app/entity/entity.component.ts | 177 ------------------ 7 files changed, 23 insertions(+), 287 deletions(-) delete mode 100644 src/app/entity/entity.component.css delete mode 100644 src/app/entity/entity.component.html delete mode 100644 src/app/entity/entity.component.spec.ts delete mode 100644 src/app/entity/entity.component.ts diff --git a/src/app/entity-output/entity-output.component.css b/src/app/entity-output/entity-output.component.css index e69de29..bff0f60 100644 --- a/src/app/entity-output/entity-output.component.css +++ b/src/app/entity-output/entity-output.component.css @@ -0,0 +1,5 @@ +.jsonPrev { + max-width: 50%; + text-wrap: wrap; + flex-shrink: 0; +} diff --git a/src/app/entity-output/entity-output.component.html b/src/app/entity-output/entity-output.component.html index 01cc950..d372171 100644 --- a/src/app/entity-output/entity-output.component.html +++ b/src/app/entity-output/entity-output.component.html @@ -1 +1,12 @@ -

entity-output works!

+ +
+

Discovery String

+
+
{{outputService.getDiscoveryString(basemodel) | json}}
+ {{outputService.getDiscoveryString(basemodel, true)}} +
+
+
+

Discovery Topic

+ +
\ No newline at end of file diff --git a/src/app/entity-output/entity-output.component.ts b/src/app/entity-output/entity-output.component.ts index df60952..d6e962c 100644 --- a/src/app/entity-output/entity-output.component.ts +++ b/src/app/entity-output/entity-output.component.ts @@ -1,10 +1,13 @@ -import { Component } from '@angular/core'; +import { Component, Input } from '@angular/core'; +import { MQTTEntity } from '../_models/mqtt_base'; +import { OutputService } from '../_services/output.service'; @Component({ selector: 'app-entity-output', templateUrl: './entity-output.component.html', - styleUrl: './entity-output.component.css' + styleUrl: './entity-output.component.css', }) export class EntityOutputComponent { - + constructor(public outputService: OutputService) {} + @Input() basemodel!: MQTTEntity; } diff --git a/src/app/entity/entity.component.css b/src/app/entity/entity.component.css deleted file mode 100644 index 5a303fc..0000000 --- a/src/app/entity/entity.component.css +++ /dev/null @@ -1,3 +0,0 @@ -pre{ - -} \ No newline at end of file diff --git a/src/app/entity/entity.component.html b/src/app/entity/entity.component.html deleted file mode 100644 index cf2f9e2..0000000 --- a/src/app/entity/entity.component.html +++ /dev/null @@ -1,80 +0,0 @@ -
- -
-

EntityTyp:

- -
- -
-

Name

- -
-
-

Uniqe ID

-
- - -
-
-
-

Command Topic

- -
-
-

Brightness Command Topic

- -
-
-
-

Payload off

- -
-
-

Payload on

- -
-
-
-

Unit of meassurement

- -
-
-

Value Template

- -
-
-

Device Class

- -
- - -
-

State Topic

-
- -
-
- - -
-

Discovery String

-
-
{{discoveryString | json}}
- {{JSONdiscoveryString}} -
-
-
-

Discovery Topic

- -
-
-
\ No newline at end of file diff --git a/src/app/entity/entity.component.spec.ts b/src/app/entity/entity.component.spec.ts deleted file mode 100644 index d9e8dfb..0000000 --- a/src/app/entity/entity.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { EntityComponent } from './entity.component'; - -describe('EntityComponent', () => { - let component: EntityComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - declarations: [EntityComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(EntityComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/entity/entity.component.ts b/src/app/entity/entity.component.ts deleted file mode 100644 index 395be4f..0000000 --- a/src/app/entity/entity.component.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { Component, Input } from '@angular/core'; -import { - GeneratorService, - entity_types, - randomString, -} from '../_services/generator.service'; -import { MqttBinary } from '../_models/mqtt-binary'; -import { DeviceClass, MQTTEntity } from '../_models/mqtt_base'; - -@Component({ - selector: 'app-entity', - templateUrl: './entity.component.html', - styleUrl: './entity.component.css', -}) -export class EntityComponent { - constructor(public generatorService: GeneratorService) { - generatorService.updateObserver.subscribe((date) => { - this.update(); - }); - } - - readonly useObject = Object; - readonly entities = entity_types; - readonly useRandomString = randomString; - - showDiscovery: boolean = false; - _discoveryTopic: string = ''; - - @Input() entity_type: number = 0; - @Input() stat_t: string = ''; - @Input() basemodel: MQTTEntity | null = null; - - @Input() entity_name: string = ''; - @Input() entity_uniq_id: string = ''; - @Input() entity_cmd_t: string = ''; - @Input() entity_bri_cmd_t: string = ''; - @Input() entity_pl_off: string = '0'; - @Input() entity_pl_on: string = '1'; - @Input() entity_unit_of_meas: string = ''; - @Input() entity_val_tpl: string = ''; - @Input() entity_dev_cla: DeviceClass = new DeviceClass([]); - - get display_name() { - if (this.entity_name != '' && this.entity_uniq_id != '') { - return this.entity_name + '_' + this.entity_uniq_id; - } else { - return this.entity_name; - } - } - - 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]; - // } - // } - } - - sync_topcis(model: keyof this, value: string) { - let new_list = value.split('/'); - let old_list = String(this[model]).split('/'); - 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 = 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]; - return; - } - let missing_index = new_list.indexOf(missing[0]); - this.stat_t = this.replaceComponent(this.stat_t, missing[0], missing_index); - this.entity_cmd_t = this.replaceComponent( - this.entity_cmd_t, - missing[0], - missing_index - ); - this.entity_bri_cmd_t = this.replaceComponent( - this.entity_bri_cmd_t, - missing[0], - missing_index - ); - - return; - } - - replaceComponent(object: string, value: string, index: number) { - let param_list = object.split('/'); - param_list[index] = value; - return param_list.join('/'); - } - - updateTopic(topic: string) { - let topic_str = join( - '/', - this.generatorService.upperTopic, - entity_types[this.entity_type][0], - this.generatorService.device_name, - this.display_name, - topic - ).toLowerCase(); - 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.; - // // } - // } else this.generatorService.selected_entity = null; - // this.entity_type = event as number; - // this.update(); - // } - - lock_auto_topic() { - // 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; - // } - - get discoveryString() { - return this.basemodel?.toJSON(); - } - - get JSONdiscoveryString() { - return JSON.stringify(this.basemodel?.toJSON()).replaceAll('"', '\\"'); - } - - get discoveryTopic() { - if (this.entity_type == 0) return ''; - return join( - '/', - 'homeassistant', - entity_types[this.entity_type][0], - this.display_name - ).toLowerCase(); - } -} - -function join(seperator = '/', first: string, ...args: string[]): string { - let result = ''; - for (let str of args) { - if (str == '') continue; - result += seperator + str; - } - if (first == '') return result.slice(1); - return first + result; -}