From 64fe540a07f0031cef78aa20f2b37b5be017d68f Mon Sep 17 00:00:00 2001 From: philipostli <55027973+philipostli@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:04:12 +0100 Subject: [PATCH] Add setting for showing 1/3 phases - Watty --- app.json | 13 +++++++++++++ drivers/watty/device.ts | 15 +++++++++++++++ drivers/watty/driver.compose.json | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index 11b0c77..0a4b574 100644 --- a/app.json +++ b/app.json @@ -1686,6 +1686,19 @@ ] } ] + }, + { + "id": "phase_mode", + "type": "checkbox", + "label": { + "en": "Show 3 phases", + "no": "Vis 3 faser" + }, + "hint": { + "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", + "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + }, + "value": true } ], "id": "watty" diff --git a/drivers/watty/device.ts b/drivers/watty/device.ts index a1ea5de..99d749e 100644 --- a/drivers/watty/device.ts +++ b/drivers/watty/device.ts @@ -15,6 +15,7 @@ class WattyDevice extends Device { #currency?: string; #cachedNordPoolPrice: { hour: number; price: number } | null = null; #area?: string; + #phaseMode!: boolean; #prevPowerProduction?: number; #prevUpdate?: moment.Moment; #prevPower?: number; @@ -40,6 +41,7 @@ class WattyDevice extends Device { this.#api = new TibberApi(this.log, this.homey.settings, id, token); this.#deviceId = id; this.#throttle = this.getSetting('pulse_throttle') || 30; + this.#phaseMode = this.getSetting('phase_mode') || true; this.#powerChangedTrigger = this.homey.flow.getDeviceTriggerCard( 'watty_power_changed', @@ -106,6 +108,19 @@ class WattyDevice extends Device { this.#area = newSettings.pulse_area; this.#cachedNordPoolPrice = null; } + if (changedKeys.includes('phase_mode')) { + this.log('Updated 3-phase mode value: ', Boolean(newSettings.phase_mode)); + this.#phaseMode = Boolean(newSettings.phase_mode); + if (this.#phaseMode) { + this.log('3-phase mode enabled'); + await this.addCapability('measure_current.L2'); + await this.addCapability('measure_current.L3'); + } else { + this.log('3-phase mode disabled'); + await this.removeCapability('measure_current.L2'); + await this.removeCapability('measure_current.L3'); + } + } } async #subscribeToLive() { diff --git a/drivers/watty/driver.compose.json b/drivers/watty/driver.compose.json index a1d74ea..e41c660 100644 --- a/drivers/watty/driver.compose.json +++ b/drivers/watty/driver.compose.json @@ -231,7 +231,20 @@ } ] } - ] + ] + }, + { + "id": "phase_mode", + "type": "checkbox", + "label": { + "en": "Show 3 phases", + "no": "Vis 3 faser" + }, + "hint": { + "en": "Enables 3 phase mode\nDefault: true\n\nWill show current on separate phases 1, 2 and 3/nTurn off to show only one phase", + "no": "Aktiverer 3-fase modus\nDefault: true\n\nViser strøm på fase 1, 2 og 3 separat/nSlå av for å vise kun én fase." + }, + "value": true } ] }