From b1b1e4d06f04bebbae572c6166269ed75cd335e6 Mon Sep 17 00:00:00 2001 From: Vincent Wolsink Date: Mon, 23 Sep 2024 20:39:34 +0200 Subject: [PATCH] Disabled pcu_comm_check by default. Add option to enable. --- custom_components/enphase_envoy/__init__.py | 11 ++++++- .../enphase_envoy/config_flow.py | 29 +++++++++++-------- .../enphase_envoy/envoy_endpoints.py | 2 +- .../enphase_envoy/envoy_reader.py | 2 +- .../enphase_envoy/envoy_test_data.py | 2 +- custom_components/enphase_envoy/strings.json | 1 + .../enphase_envoy/translations/en.json | 1 + .../enphase_envoy/translations/nl.json | 1 + 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/custom_components/enphase_envoy/__init__.py b/custom_components/enphase_envoy/__init__.py index 3fb7b3d..7ebd1a2 100644 --- a/custom_components/enphase_envoy/__init__.py +++ b/custom_components/enphase_envoy/__init__.py @@ -8,6 +8,7 @@ import logging import time from typing import Optional +import copy import async_timeout from .envoy_reader import EnvoyReader, StreamData @@ -70,6 +71,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Setup persistent storage, to save tokens between home assistant restarts store = Store(hass, STORAGE_VERSION, ".".join([STORAGE_KEY, entry.entry_id])) + disabled_endpoints = options.get("disabled_endpoints", []) + if ( + not options.get("enable_pcu_comm_check") + and "endpoint_pcu_comm_check" not in disabled_endpoints + ): + disabled_endpoints = copy.copy(disabled_endpoints) + disabled_endpoints.append("endpoint_pcu_comm_check") + envoy_reader = EnvoyReader( config[CONF_HOST], enlighten_user=config[CONF_USERNAME], @@ -78,7 +87,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: enlighten_serial_num=config[CONF_SERIAL], store=store, disable_negative_production=options.get("disable_negative_production", False), - disabled_endpoints=options.get("disabled_endpoints", []), + disabled_endpoints=disabled_endpoints, ) 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 fc13598..e8340e4 100644 --- a/custom_components/enphase_envoy/config_flow.py +++ b/custom_components/enphase_envoy/config_flow.py @@ -241,6 +241,17 @@ async def async_step_user(self, user_input=None): if user_input is not None: return self.async_create_entry(title="", data=user_input) + optional_endpoints = { + f"endpoint_{key}": key + for key, endpoint in ENVOY_ENDPOINTS.items() + if endpoint["optional"] + } + disabled_endpoints = [ + ep + for ep in self.config_entry.options.get("disabled_endpoints") + if ep in optional_endpoints.keys() + ] + schema = { vol.Optional( "time_between_update", @@ -274,20 +285,14 @@ async def async_step_user(self, user_input=None): ENABLE_ADDITIONAL_METRICS, default=self.config_entry.options.get(ENABLE_ADDITIONAL_METRICS, False), ): bool, + vol.Optional( + "enable_pcu_comm_check", + default=self.config_entry.options.get("enable_pcu_comm_check", False), + ): bool, vol.Optional( "disabled_endpoints", - description={ - "suggested_value": self.config_entry.options.get( - "disabled_endpoints" - ) - }, - ): cv.multi_select( - { - f"endpoint_{key}": key - for key, endpoint in ENVOY_ENDPOINTS.items() - if endpoint["optional"] - } - ), + description={"suggested_value": disabled_endpoints}, + ): cv.multi_select(optional_endpoints), } return self.async_show_form(step_id="user", data_schema=vol.Schema(schema)) diff --git a/custom_components/enphase_envoy/envoy_endpoints.py b/custom_components/enphase_envoy/envoy_endpoints.py index 11469ad..b947e57 100644 --- a/custom_components/enphase_envoy/envoy_endpoints.py +++ b/custom_components/enphase_envoy/envoy_endpoints.py @@ -75,7 +75,7 @@ "installer_required": True, "optional": False, }, - "pcu_comm_status": { + "pcu_comm_check": { "url": "https://{}/installer/pcu_comm_check", "cache": 90, "installer_required": True, diff --git a/custom_components/enphase_envoy/envoy_reader.py b/custom_components/enphase_envoy/envoy_reader.py index 39b81c6..01f4994 100644 --- a/custom_components/enphase_envoy/envoy_reader.py +++ b/custom_components/enphase_envoy/envoy_reader.py @@ -403,7 +403,7 @@ def grid_status(self): installer="endpoint_devstatus.pcu[?(@.devType==1)]", ) - pcu_availability_value = "endpoint_pcu_comm_status" + pcu_availability_value = "endpoint_pcu_comm_check" @envoy_property def inverters_production(self): diff --git a/custom_components/enphase_envoy/envoy_test_data.py b/custom_components/enphase_envoy/envoy_test_data.py index b48709f..07d3218 100644 --- a/custom_components/enphase_envoy/envoy_test_data.py +++ b/custom_components/enphase_envoy/envoy_test_data.py @@ -76,7 +76,7 @@ "installer_required": True, "optional": False, }, - "pcu_comm_status": { + "pcu_comm_check": { "url": TEST_DATA + "endpoint_pcu_comm_check.json", "cache": 90, "installer_required": True, diff --git a/custom_components/enphase_envoy/strings.json b/custom_components/enphase_envoy/strings.json index ec26bf3..9d7d905 100644 --- a/custom_components/enphase_envoy/strings.json +++ b/custom_components/enphase_envoy/strings.json @@ -35,6 +35,7 @@ "getdata_timeout": "Timeout value for fetching data from envoy [s]", "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)", "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 1fd2c8c..996846b 100644 --- a/custom_components/enphase_envoy/translations/en.json +++ b/custom_components/enphase_envoy/translations/en.json @@ -34,6 +34,7 @@ "getdata_timeout": "Timeout value for fetching data from envoy [s]", "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)", "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 3b23ebd..75a19c5 100644 --- a/custom_components/enphase_envoy/translations/nl.json +++ b/custom_components/enphase_envoy/translations/nl.json @@ -34,6 +34,7 @@ "getdata_timeout": "Maximum tijd voor het ophalen van data vanaf envoy [s]", "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)", "disabled_endpoints": "[Geavanceerd] Uitgeschakelde Envoy endpoints" }, "data_description": {