Skip to content

Commit

Permalink
FIX: First endpoint data not stored. FIX: Tries to update first insta…
Browse files Browse the repository at this point in the history
…ller endpoint anyway when using owner token
  • Loading branch information
vincentwolsink committed Sep 26, 2024
1 parent bbf9a30 commit 53ae772
Showing 1 changed file with 5 additions and 7 deletions.
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 53ae772

Please sign in to comment.