Relay toggle buttons initial state reflects current relay state

This commit is contained in:
Zakary Timson 2019-01-01 22:26:23 -05:00
parent 31f0399e35
commit 521bbadb0c
2 changed files with 10 additions and 11 deletions

View File

@ -1,10 +1,10 @@
<div class="desktop-height p-3" style="background-color: #b52e3c !important;">
<div style="max-width: 1000px;">
<h1 class="text-white">Powerwall: {{batteryService.charge | round}} V</h1>
<mat-button-toggle-group [(ngModel)]="batteryService.relayMode" (change)="batteryService.setRelayMode($event.value)">
<mat-button-toggle [value]="null" checked>Auto</mat-button-toggle>
<mat-button-toggle [value]="true">On</mat-button-toggle>
<mat-button-toggle [value]="false">Off</mat-button-toggle>
<mat-button-toggle-group [ngModel]="batteryService.relayMode" (change)="batteryService.setRelayMode($event.value)"><!---->
<mat-button-toggle value="null">Auto</mat-button-toggle>
<mat-button-toggle value="true">On</mat-button-toggle>
<mat-button-toggle value="false">Off</mat-button-toggle>
</mat-button-toggle-group>
<mat-card class="mt-2" *ngFor="let battery of batteryService.batteries; let i = index">
<div class="d-flex">

View File

@ -10,7 +10,7 @@ export class BatteryService {
batteries = [];
charge: number;
lastCharge: number;
relayMode?: boolean = null;
relayMode: string = 'null';
temp: number = 0;
get charging() { return this.lastCharge < this.charge; }
@ -47,10 +47,7 @@ export class BatteryService {
this.firestore.settings({timestampsInSnapshots: true});
this.firestore.collection('Battery').doc('170614D').onSnapshot(snap => {
let data = snap.data();
this.relayMode = data.config.relayMode || null
;
this.relayMode = data.config.relayMode ? data.config.relayMode.toString() : 'null';
this.batteries = Object.keys(data.modules).map(key => {
let last = data.modules[key].length - 1;
return {
@ -67,7 +64,9 @@ export class BatteryService {
});
}
setRelayMode(mode?:boolean) {
this.firestore.collection('Battery').doc('170614D').update({config: {relayMode: mode}});
setRelayMode(mode?: string) {
if(mode == 'null') this.firestore.collection('Battery').doc('170614D').update({config: {relayMode: null}});
else if(mode == 'true') this.firestore.collection('Battery').doc('170614D').update({config: {relayMode: true}});
else if(mode == 'false') this.firestore.collection('Battery').doc('170614D').update({config: {relayMode: false}});
}
}