mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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
@ -83,7 +83,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await client.close()
|
await client.close()
|
||||||
raise ConfigEntryNotReady from error
|
raise ConfigEntryNotReady from error
|
||||||
|
|
||||||
tractive = TractiveClient(hass, client, creds["user_id"])
|
tractive = TractiveClient(hass, client, creds["user_id"], entry)
|
||||||
tractive.subscribe()
|
tractive.subscribe()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -148,7 +148,11 @@ class TractiveClient:
|
|||||||
"""A Tractive client."""
|
"""A Tractive client."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, client: aiotractive.Tractive, user_id: str
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
client: aiotractive.Tractive,
|
||||||
|
user_id: str,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the client."""
|
"""Initialize the client."""
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
@ -157,6 +161,7 @@ class TractiveClient:
|
|||||||
self._last_hw_time = 0
|
self._last_hw_time = 0
|
||||||
self._last_pos_time = 0
|
self._last_pos_time = 0
|
||||||
self._listen_task: asyncio.Task | None = None
|
self._listen_task: asyncio.Task | None = None
|
||||||
|
self._config_entry = config_entry
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_id(self) -> str:
|
def user_id(self) -> str:
|
||||||
@ -210,6 +215,15 @@ class TractiveClient:
|
|||||||
):
|
):
|
||||||
self._last_pos_time = event["position"]["time"]
|
self._last_pos_time = event["position"]["time"]
|
||||||
self._send_position_update(event)
|
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:
|
except aiotractive.exceptions.TractiveError:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Tractive is not available. Internet connection is down? Sleeping %i seconds and retrying",
|
"Tractive is not available. Internet connection is down? Sleeping %i seconds and retrying",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Tractive",
|
"name": "Tractive",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/tractive",
|
"documentation": "https://www.home-assistant.io/integrations/tractive",
|
||||||
"requirements": ["aiotractive==0.5.4"],
|
"requirements": ["aiotractive==0.5.5"],
|
||||||
"codeowners": ["@Danielhiversen", "@zhulik", "@bieniu"],
|
"codeowners": ["@Danielhiversen", "@zhulik", "@bieniu"],
|
||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["aiotractive"],
|
"loggers": ["aiotractive"],
|
||||||
|
@ -279,7 +279,7 @@ aioswitcher==3.1.0
|
|||||||
aiosyncthing==0.5.1
|
aiosyncthing==0.5.1
|
||||||
|
|
||||||
# homeassistant.components.tractive
|
# homeassistant.components.tractive
|
||||||
aiotractive==0.5.4
|
aiotractive==0.5.5
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==41
|
aiounifi==41
|
||||||
|
@ -254,7 +254,7 @@ aioswitcher==3.1.0
|
|||||||
aiosyncthing==0.5.1
|
aiosyncthing==0.5.1
|
||||||
|
|
||||||
# homeassistant.components.tractive
|
# homeassistant.components.tractive
|
||||||
aiotractive==0.5.4
|
aiotractive==0.5.5
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
aiounifi==41
|
aiounifi==41
|
||||||
|
Loading…
x
Reference in New Issue
Block a user