Skip to content

Commit

Permalink
#223 MultiSwitch renamed to LevelSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Müller committed Apr 7, 2022
1 parent 3bd5af0 commit fe9dd91
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 80 deletions.
4 changes: 2 additions & 2 deletions run/Appliances.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Appliances xmlns="http://github.com/camueller/SmartApplianceEnabler/v2.0">
<Configuration param="NodeRED.Dashboard.Url" value="http://localhost:1880"/>
<Appliance id="F-00000001-000000000002-00">
<MultiSwitch>
<LevelSwitch>
<!--HttpSwitch id="1">
<HttpWrite url="http://tasmota/cm?cmnd=Power%20On">
<HttpWriteValue name="On" method="GET"/>
Expand Down Expand Up @@ -52,7 +52,7 @@
<SwitchStatus idref="1" on="true"/>
<SwitchStatus idref="2" on="true"/>
</PowerLevel>
</MultiSwitch>
</LevelSwitch>
<HttpElectricityMeter contentProtocol="JSON">
<HttpRead url="http://tasmota/cm?cmnd=Status%208">
<HttpReadValue name="Energy" method="GET" path="$.StatusSNS.ENERGY.Total"/>
Expand Down
10 changes: 5 additions & 5 deletions src/main/angular/src/app/control/control-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {EvCharger} from './evcharger/ev-charger';
import {ElectricVehicle} from './evcharger/electric-vehicle/electric-vehicle';
import {MeterReportingSwitch} from './meterreporting/meter-reporting-switch';
import {PwmSwitch} from './pwm/pwm-switch';
import {MultiSwitch} from './multi/multi-switch';
import {LevelSwitch} from './level/level-switch';

export class ControlFactory {

Expand Down Expand Up @@ -82,8 +82,8 @@ export class ControlFactory {
control.switch_ = this.createSwitch(rawControl);
} else if (control.type === ModbusSwitch.TYPE) {
control.modbusSwitch = this.createModbusSwitch(rawControl);
} else if (control.type === MultiSwitch.TYPE) {
control.multiSwitch = this.createMultiSwitch(rawControl);
} else if (control.type === LevelSwitch.TYPE) {
control.levelSwitch = this.createLevelSwitch(rawControl);
} else if (control.type === PwmSwitch.TYPE) {
control.pwmSwitch = this.createPwmSwitch(rawControl);
} else if (control.type === EvCharger.TYPE) {
Expand Down Expand Up @@ -142,8 +142,8 @@ export class ControlFactory {
return new HttpSwitch(rawHttpSwitch);
}

createMultiSwitch(rawMultiSwitch: any): MultiSwitch {
return new MultiSwitch(rawMultiSwitch);
createLevelSwitch(rawLevelSwitch: any): LevelSwitch {
return new LevelSwitch(rawLevelSwitch);
}

createPwmSwitch(rawPwmSwitch: any): PwmSwitch {
Expand Down
6 changes: 3 additions & 3 deletions src/main/angular/src/app/control/control.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
[httpSwitch]="control.httpSwitch"
[controlDefaults]="controlDefaults"
></app-control-http>
<app-control-multi *ngIf="isMultiSwitch"
[multiSwitch]="control.multiSwitch"
<app-control-level *ngIf="isLevelSwitch"
[levelSwitch]="control.levelSwitch"
[controlDefaults]="controlDefaults"
[modbusSettings]="settings.modbusSettings"
[modbusConfigured]="!!settings.modbusSettings?.length"
></app-control-multi>
></app-control-level>
<app-control-pwm *ngIf="isPwmSwitch"
[pwmSwitch]="control.pwmSwitch"
></app-control-pwm>
Expand Down
10 changes: 5 additions & 5 deletions src/main/angular/src/app/control/control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {NotificationType} from '../notification/notification-type';
import {ControlMeterreportingComponent} from './meterreporting/control-meterreporting.component';
import {ControlPwmComponent} from './pwm/control-pwm.component';
import {PwmSwitch} from './pwm/pwm-switch';
import {MultiSwitch} from './multi/multi-switch';
import {LevelSwitch} from './level/level-switch';

@Component({
selector: 'app-control',
Expand Down Expand Up @@ -123,7 +123,7 @@ export class ControlComponent implements OnInit, CanDeactivate<ControlComponent>
if (this.appliance.type === 'EVCharger') {
this.control.type = EvCharger.TYPE;
}
const controlTypeKeys = [MeterReportingSwitch.TYPE, Switch.TYPE, HttpSwitch.TYPE, AlwaysOnSwitch.TYPE, MultiSwitch.TYPE, PwmSwitch.TYPE];
const controlTypeKeys = [MeterReportingSwitch.TYPE, Switch.TYPE, HttpSwitch.TYPE, AlwaysOnSwitch.TYPE, LevelSwitch.TYPE, PwmSwitch.TYPE];
if(this.settings.modbusSettings) {
controlTypeKeys.splice(3, 0, ModbusSwitch.TYPE);
}
Expand Down Expand Up @@ -203,8 +203,8 @@ export class ControlComponent implements OnInit, CanDeactivate<ControlComponent>
return this.control && this.control.type === HttpSwitch.TYPE;
}

get isMultiSwitch() {
return this.control && this.control.type === MultiSwitch.TYPE;
get isLevelSwitch() {
return this.control && this.control.type === LevelSwitch.TYPE;
}

get isPwmSwitch() {
Expand Down Expand Up @@ -247,7 +247,7 @@ export class ControlComponent implements OnInit, CanDeactivate<ControlComponent>
}

get canHaveStartingCurrentDetection(): boolean {
return !(this.isMeterReportingSwitch || this.isAlwaysOnSwitch || this.isPwmSwitch || this.isMultiSwitch || this.control.type === MockSwitch.TYPE);
return !(this.isMeterReportingSwitch || this.isAlwaysOnSwitch || this.isPwmSwitch || this.isLevelSwitch || this.control.type === MockSwitch.TYPE);
}

toggleStartingCurrentDetection() {
Expand Down
4 changes: 2 additions & 2 deletions src/main/angular/src/app/control/control.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {HttpLoaderFactory} from '../shared/http-loader-factory';
import {NotificationModule} from '../notification/notification.module';
import { ControlMeterreportingComponent } from './meterreporting/control-meterreporting.component';
import {ControlPwmComponent} from './pwm/control-pwm.component';
import {ControlMultiComponent} from './multi/control-multi.component';
import {ControlLevelComponent} from './level/control-level.component';

@NgModule({
declarations: [
Expand All @@ -34,7 +34,7 @@ import {ControlMultiComponent} from './multi/control-multi.component';
ControlHttpComponent,
ControlMeterreportingComponent,
ControlModbusComponent,
ControlMultiComponent,
ControlLevelComponent,
ControlPwmComponent,
ControlStartingcurrentComponent,
ControlSwitchComponent,
Expand Down
4 changes: 2 additions & 2 deletions src/main/angular/src/app/control/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {EvCharger} from './evcharger/ev-charger';
import {Notifications} from '../notification/notifications';
import {MeterReportingSwitch} from './meterreporting/meter-reporting-switch';
import {PwmSwitch} from './pwm/pwm-switch';
import {MultiSwitch} from './multi/multi-switch';
import {LevelSwitch} from './level/level-switch';

export class Control {
type: string;
Expand All @@ -38,7 +38,7 @@ export class Control {
modbusSwitch?: ModbusSwitch;
mockSwitch?: MockSwitch;
httpSwitch?: HttpSwitch;
multiSwitch?: MultiSwitch;
levelSwitch?: LevelSwitch;
pwmSwitch?: PwmSwitch;
evCharger?: EvCharger;
notifications?: Notifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->

<div class="ControlMultiComponent">
<div class="ControlLevelComponent">
<div class="sae__fields">
<div class="field">
<mat-form-field class="ControlMultiComponent__controlType">
<mat-label>{{'ControlMultiComponent.type' | translate}}</mat-label>
<mat-form-field class="ControlLevelComponent__controlType">
<mat-label>{{'ControlLevelComponent.type' | translate}}</mat-label>
<mat-select formControlName="realControlType" required="{{formHandler.isRequired('realControlType')}}" (ngModelChange)="realControlTypeChanged($event)">
<mat-option *ngFor="let controlType of controlTypes" [value]="controlType.value">
{{controlType.viewValue}}
Expand All @@ -30,63 +30,63 @@
</div>
</div>
<div formArrayName="controls" *ngIf="isRealControlTypeSwitch">
<app-control-switch *ngFor="let control of multiSwitch.controls; index as i; last as l"
<app-control-switch *ngFor="let control of levelSwitch.controls; index as i; last as l"
[formGroup]="getControlFormGroup(i)"
[switch_]="control"
[controlDefaults]="controlDefaults"
>
<div class="sae__fields-with-button">
<h2>{{'ControlMultiComponent.control.heading' | translate}} {{control.id}}</h2>
<button mat-raised-button type="button" class="ControlMultiComponent__removeControl" (click)="removeControl(i)">
{{'ControlMultiComponent.button.removeControl' | translate}}</button>
<h2>{{'ControlLevelComponent.control.heading' | translate}} {{control.id}}</h2>
<button mat-raised-button type="button" class="ControlLevelComponent__removeControl" (click)="removeControl(i)">
{{'ControlLevelComponent.button.removeControl' | translate}}</button>
</div>
</app-control-switch>
</div>
<div formArrayName="controls" *ngIf="isRealControlTypeHttp">
<app-control-http *ngFor="let control of multiSwitch.controls; index as i; last as l"
<app-control-http *ngFor="let control of levelSwitch.controls; index as i; last as l"
[formGroup]="getControlFormGroup(i)"
[httpSwitch]="control"
[controlDefaults]="controlDefaults"
>
<div class="sae__fields-with-button">
<h2>{{'ControlMultiComponent.control.heading' | translate}} {{control.id}}</h2>
<button mat-raised-button type="button" class="ControlMultiComponent__removeControl" (click)="removeControl(i)">
{{'ControlMultiComponent.button.removeControl' | translate}}</button>
<h2>{{'ControlLevelComponent.control.heading' | translate}} {{control.id}}</h2>
<button mat-raised-button type="button" class="ControlLevelComponent__removeControl" (click)="removeControl(i)">
{{'ControlLevelComponent.button.removeControl' | translate}}</button>
</div>
</app-control-http>
</div>
<div formArrayName="controls" *ngIf="isRealControlTypeModbus">
<app-control-modbus *ngFor="let control of multiSwitch.controls; index as i; last as l"
<app-control-modbus *ngFor="let control of levelSwitch.controls; index as i; last as l"
[formGroup]="getControlFormGroup(i)"
[modbusSwitch]="control"
[modbusSettings]="modbusSettings"
[controlDefaults]="controlDefaults"
>
<div class="sae__fields-with-button">
<h2>{{'ControlMultiComponent.control.heading' | translate}} {{control.id}}</h2>
<button mat-raised-button type="button" class="ControlMultiComponent__removeControl" (click)="removeControl(i)">
{{'ControlMultiComponent.button.removeControl' | translate}}</button>
<h2>{{'ControlLevelComponent.control.heading' | translate}} {{control.id}}</h2>
<button mat-raised-button type="button" class="ControlLevelComponent__removeControl" (click)="removeControl(i)">
{{'ControlLevelComponent.button.removeControl' | translate}}</button>
</div>
</app-control-modbus>
</div>

<button mat-raised-button type="button" class="ControlMultiComponent__addControl"
(click)="addControl()">{{'ControlMultiComponent.button.addControl' | translate}}</button>
<button mat-raised-button type="button" class="ControlLevelComponent__addControl"
(click)="addControl()">{{'ControlLevelComponent.button.addControl' | translate}}</button>

<h2>{{'ControlMultiComponent.powerlevels.heading' | translate}}</h2>
<h2>{{'ControlLevelComponent.powerlevels.heading' | translate}}</h2>
<div formArrayName="powerLevels" *ngFor="let powerLevel of powerLevelFormArray.controls; let i = index;">
<div [formGroupName]="i">
<mat-form-field class="power">
<mat-label>{{'ControlMultiComponent.powerlevels.power' | translate}}</mat-label>
<mat-label>{{'ControlLevelComponent.powerlevels.power' | translate}}</mat-label>
<input matInput type="text" formControlName="power"
required="{{formHandler.isRequired('power')}}">
<mat-error *ngIf="errors.maxPowerConsumption">{{errors.maxPowerConsumption}}</mat-error>
</mat-form-field>
<mat-checkbox *ngFor="let idref of controlIds" formControlName="{{idref}}"
>{{'ControlMultiComponent.control.heading' | translate}} {{idref}}</mat-checkbox>
>{{'ControlLevelComponent.control.heading' | translate}} {{idref}}</mat-checkbox>
<button mat-raised-button (click)="removePowerLevel(i)">{{'button.delete' | translate}}</button>
</div>
</div>
<button mat-raised-button type="button" class="ControlMultiComponent__addPowerLevel"
<button mat-raised-button type="button" class="ControlLevelComponent__addPowerLevel"
(click)="addPowerLevel()">{{'button.new' | translate}}</button>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
37 changes: 19 additions & 18 deletions src/main/angular/src/app/control/level/control-level.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()
Expand Down Expand Up @@ -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();
}
Expand All @@ -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<this.controlsFormArray.length; i++) {
this.controlsFormArray.removeAt(i);
}
this.multiSwitch.controls = [];
this.levelSwitch.controls = [];
this.controlIds = [];
this.form.markAsDirty();
this.changeDetectorRef.detectChanges();
Expand Down Expand Up @@ -165,7 +166,7 @@ export class ControlMultiComponent implements OnChanges, OnInit {

removeControl(index: number) {
this.controlsFormArray.removeAt(index);
this.multiSwitch.controls.splice(index, 1);
this.levelSwitch.controls.splice(index, 1);

this.controlIds.splice(index, 1);

Expand Down Expand Up @@ -202,7 +203,7 @@ export class ControlMultiComponent implements OnChanges, OnInit {
this.powerLevelFormArray.removeAt(index);
}

updateModelFromForm(): MultiSwitch | undefined {
return this.multiSwitch;
updateModelFromForm(): LevelSwitch | undefined {
return this.levelSwitch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import {ModbusSwitch} from '../modbus/modbus-switch';
import {HttpSwitch} from '../http/http-switch';
import {PowerLevel} from './power-level';

export class MultiSwitch {
export class LevelSwitch {
static get TYPE(): string {
return 'de.avanux.smartapplianceenabler.control.MultiSwitch';
return 'de.avanux.smartapplianceenabler.control.LevelSwitch';
}
'@class' = MultiSwitch.TYPE;
'@class' = LevelSwitch.TYPE;
controls?: (Switch | HttpSwitch | ModbusSwitch)[];
powerLevels?: PowerLevel[];

public constructor(init?: Partial<MultiSwitch>) {
public constructor(init?: Partial<LevelSwitch>) {
Object.assign(this, init);
}
}
14 changes: 7 additions & 7 deletions src/main/angular/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down Expand Up @@ -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]",
Expand Down
Loading

0 comments on commit fe9dd91

Please sign in to comment.