aioheos.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:aioheos 作者: easink 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号