From fe9dd91215e6f46eec4566dee8765201617c0414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20M=C3=BCller?= Date: Thu, 7 Apr 2022 16:58:33 +0200 Subject: [PATCH] #223 MultiSwitch renamed to LevelSwitch --- run/Appliances.xml | 4 +- .../src/app/control/control-factory.ts | 10 ++--- .../src/app/control/control.component.html | 6 +-- .../src/app/control/control.component.ts | 10 ++--- .../angular/src/app/control/control.module.ts | 4 +- src/main/angular/src/app/control/control.ts | 4 +- .../control-level.component.html} | 42 +++++++++---------- .../control-level.component.scss} | 2 +- .../control/level/control-level.component.ts | 37 ++++++++-------- .../multi-switch.ts => level/level-switch.ts} | 8 ++-- .../control/{multi => level}/power-level.ts | 0 .../control/{multi => level}/switch-status.ts | 0 src/main/angular/src/assets/i18n/de.json | 14 +++---- .../appliance/Appliance.java | 2 +- .../{MultiSwitch.java => LevelSwitch.java} | 4 +- .../semp/webservice/SempController.java | 6 +-- xsd/SmartApplianceEnabler-2.0.xsd | 8 ++-- 17 files changed, 81 insertions(+), 80 deletions(-) rename src/main/angular/src/app/control/{multi/control-multi.component.html => level/control-level.component.html} (70%) rename src/main/angular/src/app/control/{multi/control-multi.component.scss => level/control-level.component.scss} (97%) rename src/main/angular/src/app/control/{multi/multi-switch.ts => level/level-switch.ts} (86%) rename src/main/angular/src/app/control/{multi => level}/power-level.ts (100%) rename src/main/angular/src/app/control/{multi => level}/switch-status.ts (100%) rename src/main/java/de/avanux/smartapplianceenabler/control/{MultiSwitch.java => LevelSwitch.java} (98%) diff --git a/run/Appliances.xml b/run/Appliances.xml index 8b73ba66..95370998 100644 --- a/run/Appliances.xml +++ b/run/Appliances.xml @@ -2,7 +2,7 @@ - + -
+
- - {{'ControlMultiComponent.type' | translate}} + + {{'ControlLevelComponent.type' | translate}} {{controlType.viewValue}} @@ -30,63 +30,63 @@
-
-

{{'ControlMultiComponent.control.heading' | translate}} {{control.id}}

- +

{{'ControlLevelComponent.control.heading' | translate}} {{control.id}}

+
-
-

{{'ControlMultiComponent.control.heading' | translate}} {{control.id}}

- +

{{'ControlLevelComponent.control.heading' | translate}} {{control.id}}

+
-
-

{{'ControlMultiComponent.control.heading' | translate}} {{control.id}}

- +

{{'ControlLevelComponent.control.heading' | translate}} {{control.id}}

+
- + -

{{'ControlMultiComponent.powerlevels.heading' | translate}}

+

{{'ControlLevelComponent.powerlevels.heading' | translate}}

- {{'ControlMultiComponent.powerlevels.power' | translate}} + {{'ControlLevelComponent.powerlevels.power' | translate}} {{errors.maxPowerConsumption}} {{'ControlMultiComponent.control.heading' | translate}} {{idref}} + >{{'ControlLevelComponent.control.heading' | translate}} {{idref}}
-
diff --git a/src/main/angular/src/app/control/multi/control-multi.component.scss b/src/main/angular/src/app/control/level/control-level.component.scss similarity index 97% rename from src/main/angular/src/app/control/multi/control-multi.component.scss rename to src/main/angular/src/app/control/level/control-level.component.scss index daf67c75..51825bfa 100644 --- a/src/main/angular/src/app/control/multi/control-multi.component.scss +++ b/src/main/angular/src/app/control/level/control-level.component.scss @@ -15,7 +15,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -.ControlMultiComponent { +.ControlLevelComponent { &__addControl { margin-bottom: 2rem !important; } diff --git a/src/main/angular/src/app/control/level/control-level.component.ts b/src/main/angular/src/app/control/level/control-level.component.ts index 797e470d..f450442b 100644 --- a/src/main/angular/src/app/control/level/control-level.component.ts +++ b/src/main/angular/src/app/control/level/control-level.component.ts @@ -24,7 +24,7 @@ import {simpleControlType} from '../../shared/form-util'; import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core'; import {ControlContainer, FormArray, FormBuilder, FormControl, FormGroup, FormGroupDirective} from '@angular/forms'; import {TranslateService} from '@ngx-translate/core'; -import {MultiSwitch} from './multi-switch'; +import {LevelSwitch} from './level-switch'; import {Switch} from '../switch/switch'; import {HttpSwitch} from '../http/http-switch'; import {ListItem} from '../../shared/list-item'; @@ -34,19 +34,20 @@ import {ModbusSwitch} from '../modbus/modbus-switch'; import {HttpWrite} from '../../http/write/http-write'; import {ValueNameChangedEvent} from '../../meter/value-name-changed-event'; import {ModbusSetting} from '../../settings/modbus/modbus-setting'; +import {ModbusWrite} from '../../modbus/write/modbus-write'; @Component({ - selector: 'app-control-multi', - templateUrl: './control-multi.component.html', - styleUrls: ['./control-multi.component.scss'], + selector: 'app-control-level', + templateUrl: './control-level.component.html', + styleUrls: ['./control-level.component.scss'], viewProviders: [ {provide: ControlContainer, useExisting: FormGroupDirective} ], changeDetection: ChangeDetectionStrategy.OnPush }) -export class ControlMultiComponent implements OnChanges, OnInit { +export class ControlLevelComponent implements OnChanges, OnInit { @Input() - multiSwitch: MultiSwitch; + levelSwitch: LevelSwitch; @Input() controlDefaults: ControlDefaults; @Input() @@ -74,11 +75,11 @@ export class ControlMultiComponent implements OnChanges, OnInit { ngOnChanges(changes: SimpleChanges): void { this.form = this.parent.form; - if (changes.multiSwitch) { - if (changes.multiSwitch.currentValue) { - this.multiSwitch = changes.multiSwitch.currentValue; + if (changes.levelSwitch) { + if (changes.levelSwitch.currentValue) { + this.levelSwitch = changes.levelSwitch.currentValue; } else { - this.multiSwitch = new MultiSwitch(); + this.levelSwitch = new LevelSwitch(); } this.expandParentForm(); } @@ -98,21 +99,21 @@ export class ControlMultiComponent implements OnChanges, OnInit { } expandParentForm() { - const firstControlType = simpleControlType(this.multiSwitch?.controls[0]['@class']) ?? Switch.TYPE; + const firstControlType = simpleControlType(this.levelSwitch?.controls[0]['@class']) ?? Switch.TYPE; this.formHandler.addFormControl(this.form, 'realControlType', firstControlType); this.formHandler.addFormArrayControlWithEmptyFormGroups(this.form, 'controls', - this.multiSwitch.controls); - this.controlIds = this.multiSwitch.controls.map(control => control.id); + this.levelSwitch.controls); + this.controlIds = this.levelSwitch.controls.map(control => control.id); this.form.addControl('powerLevels', this.fb.array([])); this.powerLevelFormArray.clear(); - this.multiSwitch.powerLevels.forEach(powerlevel => this.addPowerLevel(powerlevel)); + this.levelSwitch.powerLevels.forEach(powerlevel => this.addPowerLevel(powerlevel)); } realControlTypeChanged(newType?: string | undefined) { for(let i=0; i) { + public constructor(init?: Partial) { Object.assign(this, init); } } diff --git a/src/main/angular/src/app/control/multi/power-level.ts b/src/main/angular/src/app/control/level/power-level.ts similarity index 100% rename from src/main/angular/src/app/control/multi/power-level.ts rename to src/main/angular/src/app/control/level/power-level.ts diff --git a/src/main/angular/src/app/control/multi/switch-status.ts b/src/main/angular/src/app/control/level/switch-status.ts similarity index 100% rename from src/main/angular/src/app/control/multi/switch-status.ts rename to src/main/angular/src/app/control/level/switch-status.ts diff --git a/src/main/angular/src/assets/i18n/de.json b/src/main/angular/src/assets/i18n/de.json index 4d829b2a..b4e78155 100644 --- a/src/main/angular/src/assets/i18n/de.json +++ b/src/main/angular/src/assets/i18n/de.json @@ -148,10 +148,10 @@ "ControlComponent.type": "Typ", "de.avanux.smartapplianceenabler.control.AlwaysOnSwitch": "Immer eingeschaltet", "de.avanux.smartapplianceenabler.control.HttpSwitch": "HTTP", + "de.avanux.smartapplianceenabler.control.LevelSwitch": "Stufenschalter", "de.avanux.smartapplianceenabler.control.MeterReportingSwitch": "Zählerbasierter Zustandsmelder", "de.avanux.smartapplianceenabler.control.MockSwitch": "Testschalter", "de.avanux.smartapplianceenabler.control.ModbusSwitch": "Modbus", - "de.avanux.smartapplianceenabler.control.MultiSwitch": "Multi-Schalter", "de.avanux.smartapplianceenabler.control.PwmSwitch": "PWM", "de.avanux.smartapplianceenabler.control.Switch": "GPIO", @@ -192,12 +192,12 @@ "ControlModbusComponent.button.addModbusWrite": "Weiteres Register", "ControlModbusComponent.error.slaveAddress_pattern": "Die Slave-Adresse muss eine Zahl sein", - "ControlMultiComponent.type": "Realer Schaltertyp", - "ControlMultiComponent.control.heading": "Schalter", - "ControlMultiComponent.button.addControl": "Schalter hinzufügen", - "ControlMultiComponent.button.removeControl": "Schalter löschen", - "ControlMultiComponent.powerlevels.heading": "Leistungsstufen", - "ControlMultiComponent.powerlevels.power": "Leistungsaufnahme [W]", + "ControlLevelComponent.type": "Realer Schaltertyp", + "ControlLevelComponent.control.heading": "Schalter", + "ControlLevelComponent.button.addControl": "Schalter hinzufügen", + "ControlLevelComponent.button.removeControl": "Schalter löschen", + "ControlLevelComponent.powerlevels.heading": "Leistungsstufen", + "ControlLevelComponent.powerlevels.power": "Leistungsaufnahme [W]", "ControlPwmComponent.gpio": "GPIO-Anschluss", "ControlPwmComponent.pwmFrequency": "PWM-Frequenz [Hz]", diff --git a/src/main/java/de/avanux/smartapplianceenabler/appliance/Appliance.java b/src/main/java/de/avanux/smartapplianceenabler/appliance/Appliance.java index 75fe6687..b900cf7b 100644 --- a/src/main/java/de/avanux/smartapplianceenabler/appliance/Appliance.java +++ b/src/main/java/de/avanux/smartapplianceenabler/appliance/Appliance.java @@ -59,7 +59,7 @@ public class Appliance implements Validateable, TimeframeIntervalChangedListener @XmlElement(name = "MeterReportingSwitch", type = MeterReportingSwitch.class), @XmlElement(name = "MockSwitch", type = MockSwitch.class), @XmlElement(name = "ModbusSwitch", type = ModbusSwitch.class), - @XmlElement(name = "MultiSwitch", type =MultiSwitch.class), + @XmlElement(name = "LevelSwitch", type = LevelSwitch.class), @XmlElement(name = "StartingCurrentSwitch", type = StartingCurrentSwitch.class), @XmlElement(name = "Switch", type = Switch.class), @XmlElement(name = "PwmSwitch", type = PwmSwitch.class), diff --git a/src/main/java/de/avanux/smartapplianceenabler/control/MultiSwitch.java b/src/main/java/de/avanux/smartapplianceenabler/control/LevelSwitch.java similarity index 98% rename from src/main/java/de/avanux/smartapplianceenabler/control/MultiSwitch.java rename to src/main/java/de/avanux/smartapplianceenabler/control/LevelSwitch.java index 2353cbc0..2bea25f2 100644 --- a/src/main/java/de/avanux/smartapplianceenabler/control/MultiSwitch.java +++ b/src/main/java/de/avanux/smartapplianceenabler/control/LevelSwitch.java @@ -38,8 +38,8 @@ import java.util.*; @XmlAccessorType(XmlAccessType.FIELD) -public class MultiSwitch implements VariablePowerConsumer, ApplianceIdConsumer, Validateable, NotificationProvider { - private transient Logger logger = LoggerFactory.getLogger(MultiSwitch.class); +public class LevelSwitch implements VariablePowerConsumer, ApplianceIdConsumer, Validateable, NotificationProvider { + private transient Logger logger = LoggerFactory.getLogger(LevelSwitch.class); @XmlAttribute private String id; @XmlElements({ diff --git a/src/main/java/de/avanux/smartapplianceenabler/semp/webservice/SempController.java b/src/main/java/de/avanux/smartapplianceenabler/semp/webservice/SempController.java index 44798b3a..77d04e72 100644 --- a/src/main/java/de/avanux/smartapplianceenabler/semp/webservice/SempController.java +++ b/src/main/java/de/avanux/smartapplianceenabler/semp/webservice/SempController.java @@ -20,7 +20,7 @@ import de.avanux.smartapplianceenabler.appliance.Appliance; import de.avanux.smartapplianceenabler.appliance.ApplianceManager; import de.avanux.smartapplianceenabler.control.Control; -import de.avanux.smartapplianceenabler.control.MultiSwitch; +import de.avanux.smartapplianceenabler.control.LevelSwitch; import de.avanux.smartapplianceenabler.control.VariablePowerConsumer; import de.avanux.smartapplianceenabler.meter.Meter; import de.avanux.smartapplianceenabler.mqtt.*; @@ -183,9 +183,9 @@ private Characteristics createCharacteristics(DeviceInfo deviceInfo, VariablePow characteristics.setMinOffTime(deviceInfo.getCharacteristics().getMinOffTime()); characteristics.setMaxOnTime(deviceInfo.getCharacteristics().getMaxOnTime()); characteristics.setMaxOffTime(deviceInfo.getCharacteristics().getMaxOffTime()); - if(variablePowerConsumer instanceof MultiSwitch) { + if(variablePowerConsumer instanceof LevelSwitch) { List powerLevelValues = new ArrayList<>(); - ((MultiSwitch) variablePowerConsumer).getPowerLevels().forEach(pl -> powerLevelValues.add(pl.getPower())); + ((LevelSwitch) variablePowerConsumer).getPowerLevels().forEach(pl -> powerLevelValues.add(pl.getPower())); PowerLevels powerLevels = new PowerLevels(); powerLevels.setPowerLevels(powerLevelValues); characteristics.setPowerLevels(powerLevels); diff --git a/xsd/SmartApplianceEnabler-2.0.xsd b/xsd/SmartApplianceEnabler-2.0.xsd index 57c744ef..7db3cfd9 100644 --- a/xsd/SmartApplianceEnabler-2.0.xsd +++ b/xsd/SmartApplianceEnabler-2.0.xsd @@ -64,11 +64,11 @@ - + - + @@ -90,7 +90,7 @@ - + @@ -367,7 +367,7 @@ - +