Bump aiotractive, properly handle auth errors when reading events (#76715)
* Bump aiotractive, start handling authorzation errors when reading events * Bump aiotractive, start handling authorzation errors when reading events * Properly handle unauthorized errors * Update homeassistant/components/tractive/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> * Use await when unsibscribing after auth error * Update homeassistant/components/tractive/__init__.py Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
18dd605a74
commit
6c024c8875
4 changed files with 19 additions and 5 deletions
|
@ -83,7 +83,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
await client.close()
|
||||
raise ConfigEntryNotReady from error
|
||||
|
||||
tractive = TractiveClient(hass, client, creds["user_id"])
|
||||
tractive = TractiveClient(hass, client, creds["user_id"], entry)
|
||||
tractive.subscribe()
|
||||
|
||||
try:
|
||||
|
@ -148,7 +148,11 @@ class TractiveClient:
|
|||
"""A Tractive client."""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, client: aiotractive.Tractive, user_id: str
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
client: aiotractive.Tractive,
|
||||
user_id: str,
|
||||
config_entry: ConfigEntry,
|
||||
) -> None:
|
||||
"""Initialize the client."""
|
||||
self._hass = hass
|
||||
|
@ -157,6 +161,7 @@ class TractiveClient:
|
|||
self._last_hw_time = 0
|
||||
self._last_pos_time = 0
|
||||
self._listen_task: asyncio.Task | None = None
|
||||
self._config_entry = config_entry
|
||||
|
||||
@property
|
||||
def user_id(self) -> str:
|
||||
|
@ -210,6 +215,15 @@ class TractiveClient:
|
|||
):
|
||||
self._last_pos_time = event["position"]["time"]
|
||||
self._send_position_update(event)
|
||||
except aiotractive.exceptions.UnauthorizedError:
|
||||
self._config_entry.async_start_reauth(self._hass)
|
||||
await self.unsubscribe()
|
||||
_LOGGER.error(
|
||||
"Authentication failed for %s, try reconfiguring device",
|
||||
self._config_entry.data[CONF_EMAIL],
|
||||
)
|
||||
return
|
||||
|
||||
except aiotractive.exceptions.TractiveError:
|
||||
_LOGGER.debug(
|
||||
"Tractive is not available. Internet connection is down? Sleeping %i seconds and retrying",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Tractive",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/tractive",
|
||||
"requirements": ["aiotractive==0.5.4"],
|
||||
"requirements": ["aiotractive==0.5.5"],
|
||||
"codeowners": ["@Danielhiversen", "@zhulik", "@bieniu"],
|
||||
"iot_class": "cloud_push",
|
||||
"loggers": ["aiotractive"],
|
||||
|
|
|
@ -279,7 +279,7 @@ aioswitcher==3.1.0
|
|||
aiosyncthing==0.5.1
|
||||
|
||||
# homeassistant.components.tractive
|
||||
aiotractive==0.5.4
|
||||
aiotractive==0.5.5
|
||||
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==41
|
||||
|
|
|
@ -254,7 +254,7 @@ aioswitcher==3.1.0
|
|||
aiosyncthing==0.5.1
|
||||
|
||||
# homeassistant.components.tractive
|
||||
aiotractive==0.5.4
|
||||
aiotractive==0.5.5
|
||||
|
||||
# homeassistant.components.unifi
|
||||
aiounifi==41
|
||||
|
|
Loading…
Add table
Reference in a new issue