Add logging to light updates (#17069)
parent
11d5671ee0
commit
a6f8c3f662
|
@ -7,6 +7,7 @@ https://home-assistant.io/components/light.hue/
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from time import monotonic
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
@ -159,18 +160,23 @@ async def async_update_items(hass, bridge, async_add_entities,
|
||||||
import aiohue
|
import aiohue
|
||||||
|
|
||||||
if is_group:
|
if is_group:
|
||||||
|
api_type = 'group'
|
||||||
api = bridge.api.groups
|
api = bridge.api.groups
|
||||||
else:
|
else:
|
||||||
|
api_type = 'light'
|
||||||
api = bridge.api.lights
|
api = bridge.api.lights
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
start = monotonic()
|
||||||
with async_timeout.timeout(4):
|
with async_timeout.timeout(4):
|
||||||
await api.update()
|
await api.update()
|
||||||
except (asyncio.TimeoutError, aiohue.AiohueException):
|
except (asyncio.TimeoutError, aiohue.AiohueException) as err:
|
||||||
|
_LOGGER.debug('Failed to fetch %s: %s', api_type, err)
|
||||||
|
|
||||||
if not bridge.available:
|
if not bridge.available:
|
||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.error('Unable to reach bridge %s', bridge.host)
|
_LOGGER.error('Unable to reach bridge %s (%s)', bridge.host, err)
|
||||||
bridge.available = False
|
bridge.available = False
|
||||||
|
|
||||||
for light_id, light in current.items():
|
for light_id, light in current.items():
|
||||||
|
@ -179,6 +185,10 @@ async def async_update_items(hass, bridge, async_add_entities,
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
finally:
|
||||||
|
_LOGGER.debug('Finished %s request in %.3f seconds',
|
||||||
|
api_type, monotonic() - start)
|
||||||
|
|
||||||
if not bridge.available:
|
if not bridge.available:
|
||||||
_LOGGER.info('Reconnected to bridge %s', bridge.host)
|
_LOGGER.info('Reconnected to bridge %s', bridge.host)
|
||||||
bridge.available = True
|
bridge.available = True
|
||||||
|
|
Loading…
Reference in New Issue