Skip to content

Commit

Permalink
Merge pull request #159 from vincentwolsink/disable_pcu_comm_check
Browse files Browse the repository at this point in the history
Disabled pcu_comm_check by default. Add option to enable.
  • Loading branch information
vincentwolsink authored Sep 23, 2024
2 parents 25112bc + b1b1e4d commit 7191b34
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
11 changes: 10 additions & 1 deletion custom_components/enphase_envoy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import time
from typing import Optional
import copy

import async_timeout
from .envoy_reader import EnvoyReader, StreamData
Expand Down Expand Up @@ -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],
Expand All @@ -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)

Expand Down
29 changes: 17 additions & 12 deletions custom_components/enphase_envoy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion custom_components/enphase_envoy/envoy_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"installer_required": True,
"optional": False,
},
"pcu_comm_status": {
"pcu_comm_check": {
"url": "https://{}/installer/pcu_comm_check",
"cache": 3600,
"installer_required": True,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/enphase_envoy/envoy_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/enphase_envoy/envoy_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions custom_components/enphase_envoy/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/enphase_envoy/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions custom_components/enphase_envoy/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 7191b34

Please sign in to comment.