CHANGE: autochange topics with custom ending in mind
This commit is contained in:
@@ -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']);
|
||||
|
||||
@@ -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,8 +37,8 @@ export class GeneratorService {
|
||||
|
||||
set selected_entity(entity: MQTTEntity | null) {
|
||||
this._selected_entity = entity;
|
||||
console.log('added');
|
||||
entity?.topic_updates.subscribe((topic: string) => {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,15 @@
|
||||
<div class="property">
|
||||
<p>Automatische Topics</p>
|
||||
<div class="customCheckboxContainer">
|
||||
<input [ngModel]="auto_topic" (ngModelChange)="auto_topic=$event" id="auto_topic_0" type="radio" name="auto_topic" value="2">
|
||||
<input [ngModel]="generatorService.auto_topic" (ngModelChange)="generatorService.auto_topic=$event" id="auto_topic_0" type="radio" name="auto_topic" [value]="true">
|
||||
<label class="customCheckbox" for="auto_topic_0">Alles</label>
|
||||
<input [ngModel]="auto_topic" (ngModelChange)="auto_topic=$event" id="auto_topic_1" type="radio" name="auto_topic" value="1">
|
||||
<label class="customCheckbox" for="auto_topic_1">Änderungen übernehmen</label>
|
||||
<input [ngModel]="auto_topic" (ngModelChange)="auto_topic=$event" id="auto_topic_2" type="radio" name="auto_topic" value="0">
|
||||
<input [ngModel]="generatorService.auto_topic" (ngModelChange)="generatorService.auto_topic=$event" id="auto_topic_2" type="radio" name="auto_topic" [value]="false">
|
||||
<label class="customCheckbox" for="auto_topic_2">Aus</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-span-2 property">
|
||||
<h3>EntityTyp:</h3>
|
||||
<select [ngModel]="entity_type" (ngModelChange)="select_type($event)">
|
||||
<select #typeinput autofocus [ngModel]="entity_type" (ngModelChange)="select_type($event)">
|
||||
<option *ngFor="let key of useObject.keys(generatorService.entity_types)" value="{{key}}">{{generatorService.entity_types[key][0]}}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, Input, ViewChild } from '@angular/core';
|
||||
import { EntityService } from '../_services/entity.service';
|
||||
import { GeneratorService, randomString } from '../_services/generator.service';
|
||||
import { MQTTEntity } from '../_models/mqtt_base';
|
||||
@@ -17,33 +17,27 @@ export class GeneratorComponent {
|
||||
readonly useObject = Object;
|
||||
readonly useRandomString = randomString;
|
||||
|
||||
set auto_topic(value: number) {
|
||||
this.generatorService.auto_topic = value;
|
||||
console.log(this.generatorService.auto_topic);
|
||||
}
|
||||
|
||||
get auto_topic(): string {
|
||||
return String(this.generatorService.auto_topic);
|
||||
}
|
||||
@ViewChild('typeinput') typeinput: any;
|
||||
@Input() entity_type: number = 0;
|
||||
|
||||
get created_entities(): MQTTEntity[] {
|
||||
return Array.from(this.generatorService.created_enteties).reverse();
|
||||
}
|
||||
|
||||
entity_type: number = 0;
|
||||
|
||||
select_type(etype: number) {
|
||||
let ent_type =
|
||||
select_type(entity_num: number) {
|
||||
this.entity_type = entity_num;
|
||||
let entity_type =
|
||||
this.generatorService.entity_types[
|
||||
etype as keyof typeof this.generatorService.entity_types
|
||||
entity_num as keyof typeof this.generatorService.entity_types
|
||||
];
|
||||
let ent_class = ent_type[1];
|
||||
if (typeof ent_class === 'function' && etype != 0) {
|
||||
let entity_model = new ent_class();
|
||||
this.generatorService.selected_entity = entity_model;
|
||||
} else this.generatorService.selected_entity = null;
|
||||
this.entity_type = etype;
|
||||
console.log(this.generatorService.selected_entity);
|
||||
let entity_class = entity_type[1];
|
||||
|
||||
if (typeof entity_class === 'function' && entity_num != 0) {
|
||||
this.generatorService.selected_entity = new entity_class();
|
||||
} else {
|
||||
this.generatorService.selected_entity = null;
|
||||
this.typeinput.nativeElement.focus();
|
||||
}
|
||||
}
|
||||
|
||||
log(event: any) {
|
||||
|
||||
Reference in New Issue
Block a user