Fixed fan buttons

This commit is contained in:
Zakary Timson 2019-01-01 17:10:08 -05:00
parent 7eb85ce630
commit cec1e09bb0
2 changed files with 6 additions and 11 deletions

View File

@ -4,7 +4,7 @@
<h3 class="mb-0 text-white">Powerwall: {{batteryService.total | round}} V</h3> <h3 class="mb-0 text-white">Powerwall: {{batteryService.total | round}} V</h3>
</div> </div>
<div class="d-flex flex-grow-1 align-content-center justify-content-end"> <div class="d-flex flex-grow-1 align-content-center justify-content-end">
<mat-button-toggle-group (change)="batteryService.setRelayMode($event.value)"> <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]="null" checked>Auto</mat-button-toggle>
<mat-button-toggle [value]="true">On</mat-button-toggle> <mat-button-toggle [value]="true">On</mat-button-toggle>
<mat-button-toggle [value]="false">Off</mat-button-toggle> <mat-button-toggle [value]="false">Off</mat-button-toggle>

View File

@ -9,6 +9,7 @@ export class BatteryService {
batteries = []; batteries = [];
last: Date; last: Date;
relayMode?: boolean = null;
total: number = 0; total: number = 0;
get icon() { get icon() {
@ -45,6 +46,9 @@ export class BatteryService {
this.firestore.collection('Battery').doc('170614D').onSnapshot(snap => { this.firestore.collection('Battery').doc('170614D').onSnapshot(snap => {
this.last = new Date(); this.last = new Date();
let data = snap.data(); let data = snap.data();
this.relayMode = data.config.relayMode || null;
this.batteries = Object.keys(data.modules).map(key => { this.batteries = Object.keys(data.modules).map(key => {
let last = data.modules[key].length - 1; let last = data.modules[key].length - 1;
return { return {
@ -56,20 +60,11 @@ export class BatteryService {
tempHistory: data.modules[key].map((val, i) => ({name: i, value: val.temp})) tempHistory: data.modules[key].map((val, i) => ({name: i, value: val.temp}))
} }
}); });
this.batteries.map((battery, i, arr) => {
if(i % 2 == 1) return battery;
console.log(i, battery.charge);
battery.charge = battery.charge - arr[i + 1].charge;
});
this.total = this.batteries.reduce((acc, battery) => acc + battery.charge, 0) / 2; this.total = this.batteries.reduce((acc, battery) => acc + battery.charge, 0) / 2;
console.log(this.batteries)
}); });
} }
setRelayMode(mode?:boolean) { setRelayMode(mode?:boolean) {
this.firestore.collection('Battery').doc('170724D').update({config: {relayMode: mode}}); this.firestore.collection('Battery').doc('170614D').update({config: {relayMode: mode}});
} }
} }