From ad7d5ed5b0773d15f9e2dc654ef823227ebaab40 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Mon, 19 Feb 2024 18:52:55 +0100 Subject: [PATCH 1/3] Battery settings: improve buffer start --- assets/js/components/BatterySettingsModal.vue | 111 ++++++++---------- core/site_api.go | 2 +- i18n/de.toml | 5 +- i18n/en.toml | 5 +- 4 files changed, 52 insertions(+), 71 deletions(-) diff --git a/assets/js/components/BatterySettingsModal.vue b/assets/js/components/BatterySettingsModal.vue index ccfd5b66b..c4dd172da 100644 --- a/assets/js/components/BatterySettingsModal.vue +++ b/assets/js/components/BatterySettingsModal.vue @@ -162,31 +162,19 @@ - {{ - $t( - `batterySettings.bufferStart.${bufferStartOption}` - ) - }} + {{ bufferStartOption.name }} @@ -311,6 +299,25 @@ export default { if (!this.selectedBufferStartSoc) return 0; return 100 - this.selectedBufferStartSoc; }, + bufferStartOptions() { + const options = []; + for (let i = 100; i >= this.bufferSoc; i -= 5) { + options.push({ + value: i, + name: this.$t(`batterySettings.bufferStart.${i === 100 ? "full" : "above"}`, { + soc: this.fmtSoc(i), + }), + }); + } + options.push({ + value: 0, + name: this.$t("batterySettings.bufferStart.never"), + }); + return options; + }, + bufferStartOption() { + return this.bufferStartOptions.find((option) => this.bufferStartSoc >= option.value); + }, topHeight() { return 100 - (this.bufferSoc || 100); }, @@ -320,13 +327,6 @@ export default { bottomHeight() { return this.prioritySoc; }, - bufferStartOption() { - if (!this.selectedBufferStartSoc) return "never"; - if (this.selectedBufferStartSoc >= this.bufferStartOptionToSoc("full")) return "full"; - if (this.selectedBufferStartSoc >= this.bufferStartOptionToSoc("medium")) - return "medium"; - return "low"; - }, batteryDetails() { if (!Array.isArray(this.battery)) { return; @@ -382,52 +382,35 @@ export default { this.isModalVisible = false; }, changeBufferStart($event) { - this.setBufferStart($event.target.value); + this.setBufferStartSoc(parseInt($event.target.value, 10)); }, changePrioritySoc($event) { - const value = parseInt($event.target.value, 10); - if (value > this.bufferSoc) { - const startOption = this.bufferStartOption; - this.saveBufferSoc(value); - this.setBufferStart(startOption); + const soc = parseInt($event.target.value, 10); + if (soc > this.bufferSoc) { + this.saveBufferSoc(soc); + if (soc > this.bufferStartSoc && this.bufferStartSoc > 0) { + this.setBufferStartSoc(soc); + } } else { - this.savePrioritySoc(value); - } - }, - bufferStartOptionToSoc(option) { - const bufferSoc = this.selectedBufferSoc; - const bufferHeight = 100 - bufferSoc; - switch (option) { - case "low": - return bufferSoc + bufferHeight * 0.2; - case "medium": - return bufferSoc + bufferHeight * 0.5; - case "full": - return bufferSoc + bufferHeight * 0.8; - case "never": - return 0; + this.savePrioritySoc(soc); } }, toggleBufferStart() { - const next = { - never: "low", - low: "medium", - medium: "full", - full: "never", - }; - const nextOption = next[this.bufferStartOption]; - if (nextOption) { - this.setBufferStart(nextOption); + const options = this.bufferStartOptions.map((option) => option.value); + const index = options.findIndex((value) => this.bufferStartSoc >= value); + const nextIndex = index === 0 ? options.length - 1 : index - 1; + this.setBufferStartSoc(options[nextIndex]); + }, + async setBufferStartSoc(soc) { + this.selectedBufferStartSoc = soc; + await this.saveBufferStartSoc(this.selectedBufferStartSoc); + }, + async changeBufferSoc($event) { + const soc = parseInt($event.target.value, 10); + if (soc > this.bufferStartSoc && this.bufferStartSoc > 0) { + await this.setBufferStartSoc(soc); } - }, - setBufferStart(option) { - this.selectedBufferStartSoc = this.bufferStartOptionToSoc(option); - this.saveBufferStartSoc(this.selectedBufferStartSoc); - }, - changeBufferSoc($event) { - const startOption = this.bufferStartOption; - this.saveBufferSoc(parseInt($event.target.value, 10)); - this.setBufferStart(startOption); + await this.saveBufferSoc(soc); }, async savePrioritySoc(soc) { this.selectedPrioritySoc = soc; diff --git a/core/site_api.go b/core/site_api.go index b098e1e1e..8f1d7b955 100644 --- a/core/site_api.go +++ b/core/site_api.go @@ -218,7 +218,7 @@ func (site *Site) SetBufferStartSoc(soc float64) error { return ErrBatteryNotConfigured } - if soc != 0 && soc <= site.bufferSoc { + if soc != 0 && soc < site.bufferSoc { return errors.New("buffer start soc must be larger than buffer soc") } diff --git a/i18n/de.toml b/i18n/de.toml index b5e5f69f7..a900242b0 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -16,9 +16,8 @@ legendTopSubline = "ohne Unterbrechungen" modalTitle = "Batterieeinstellungen" [batterySettings.bufferStart] -full = "wenn fast voll" -low = "wenn etwas voll" -medium = "wenn halbvoll" +above = "wenn über {soc}" +full = "wenn auf {soc}" never = "nur mit genug PV-Überschuss" [config] diff --git a/i18n/en.toml b/i18n/en.toml index f48addfe7..96008f8f2 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -16,9 +16,8 @@ legendTopSubline = "without interruptions" modalTitle = "Battery Settings" [batterySettings.bufferStart] -full = "when nearly full" -low = "when somewhat full" -medium = "when half full" +above = "when above {soc}" +full = "when at {soc}" never = "only with enough surplus" [config] From bc867467b4717e7400afe6704ed8e8a6ba713028 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Mon, 19 Feb 2024 20:25:45 +0100 Subject: [PATCH 2/3] initial priority soc fix --- assets/js/components/BatterySettingsModal.vue | 2 +- assets/js/components/TopNavigation.vue | 21 ++++++++++++++++--- assets/js/utils/native.js | 10 +++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 assets/js/utils/native.js diff --git a/assets/js/components/BatterySettingsModal.vue b/assets/js/components/BatterySettingsModal.vue index c4dd172da..92a71a2d0 100644 --- a/assets/js/components/BatterySettingsModal.vue +++ b/assets/js/components/BatterySettingsModal.vue @@ -386,7 +386,7 @@ export default { }, changePrioritySoc($event) { const soc = parseInt($event.target.value, 10); - if (soc > this.bufferSoc) { + if (soc > (this.bufferSoc || 100)) { this.saveBufferSoc(soc); if (soc > this.bufferStartSoc && this.bufferStartSoc > 0) { this.setBufferStartSoc(soc); diff --git a/assets/js/components/TopNavigation.vue b/assets/js/components/TopNavigation.vue index 9ba99d7be..de69111af 100644 --- a/assets/js/components/TopNavigation.vue +++ b/assets/js/components/TopNavigation.vue @@ -28,7 +28,12 @@
  • -
  • -
  • -
  • diff --git a/assets/js/utils/native.js b/assets/js/utils/native.js new file mode 100644 index 000000000..a11ff9d4f --- /dev/null +++ b/assets/js/utils/native.js @@ -0,0 +1,10 @@ +export function isApp() { + return navigator.userAgent.includes("evcc-app"); +} + +export function appDetection() { + if (isApp()) { + const $html = document.querySelector("html"); + $html.classList.add("app"); + } +} From 9fbd6eb1e381ff67eb3f9217b974f5601a7dc565 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Tue, 20 Feb 2024 20:53:36 +0100 Subject: [PATCH 3/3] clean --- assets/js/utils/native.js | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 assets/js/utils/native.js diff --git a/assets/js/utils/native.js b/assets/js/utils/native.js deleted file mode 100644 index a11ff9d4f..000000000 --- a/assets/js/utils/native.js +++ /dev/null @@ -1,10 +0,0 @@ -export function isApp() { - return navigator.userAgent.includes("evcc-app"); -} - -export function appDetection() { - if (isApp()) { - const $html = document.querySelector("html"); - $html.classList.add("app"); - } -}