Skip to content

Commit

Permalink
feat(wip): Trigger reauth after data update token expired
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow committed Mar 6, 2023
1 parent 78768a0 commit f7e97dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion custom_components/aigues_barcelona/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ async def async_step_reauth(self, entry) -> FlowResult:
"""Request OAuth Token again when expired."""
# get previous entity content back to flow
self.entry = entry
self.stored_input = entry.data
if hasattr(entry, "data"):
self.stored_input = entry.data
else:
# FIXME: for DataUpdateCoordinator, entry is not valid,
# as it contains only sensor data. Missing entry_id.
# Reauth when restarting works.
self.stored_input = entry
return await self.async_step_reauth_confirm(None)

async def async_step_reauth_confirm(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/aigues_barcelona/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ async def _async_update_data(self):
consumptions = await self.hass.async_add_executor_job(
self._api.consumptions, LAST_WEEK, TOMORROW
)
except ConfigEntryAuthFailed:
except ConfigEntryAuthFailed as exp:
_LOGGER.error("Token has expired, cannot check consumptions.")
return False
raise ConfigEntryAuthFailed from exp
except Exception as msg:
_LOGGER.error("error while getting data: %s", msg)

Expand Down

0 comments on commit f7e97dc

Please sign in to comment.