From eef2c6c234d5d93c9ce29657ba9cc16969c6a880 Mon Sep 17 00:00:00 2001 From: Vincent Wolsink Date: Thu, 3 Oct 2024 22:22:40 +0200 Subject: [PATCH] Add configuration option to correct lifetime production value --- custom_components/enphase_envoy/__init__.py | 1 + .../enphase_envoy/config_flow.py | 6 ++++++ .../enphase_envoy/envoy_reader.py | 21 +++++++++++++++++-- custom_components/enphase_envoy/strings.json | 1 + .../enphase_envoy/translations/en.json | 1 + .../enphase_envoy/translations/nl.json | 1 + 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/custom_components/enphase_envoy/__init__.py b/custom_components/enphase_envoy/__init__.py index 7ebd1a2..c5dd143 100644 --- a/custom_components/enphase_envoy/__init__.py +++ b/custom_components/enphase_envoy/__init__.py @@ -88,6 +88,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: store=store, disable_negative_production=options.get("disable_negative_production", False), disabled_endpoints=disabled_endpoints, + lifetime_production_correction=options.get("lifetime_production_correction", 0), ) await envoy_reader._sync_store(load=True) diff --git a/custom_components/enphase_envoy/config_flow.py b/custom_components/enphase_envoy/config_flow.py index 72da669..f1c3728 100644 --- a/custom_components/enphase_envoy/config_flow.py +++ b/custom_components/enphase_envoy/config_flow.py @@ -289,6 +289,12 @@ async def async_step_user(self, user_input=None): "enable_pcu_comm_check", default=self.config_entry.options.get("enable_pcu_comm_check", False), ): bool, + vol.Optional( + "lifetime_production_correction", + default=self.config_entry.options.get( + "lifetime_production_correction", 0 + ), + ): vol.All(vol.Coerce(int)), vol.Optional( "disabled_endpoints", description={"suggested_value": disabled_endpoints}, diff --git a/custom_components/enphase_envoy/envoy_reader.py b/custom_components/enphase_envoy/envoy_reader.py index 250f4fb..5403b64 100644 --- a/custom_components/enphase_envoy/envoy_reader.py +++ b/custom_components/enphase_envoy/envoy_reader.py @@ -378,11 +378,18 @@ def envoy_info(self): owner="endpoint_production_v1.wattHoursToday", installer="endpoint_pdm_energy.production.pcu.wattHoursToday", ) - lifetime_production_value = path_by_token( + + _lifetime_production_path = path_by_token( owner="endpoint_production_v1.wattHoursLifetime", installer="endpoint_pdm_energy.production.pcu.wattHoursLifetime", ) + @envoy_property(required_endpoint="endpoint_production_v1") + def lifetime_production(self): + lifetime_production = self._resolve_path(self._lifetime_production_path) + if lifetime_production is not None: + return lifetime_production + self.reader.lifetime_production_correction + @envoy_property(required_endpoint="endpoint_production_power") def production_power(self): """Return production power status reported by Envoy""" @@ -542,10 +549,18 @@ def __new__(cls, *a, **kw): _production = "endpoint_production_json.production[?(@.type=='inverters')]" production_value = _production + ".wNow" - lifetime_production_value = path_by_token( + + _lifetime_production_path = path_by_token( owner=_production + ".whLifetime", installer="endpoint_pdm_energy.production.pcu.wattHoursLifetime", ) + + @envoy_property(required_endpoint="endpoint_production_json") + def lifetime_production(self): + lifetime_production = self._resolve_path(self._lifetime_production_path) + if lifetime_production is not None: + return lifetime_production + self.reader.lifetime_production_correction + daily_production_value = "endpoint_pdm_energy.production.pcu.wattHoursToday" _production_ct = ( @@ -632,6 +647,7 @@ def __init__( store=None, disable_negative_production=False, disabled_endpoints=[], + lifetime_production_correction=0, ): """Init the EnvoyReader.""" self.host = host.lower() @@ -655,6 +671,7 @@ def __init__( self.data: EnvoyData = EnvoyStandard(self) self.required_endpoints = set() # in case we would need it.. self.disabled_endpoints = disabled_endpoints + self.lifetime_production_correction = lifetime_production_correction self.uri_registry = {} for key, endpoint in ENVOY_ENDPOINTS.items(): diff --git a/custom_components/enphase_envoy/strings.json b/custom_components/enphase_envoy/strings.json index 9d7d905..cff469b 100644 --- a/custom_components/enphase_envoy/strings.json +++ b/custom_components/enphase_envoy/strings.json @@ -36,6 +36,7 @@ "enable_additional_metrics": "[Metered only] Enable additional metrics like total amps, frequency, apparent and reactive power and power factor.", "disable_installer_account_use": "Do not collect data that requires installer or DIY enphase account", "enable_pcu_comm_check": "Enable powerline communication level sensors (slow)", + "lifetime_production_correction": "Correction of lifetime production value (Wh)", "disabled_endpoints": "[Advanced] Disabled Envoy endpoints" }, "data_description": { diff --git a/custom_components/enphase_envoy/translations/en.json b/custom_components/enphase_envoy/translations/en.json index 996846b..f42fc8b 100644 --- a/custom_components/enphase_envoy/translations/en.json +++ b/custom_components/enphase_envoy/translations/en.json @@ -35,6 +35,7 @@ "enable_additional_metrics": "[Envoy-S Metered] Enable additional metrics like total amps, frequency, apparent and reactive power and power factor.", "disable_installer_account_use": "Do not collect data that requires installer or DIY enphase account", "enable_pcu_comm_check": "Enable powerline communication level sensors (slow)", + "lifetime_production_correction": "Correction of lifetime production value (Wh)", "disabled_endpoints": "[Advanced] Disabled Envoy endpoints" }, "data_description": { diff --git a/custom_components/enphase_envoy/translations/nl.json b/custom_components/enphase_envoy/translations/nl.json index 75a19c5..6f940d2 100644 --- a/custom_components/enphase_envoy/translations/nl.json +++ b/custom_components/enphase_envoy/translations/nl.json @@ -35,6 +35,7 @@ "enable_additional_metrics": "[Envoy-S Metered] Extra metrics inschakelen, zoals total amps, frequency, apparent en reactive power en power factor.", "disable_installer_account_use": "Haal geen data op die een installateur of DHZ enphase account vereisen", "enable_pcu_comm_check": "Powerline communication level sensors inschakelen (langzaam)", + "lifetime_production_correction": "Correctie van lifetime production waarde (Wh)", "disabled_endpoints": "[Geavanceerd] Uitgeschakelde Envoy endpoints" }, "data_description": {