) {
diff --git a/src/main/angular/src/app/location/power/location-power.html b/src/main/angular/src/app/location/power/location-power.html
index d7e2ad1..4170907 100644
--- a/src/main/angular/src/app/location/power/location-power.html
+++ b/src/main/angular/src/app/location/power/location-power.html
@@ -11,11 +11,11 @@
Bezug
- {{ location.powerPurchase?.value?.toValueString(dateService.now) }}
+ {{ powerPurchase.toValueString(dateService.now) }}
@if (configService.energyPercent) {
- {{ location.powerPurchasePercentConsume.toValueString(dateService.now) }}
+ {{ powerPurchasePercentConsume.toValueString(dateService.now) }}
Verbrauch
}
@@ -26,11 +26,11 @@
Solar
- {{ location.powerProduce?.value?.toValueString(dateService.now) }}
+ {{ powerProduce.toValueString(dateService.now) }}
@if (configService.energyPercent) {
- {{ location.powerProducePercentConsume.toValueString(dateService.now) }}
+ {{ powerProducePercentConsume.toValueString(dateService.now) }}
Verbrauch
}
@@ -41,15 +41,15 @@
Selbst
- {{ location.powerSelf.toValueString(dateService.now) }}
+ {{ powerSelf.toValueString(dateService.now) }}
@if (configService.energyPercent) {
- {{ location.powerSelfPercentConsume.toValueString(dateService.now) }}
+ {{ powerSelfPercentConsume.toValueString(dateService.now) }}
Verbrauch
- {{ location.powerSelfPercentProduce.toValueString(dateService.now) }}
+ {{ powerSelfPercentProduce.toValueString(dateService.now) }}
Produktion
}
@@ -60,7 +60,7 @@
Verbrauch
- {{ location.powerConsume?.toValueString(dateService.now) }}
+ {{ powerConsume.toValueString(dateService.now) }}
@@ -69,15 +69,15 @@
Einspeisung
- {{ location.powerDeliver?.value?.toValueString(dateService.now) }}
+ {{ powerDeliver.toValueString(dateService.now) }}
@if (configService.energyPercent) {
- {{ location.powerDeliveryPercentConsume.toValueString(dateService.now) }}
+ {{ powerDeliverPercentConsume.toValueString(dateService.now) }}
Verbrauch
- {{ location.powerDeliveryPercentProduce.toValueString(dateService.now) }}
+ {{ powerDeliverPercentProduce.toValueString(dateService.now) }}
Produktion
}
diff --git a/src/main/angular/src/app/location/power/location-power.ts b/src/main/angular/src/app/location/power/location-power.ts
index 555de35..13fc91e 100644
--- a/src/main/angular/src/app/location/power/location-power.ts
+++ b/src/main/angular/src/app/location/power/location-power.ts
@@ -1,7 +1,11 @@
-import {Component, Input} from '@angular/core';
+import {Component, Input, OnChanges, OnDestroy, OnInit} from '@angular/core';
import {Location} from '../Location';
import {DateService} from '../../date.service';
import {ConfigService} from '../../config.service';
+import {Value} from '../../series/Value';
+import {SeriesService} from '../../series/series-service';
+import {Subscription} from 'rxjs';
+import {Series} from '../../series/Series';
@Component({
selector: 'app-location-power',
@@ -9,16 +13,86 @@ import {ConfigService} from '../../config.service';
templateUrl: './location-power.html',
styleUrl: './location-power.less',
})
-export class LocationPower {
+export class LocationPower implements OnInit, OnChanges, OnDestroy {
@Input()
location!: Location;
+ private readonly subs: Subscription[] = [];
+
+ protected energyPurchase: Value = Value.NULL;
+
+ protected energyDeliver: Value = Value.NULL;
+
+ protected energyProduce: Value = Value.NULL;
+
+ protected powerPurchase: Value = Value.NULL;
+
+ protected powerDeliver: Value = Value.NULL;
+
+ protected powerProduce: Value = Value.NULL;
+
+ protected outsideTemperature: Value = Value.NULL;
+
+ protected outsideHumidityRelative: Value = Value.NULL;
+
+ protected outsideHumidityAbsolute: Value = Value.NULL;
+
+ protected powerConsume: Value = Value.NULL;
+
+ protected powerSelf: Value = Value.NULL;
+
+ protected powerPurchasePercentConsume: Value = Value.NULL;
+
+ protected powerProducePercentConsume: Value = Value.NULL;
+
+ protected powerDeliverPercentConsume: Value = Value.NULL;
+
+ protected powerDeliverPercentProduce: Value = Value.NULL;
+
+ protected powerSelfPercentConsume: Value = Value.NULL;
+
+ protected powerSelfPercentProduce: Value = Value.NULL;
+
constructor(
readonly dateService: DateService,
readonly configService: ConfigService,
+ readonly seriesService: SeriesService,
) {
//
}
+ ngOnInit(): void {
+ this.subs.push(this.seriesService.subscribe(this.seriesUpdate));
+ }
+
+ ngOnChanges(): void {
+ this.location.getSeries().forEach(this.seriesUpdate);
+ }
+
+ ngOnDestroy(): void {
+ this.subs.forEach(sub => sub.unsubscribe());
+ this.subs.length = 0;
+ }
+
+ private readonly seriesUpdate = (series: Series): void => {
+ if (series.id === this.location.energyPurchase?.id) this.energyPurchase = series.value;
+ if (series.id === this.location.energyDeliver?.id) this.energyDeliver = series.value;
+ if (series.id === this.location.energyProduce?.id) this.energyProduce = series.value;
+ if (series.id === this.location.powerPurchase?.id) this.powerPurchase = series.value;
+ if (series.id === this.location.powerDeliver?.id) this.powerDeliver = series.value;
+ if (series.id === this.location.powerProduce?.id) this.powerProduce = series.value;
+ if (series.id === this.location.outsideTemperature?.id) this.outsideTemperature = series.value;
+ if (series.id === this.location.outsideHumidityRelative?.id) this.outsideHumidityRelative = series.value;
+ if (series.id === this.location.outsideHumidityAbsolute?.id) this.outsideHumidityAbsolute = series.value;
+ this.powerSelf = Value.ZERO.plus(this.powerProduce).minus(this.powerDeliver);
+ this.powerConsume = Value.ZERO.plus(this.powerPurchase).plus(this.powerSelf);
+ this.powerPurchasePercentConsume = this.powerPurchase.percent(this.powerConsume);
+ this.powerProducePercentConsume = this.powerProduce.percent(this.powerConsume);
+ this.powerDeliverPercentConsume = this.powerDeliver.percent(this.powerConsume)
+ this.powerDeliverPercentProduce = this.powerDeliver.percent(this.powerProduce)
+ this.powerSelfPercentConsume = this.powerSelf.percent(this.powerConsume);
+ this.powerSelfPercentProduce = this.powerSelf.percent(this.powerProduce);
+ };
+
}
diff --git a/src/main/angular/src/app/menu-service.ts b/src/main/angular/src/app/menu-service.ts
index 1107f68..b816036 100644
--- a/src/main/angular/src/app/menu-service.ts
+++ b/src/main/angular/src/app/menu-service.ts
@@ -1,18 +1,31 @@
import {Injectable} from '@angular/core';
+import {Location} from './location/Location';
@Injectable({
providedIn: 'root'
})
export class MenuService {
+ private _locationId: number | null = null;
+
private _title: string = "";
+ get locationId(): number | null {
+ return this._locationId;
+ }
+
get title(): string {
return this._title;
}
- set title(value: string) {
- setTimeout(() => this._title = value, 0);
+ setLocation(location: Location): void {
+ this._locationId = location.id;
+ this._title = location.name;
+ }
+
+ setNonLocation(title: string) {
+ this._title = title;
+ this._locationId = null;
}
}
diff --git a/src/main/angular/src/app/series/SeriesListResponse.ts b/src/main/angular/src/app/series/SeriesListResponse.ts
new file mode 100644
index 0000000..ad3cd61
--- /dev/null
+++ b/src/main/angular/src/app/series/SeriesListResponse.ts
@@ -0,0 +1,22 @@
+import {Series} from "./Series";
+import {validateList} from "../common";
+
+export class SeriesListResponse {
+
+ constructor(
+ readonly series: Series[]
+ ) {
+ //
+ }
+
+ static fromJson(json: any): SeriesListResponse {
+ return new SeriesListResponse(
+ validateList(json, Series.fromJson),
+ );
+ }
+
+ findSeries(series: Series | null): Series | null {
+ return series ? this.series.filter(s => s.id === series.id)[0] || null : null;
+ }
+
+}
diff --git a/src/main/angular/src/app/series/Value.ts b/src/main/angular/src/app/series/Value.ts
index 0aa736f..bb33e7b 100644
--- a/src/main/angular/src/app/series/Value.ts
+++ b/src/main/angular/src/app/series/Value.ts
@@ -29,7 +29,7 @@ export class Value {
return `--- ${this.unit}`
}
const scale = Math.floor(Math.log10(this.value));
- if(isNaN(scale)) {
+ if (isNaN(scale)) {
return '0';
}
const rest = scale - this.precision + 1;
@@ -39,14 +39,14 @@ export class Value {
return formatNumber(this.value, "de-DE", `0.${-rest}-${-rest}`) + ' ' + this.unit;
}
- plus(other: Value | null | undefined, nullToZero: boolean): Value {
+ plus(other: Value | null | undefined, nullToZero: boolean = true): Value {
if (!nullToZero && (other === null || other === undefined)) {
return Value.NULL;
}
return new BiValue(this, other || Value.ZERO, (a, b) => a + b);
}
- minus(other: Value | null | undefined, nullToZero: boolean): Value {
+ minus(other: Value | null | undefined, nullToZero: boolean = true): Value {
if (!nullToZero && (other === null || other === undefined)) {
return Value.NULL;
}
@@ -86,11 +86,11 @@ export class Value {
return ageSeconds > this.seconds * 2.1;
}
- percent(other: Value | null | undefined, unit: string | null = null, precision: number | null = null): Value {
+ percent(other: Value | null | undefined): Value {
if (other === null || other === undefined) {
return Value.NULL;
}
- return new BiValue(this, other, (a, b) => a / b * 100, unit, precision);
+ return new BiValue(this, other, (a, b) => a / b * 100, '%', 0);
}
}
diff --git a/src/main/angular/src/app/settings/settings-component.ts b/src/main/angular/src/app/settings/settings-component.ts
index 3e267d9..9acf542 100644
--- a/src/main/angular/src/app/settings/settings-component.ts
+++ b/src/main/angular/src/app/settings/settings-component.ts
@@ -1,6 +1,5 @@
import {Component, OnInit} from '@angular/core';
import {LocationSelect} from '../location/select/location-select';
-import {LocationService} from '../location/location-service';
import {Location} from '../location/Location'
import {ConfigService} from '../config.service';
import {FormsModule} from '@angular/forms';
@@ -22,7 +21,6 @@ export class SettingsComponent implements OnInit {
protected location: Location | null = null;
constructor(
- readonly locationService: LocationService,
readonly configService: ConfigService,
readonly menuService: MenuService,
) {
@@ -30,7 +28,7 @@ export class SettingsComponent implements OnInit {
}
ngOnInit(): void {
- this.menuService.title = "Einstellungen";
+ this.menuService.setNonLocation("Einstellungen");
}
}