From 536712dab34440611b4f907dfb4a80a59bd32eb8 Mon Sep 17 00:00:00 2001 From: Maschga <88616799+Maschga@users.noreply.github.com> Date: Wed, 4 Sep 2024 20:10:50 +0200 Subject: [PATCH] Add support for megawatt (#15818) --- assets/js/components/BatterySettingsModal.vue | 8 +- assets/js/components/ChargingPlan.vue | 2 +- assets/js/components/ChargingPlanPreview.vue | 2 +- .../components/ChargingPlanSettingsEntry.vue | 2 +- assets/js/components/ChargingPlanWarnings.vue | 4 +- assets/js/components/ChargingSessionModal.vue | 17 +++- assets/js/components/Config/DeviceTags.vue | 8 +- .../js/components/Energyflow/Energyflow.vue | 33 ++++--- .../components/Energyflow/EnergyflowEntry.vue | 4 +- .../components/Energyflow/Visualization.vue | 8 +- assets/js/components/LimitEnergySelect.vue | 4 +- assets/js/components/Loadpoint.vue | 8 +- .../js/components/LoadpointSettingsModal.vue | 8 +- assets/js/components/Savings.vue | 14 ++- assets/js/components/Vehicle.vue | 5 +- assets/js/mixins/formatter.js | 44 ++++++--- assets/js/mixins/formatter.test.js | 91 +++++++++++++------ assets/js/utils/energyOptions.js | 10 +- assets/js/views/ChargingSessions.vue | 6 +- 19 files changed, 179 insertions(+), 99 deletions(-) diff --git a/assets/js/components/BatterySettingsModal.vue b/assets/js/components/BatterySettingsModal.vue index a5554035b..edc5916f7 100644 --- a/assets/js/components/BatterySettingsModal.vue +++ b/assets/js/components/BatterySettingsModal.vue @@ -256,7 +256,7 @@ import "@h2d2/shopicons/es/regular/home"; import SmartCostLimit from "./SmartCostLimit.vue"; import CustomSelect from "./CustomSelect.vue"; import GenericModal from "./GenericModal.vue"; -import formatter from "../mixins/formatter"; +import formatter, { POWER_UNIT } from "../mixins/formatter"; import collector from "../mixins/collector"; import api from "../api"; import smartCostAvailable from "../utils/smartCostAvailable"; @@ -363,13 +363,13 @@ export default { .filter(({ capacity }) => capacity > 0) .map(({ soc, capacity }) => { const multipleBatteries = this.battery.length > 1; - const energy = this.fmtKWh( + const energy = this.fmtWh( (capacity / 100) * soc * 1e3, - true, + POWER_UNIT.KW, !multipleBatteries, 1 ); - const total = this.fmtKWh(capacity * 1e3, true, true, 1); + const total = this.fmtWh(capacity * 1e3, POWER_UNIT.KW, true, 1); const name = multipleBatteries ? "↳ " : ""; const formattedSoc = multipleBatteries ? ` (${this.fmtSoc(soc)})` : ""; const formattedEnergy = this.$t("batterySettings.capacity", { diff --git a/assets/js/components/ChargingPlan.vue b/assets/js/components/ChargingPlan.vue index cf7400836..94cc8c29a 100644 --- a/assets/js/components/ChargingPlan.vue +++ b/assets/js/components/ChargingPlan.vue @@ -196,7 +196,7 @@ export default { return fmtEnergy( this.planEnergy, optionStep(this.capacity || 100), - this.fmtKWh, + this.fmtWh, this.$t("main.targetEnergy.noLimit") ); }, diff --git a/assets/js/components/ChargingPlanPreview.vue b/assets/js/components/ChargingPlanPreview.vue index bc22005f2..dcddc3824 100644 --- a/assets/js/components/ChargingPlanPreview.vue +++ b/assets/js/components/ChargingPlanPreview.vue @@ -69,7 +69,7 @@ export default { }, fmtPower() { if (this.duration > 0 && this.power > 0) { - return `@ ${this.fmtKw(this.power)}`; + return `@ ${this.fmtW(this.power)}`; } return null; }, diff --git a/assets/js/components/ChargingPlanSettingsEntry.vue b/assets/js/components/ChargingPlanSettingsEntry.vue index 50bfd04de..ff37f27ec 100644 --- a/assets/js/components/ChargingPlanSettingsEntry.vue +++ b/assets/js/components/ChargingPlanSettingsEntry.vue @@ -175,7 +175,7 @@ export default { 0, this.capacity || 100, this.socPerKwh, - this.fmtKWh, + this.fmtWh, this.fmtPercentage, "-" ); diff --git a/assets/js/components/ChargingPlanWarnings.vue b/assets/js/components/ChargingPlanWarnings.vue index 619bf863e..d44914342 100644 --- a/assets/js/components/ChargingPlanWarnings.vue +++ b/assets/js/components/ChargingPlanWarnings.vue @@ -100,13 +100,13 @@ export default { if (this.socBasedPlanning) { return this.fmtSoc(this.effectiveLimitSoc); } - return this.fmtKWh(this.limitEnergy * 1e3); + return this.fmtWh(this.limitEnergy * 1e3); }, goalFmt: function () { if (this.socBasedPlanning) { return this.fmtSoc(this.effectivePlanSoc); } - return this.fmtKWh(this.planEnergy * 1e3); + return this.fmtWh(this.planEnergy * 1e3); }, costLimitExists: function () { return this.smartCostLimit !== 0; diff --git a/assets/js/components/ChargingSessionModal.vue b/assets/js/components/ChargingSessionModal.vue index a712cb765..213c5d363 100644 --- a/assets/js/components/ChargingSessionModal.vue +++ b/assets/js/components/ChargingSessionModal.vue @@ -68,10 +68,17 @@ {{ $t("sessions.energy") }} - {{ fmtKWh(chargedEnergy, chargedEnergy >= 1e3) }} + {{ + fmtWh( + chargedEnergy, + chargedEnergy >= 1e3 + ? POWER_UNIT.KW + : POWER_UNIT.AUTO + ) + }}
{{ fmtDurationNs(session.chargeDuration) }} - (~{{ fmtKw(avgPower) }}) + (~{{ fmtW(avgPower) }})
@@ -81,7 +88,7 @@ {{ fmtPercentage(session.solarPercentage, 1) }} - ({{ fmtKWh(solarEnergy, solarEnergy >= 1e3) }}) + ({{ fmtWh(solarEnergy, POWER_UNIT.AUTO) }}) @@ -115,8 +122,8 @@ {{ $t("session.meter") }} - {{ fmtKWh(session.meterStart * 1e3) }}
- {{ fmtKWh(session.meterStop * 1e3) }} + {{ fmtWh(session.meterStart * 1e3) }}
+ {{ fmtWh(session.meterStop * 1e3) }} diff --git a/assets/js/components/Config/DeviceTags.vue b/assets/js/components/Config/DeviceTags.vue index 54fb4aa96..1cc3a06af 100644 --- a/assets/js/components/Config/DeviceTags.vue +++ b/assets/js/components/Config/DeviceTags.vue @@ -48,11 +48,11 @@ export default { } switch (name) { case "power": - return this.fmtKw(value); + return this.fmtW(value); case "energy": case "capacity": case "chargedEnergy": - return this.fmtKWh(value * 1e3); + return this.fmtWh(value * 1e3); case "soc": case "socLimit": return this.fmtPercentage(value, 1); @@ -66,7 +66,7 @@ export default { case "phaseVoltages": return value.map((v) => this.fmtNumber(v, 0)).join(" ") + " V"; case "phasePowers": - return value.map((v) => this.fmtKw(v)).join(", "); + return value.map((v) => this.fmtW(v)).join(", "); case "chargeStatus": return this.$t(`config.deviceValue.chargeStatus${value}`); case "gridPrice": @@ -75,7 +75,7 @@ export default { case "co2": return this.fmtCo2Short(value); case "powerRange": - return `${this.fmtKw(value[0])} / ${this.fmtKw(value[1])}`; + return `${this.fmtW(value[0])} / ${this.fmtW(value[1])}`; case "currentRange": return `${this.fmtNumber(value[0], 1)} A / ${this.fmtNumber(value[1], 1)} A`; case "controllable": diff --git a/assets/js/components/Energyflow/Energyflow.vue b/assets/js/components/Energyflow/Energyflow.vue index c2bcc2034..e5620d689 100644 --- a/assets/js/components/Energyflow/Energyflow.vue +++ b/assets/js/components/Energyflow/Energyflow.vue @@ -18,7 +18,7 @@ :pvProduction="pvProduction" :homePower="homePower" :batterySoc="batterySoc" - :powerInKw="powerInKw" + :powerUnit="powerUnit" :vehicleIcons="vehicleIcons" /> @@ -79,7 +79,7 @@ icon="sun" :power="pvProduction" :powerTooltip="pvTooltip" - :powerInKw="powerInKw" + :powerUnit="powerUnit" data-testid="energyflow-entry-production" /> = 1000; + powerUnit: function () { + const watt = Math.max(this.gridImport, this.selfPv, this.selfBattery, this.pvExport); + if (watt >= 1_000_000) { + return POWER_UNIT.MW; + } else if (watt >= 1000) { + return POWER_UNIT.KW; + } else { + return POWER_UNIT.W; + } }, inPower: function () { return this.gridImport + this.pvProduction + this.batteryDischarge; @@ -308,7 +315,7 @@ export default { if (!Array.isArray(this.pv) || this.pv.length <= 1) { return; } - return this.pv.map(({ power }) => this.fmtKw(power, this.powerInKw)); + return this.pv.map(({ power }) => this.fmtW(power, this.powerUnit)); }, batteryFmt() { return (soc) => this.fmtPercentage(soc, 0); @@ -386,7 +393,7 @@ export default { return this.fmtPricePerKWh(value, this.currency, true); }, kw: function (watt) { - return this.fmtKw(watt, this.powerInKw); + return this.fmtW(watt, this.powerUnit); }, toggleDetails: function () { this.updateHeight(); diff --git a/assets/js/components/Energyflow/EnergyflowEntry.vue b/assets/js/components/Energyflow/EnergyflowEntry.vue index 81d042f3e..4519821d8 100644 --- a/assets/js/components/Energyflow/EnergyflowEntry.vue +++ b/assets/js/components/Energyflow/EnergyflowEntry.vue @@ -52,7 +52,7 @@ export default { vehicleIcons: { type: Array }, power: { type: Number }, powerTooltip: { type: Array }, - powerInKw: { type: Boolean }, + powerUnit: { type: String }, soc: { type: Number }, details: { type: Number }, detailsFmt: { type: Function }, @@ -98,7 +98,7 @@ export default { }, methods: { kw: function (watt) { - return this.fmtKw(watt, this.powerInKw); + return this.fmtW(watt, this.powerUnit); }, updatePowerTooltip() { this.powerTooltipInstance = this.updateTooltip( diff --git a/assets/js/components/Energyflow/Visualization.vue b/assets/js/components/Energyflow/Visualization.vue index d8f644e72..984e8ad2d 100644 --- a/assets/js/components/Energyflow/Visualization.vue +++ b/assets/js/components/Energyflow/Visualization.vue @@ -61,7 +61,7 @@ />
- {{ fmtKw(0, false, true) }} + {{ fmtW(0, POWER_UNIT.AUTO, true) }}
@@ -89,7 +89,7 @@