diff --git a/src/app/_models/mqtt_base.ts b/src/app/_models/mqtt_base.ts index 42028eb..4c79368 100644 --- a/src/app/_models/mqtt_base.ts +++ b/src/app/_models/mqtt_base.ts @@ -4,7 +4,7 @@ import { EntityService } from '../_services/entity.service'; @Injectable() export class MQTTEntity implements iMQTTEntityBase { protected _name: string = ''; - protected _stat_t: string = ''; + protected _stat_t: string = 'state/topic'; protected _uniq_id: string = ''; attrs = new Set(['name', 'stat_t', 'uniq_id']); diff --git a/src/app/_services/generator.service.ts b/src/app/_services/generator.service.ts index 2b3efe1..735f828 100644 --- a/src/app/_services/generator.service.ts +++ b/src/app/_services/generator.service.ts @@ -16,7 +16,7 @@ export class GeneratorService { @Input() device_name: string = ''; @Input() device_id: string = ''; @Input() device_standalone: boolean = false; - @Input() auto_topic: number = 2; + @Input() auto_topic: boolean = true; _upperTopic: string = ''; @@ -37,9 +37,9 @@ export class GeneratorService { set selected_entity(entity: MQTTEntity | null) { this._selected_entity = entity; - console.log('added'); entity?.topic_updates.subscribe((topic: string) => { - entity.setProperty(topic, this.updateTopic(entity, topic)); + if (this.auto_topic) + entity.setProperty(topic, this.updateTopic(entity, topic)); }); } @@ -47,14 +47,18 @@ export class GeneratorService { return this._selected_entity; } + //TODO: add dynamic topic gen -> use already set topic if there are changes updateTopic(entity: MQTTEntity, topic: string) { + let topicStr: string = entity.getProperty(topic).split('/').pop(); + let customTopic = + topicStr == 'topic' || topicStr == topic ? topic : topicStr; return join( '/', this.upperTopic, entity.ent_type, this.device_name, entity.display_name, - topic + customTopic ).toLowerCase(); } diff --git a/src/app/generator/generator.component.html b/src/app/generator/generator.component.html index a413641..5d665d2 100644 --- a/src/app/generator/generator.component.html +++ b/src/app/generator/generator.component.html @@ -12,17 +12,15 @@
Automatische Topics