Relay toggle buttons initial state reflects current relay state

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

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}});
}
}