mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Handle traccar connection errors (#23289)
* Handle connection errors * Fix lint issue E127 * Remove periods from logs * Merge connection checks * Fail with bad credentials * Move stuff around for async_init * Fix E128 linting issue * Simplify
This commit is contained in:
committed by
Charles Garwood
parent
5b0ee473b6
commit
2871a650f6
@@ -109,26 +109,38 @@ class TraccarScanner:
|
||||
self._scan_interval = scan_interval
|
||||
self._async_see = async_see
|
||||
self._api = api
|
||||
self.connected = False
|
||||
self._hass = hass
|
||||
|
||||
async def async_init(self):
|
||||
"""Further initialize connection to Traccar."""
|
||||
await self._api.test_connection()
|
||||
if self._api.authenticated:
|
||||
await self._async_update()
|
||||
async_track_time_interval(self._hass,
|
||||
self._async_update,
|
||||
self._scan_interval)
|
||||
if self._api.connected and not self._api.authenticated:
|
||||
_LOGGER.error("Authentication for Traccar failed")
|
||||
return False
|
||||
|
||||
return self._api.authenticated
|
||||
await self._async_update()
|
||||
async_track_time_interval(self._hass,
|
||||
self._async_update,
|
||||
self._scan_interval)
|
||||
return True
|
||||
|
||||
async def _async_update(self, now=None):
|
||||
"""Update info from Traccar."""
|
||||
_LOGGER.debug('Updating device data.')
|
||||
if not self.connected:
|
||||
_LOGGER.debug('Testing connection to Traccar')
|
||||
await self._api.test_connection()
|
||||
self.connected = self._api.connected
|
||||
if self.connected:
|
||||
_LOGGER.info("Connection to Traccar restored")
|
||||
else:
|
||||
return
|
||||
_LOGGER.debug('Updating device data')
|
||||
await self._api.get_device_info(self._custom_attributes)
|
||||
self._hass.async_create_task(self.import_device_data())
|
||||
if self._event_types:
|
||||
self._hass.async_create_task(self.import_events())
|
||||
self.connected = self._api.connected
|
||||
|
||||
async def import_device_data(self):
|
||||
"""Import device data from Traccar."""
|
||||
|
||||
Reference in New Issue
Block a user