Skip to content

Commit

Permalink
Merge pull request #161 from vincentwolsink/bugfix_thursday
Browse files Browse the repository at this point in the history
Several bugfixes incl production/consumption entities being unavailable
  • Loading branch information
vincentwolsink authored Sep 26, 2024
2 parents 9a72d75 + 53ae772 commit 47b5e37
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/enphase_envoy/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def async_step_user(self, user_input=None):
}
disabled_endpoints = [
ep
for ep in self.config_entry.options.get("disabled_endpoints")
for ep in self.config_entry.options.get("disabled_endpoints", [])
if ep in optional_endpoints.keys()
]

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 @@ -34,7 +34,7 @@
"production_power": {
"url": "https://{}/ivp/mod/603980032/mode/power",
"cache": 300,
"installer_required": False,
"installer_required": True,
"optional": True,
},
"pdm_energy": {
Expand Down
12 changes: 5 additions & 7 deletions custom_components/enphase_envoy/envoy_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ def __init__(
self.enlighten_user = enlighten_user
self.enlighten_pass = enlighten_pass
self.commissioned = commissioned
self.envoy_token_fetch_attempted = False
self.enlighten_serial_num = enlighten_serial_num
self.token_refresh_buffer_seconds = token_refresh_buffer_seconds
self.token_type = None
Expand Down Expand Up @@ -887,7 +886,6 @@ async def _fetch_envoy_token_json(self):

async def _get_enphase_token(self):
self._token = await self._fetch_envoy_token_json()
self.envoy_token_fetch_attempted = True

_LOGGER.debug("Envoy Token")
if self._is_enphase_token_expired(self._token):
Expand Down Expand Up @@ -947,6 +945,7 @@ def _is_enphase_token_expired(self, token):

if decode.get("enphaseUser", None) != None:
self.token_type = decode["enphaseUser"] # owner or installer
_LOGGER.debug("TOKEN TYPE: %s", self.token_type)

exp_epoch = decode["exp"]
# allow a buffer so we can try and grab it sooner
Expand Down Expand Up @@ -1073,9 +1072,8 @@ async def update_endpoints(self, endpoints=None):
_LOGGER.error(f"No settings found for uri {endpoint}")
continue

if endpoint_settings.get("installer_required", False) and (
(self.token_type != "installer" and self.envoy_token_fetch_attempted)
or self.disable_installer_account_use
if endpoint_settings["installer_required"] and (
self.token_type != "installer" or self.disable_installer_account_use
):
_LOGGER.info(
"Skipping installer endpoint %s (got token %s and "
Expand Down Expand Up @@ -1103,8 +1101,8 @@ async def update_endpoints(self, endpoints=None):
time.time() - endpoint_settings["last_fetch"],
)

if self.data:
self.data.set_endpoint_data(endpoint, getattr(self, endpoint))
if self.data:
self.data.set_endpoint_data(endpoint, getattr(self, endpoint))

async def get_data(self, get_inverters=True):
"""
Expand Down

0 comments on commit 47b5e37

Please sign in to comment.