def _async_subscribe(self, callback=None): # pylint: disable=too-many-branches
""" event loop """
while True:
if self._reader is None:
yield from asyncio.sleep(0.1)
continue
try:
msg = yield from self._reader.readline()
except TimeoutError:
print('[E] Connection got timed out, try to reconnect...')
yield from self._connect(self._host)
except ConnectionResetError:
print('[E] Peer reset our connection, try to reconnect...')
yield from self._connect(self._host)
except (GeneratorExit, CancelledError):
print('[I] Cancelling event loop...')
return
except: # pylint: disable=bare-except
print('[E] Ignoring', sys.exc_info()[0])
if self._verbose:
print(msg.decode())
# simplejson doesnt need to decode from byte to ascii
data = json.loads(msg.decode())
if self._verbose:
print('DATA:')
print(data)
try:
self._parse_command(data)
except AioHeosException as exc:
print('[E]', exc)
if self._verbose:
print('MSG', msg)
print('MSG decoded', msg.decode())
print('MSG json', data)
continue
if callback:
if self._verbose:
print('TRIGGER CALLBACK')
self._loop.create_task(self._callback_wrapper(callback))
评论列表
文章目录