Add more temporary logging

This commit is contained in:
Pierre Ståhl
2020-10-11 22:36:16 +02:00
committed by rospogrigio
parent ff3ca99b29
commit 91f788865c
2 changed files with 24 additions and 3 deletions

View File

@@ -112,7 +112,21 @@ class TuyaDevice(pytuya.TuyaListener):
def connect(self): def connect(self):
"""Connet to device if not already connected.""" """Connet to device if not already connected."""
if not self._is_closing and self._connect_task is None and not self._interface: if not self._is_closing and self._connect_task is None and not self._interface:
_LOGGER.debug(
"Connecting to %s (%s)",
self._config_entry[CONF_HOST],
self._config_entry[CONF_DEVICE_ID],
)
self._connect_task = asyncio.ensure_future(self._make_connection()) self._connect_task = asyncio.ensure_future(self._make_connection())
else:
_LOGGER.debug(
"Already connecting to %s (%s) - %s, %s, %s",
self._config_entry[CONF_HOST],
self._config_entry[CONF_DEVICE_ID],
self._is_closing,
self._connect_task,
self._interface,
)
async def _make_connection(self): async def _make_connection(self):
backoff = min( backoff = min(

View File

@@ -327,6 +327,7 @@ class TuyaProtocol(asyncio.Protocol):
async def heartbeat_loop(): async def heartbeat_loop():
"""Continuously send heart beat updates.""" """Continuously send heart beat updates."""
self.log.debug("Started heartbeat loop")
while True: while True:
try: try:
await self.heartbeat() await self.heartbeat()
@@ -334,6 +335,7 @@ class TuyaProtocol(asyncio.Protocol):
self.log.exception("Heartbeat failed (%s), disconnecting", ex) self.log.exception("Heartbeat failed (%s), disconnecting", ex)
break break
await asyncio.sleep(HEARTBEAT_INTERVAL) await asyncio.sleep(HEARTBEAT_INTERVAL)
self.log.debug("Stopped heartbeat loop")
self.close() self.close()
self.transport = transport self.transport = transport
@@ -346,17 +348,22 @@ class TuyaProtocol(asyncio.Protocol):
def connection_lost(self, exc): def connection_lost(self, exc):
"""Disconnected from device.""" """Disconnected from device."""
self.log.debug("connection_lost: %s", exc)
try: try:
self.close() self.close()
except Exception: except Exception:
self.log.exception("Failed to close connection") self.log.exception("Failed to close connection")
finally: finally:
listener = self.listener() try:
if listener is not None: listener = self.listener()
listener.disconnected(exc) if listener is not None:
listener.disconnected(exc)
except Exception:
self.log.exception("Failed to call disconnected callback")
def close(self): def close(self):
"""Close connection and abort all outstanding listeners.""" """Close connection and abort all outstanding listeners."""
self.log.debug("Closing connection")
if self.heartbeater is not None: if self.heartbeater is not None:
self.heartbeater.cancel() self.heartbeater.cancel()
if self.dispatcher is not None: if self.dispatcher is not None: