def async_update(self):
"""Retrieve the latest data."""
_LOGGER.debug('%s.async_update()', self)
if not self._device:
_LOGGER.debug('%s.async_update(): no device', self)
try:
yield from self._async_init_device()
except (asyncio.TimeoutError, aiohttp.ClientError):
# Not yet seen alive, leave for now, gracefully
_LOGGER.debug('%s._async_update(): device not seen yet, leaving', self)
return
# XXX TODO: if re-connected, then (re-)subscribe
# call GetTransportInfo/GetPositionInfo regularly
try:
_LOGGER.debug('%s.async_update(): calling...', self)
avt_service = self._service('AVT')
if avt_service:
get_transport_info_action = avt_service.action('GetTransportInfo')
state = yield from self._async_poll_transport_info(get_transport_info_action)
if state == STATE_PLAYING or state == STATE_PAUSED:
# playing something... get position info
get_position_info_action = avt_service.action('GetPositionInfo')
yield from self._async_poll_position_info(get_position_info_action)
else:
_LOGGER.debug('%s.async_update(): pinging...', self)
yield from self._device.async_ping()
self._is_connected = True
except (asyncio.TimeoutError, aiohttp.ClientError) as ex:
_LOGGER.debug('%s.async_update(): error on update: %s', self, ex)
self._is_connected = False
yield from self.async_unsubscribe_all()
评论列表
文章目录