Close connection properly on error

This commit is contained in:
Pierre Ståhl
2020-10-04 22:07:38 +02:00
committed by rospogrigio
parent 2565074c9c
commit f971646333
2 changed files with 5 additions and 3 deletions

View File

@@ -336,11 +336,13 @@ class TuyaProtocol(asyncio.Protocol):
def close(self):
"""Close connection and abort all outstanding listeners."""
if self.transport is not None:
self.dispatcher.abort()
self.heartbeater.cancel()
transport = self.transport
self.transport = None
transport.close()
if self.dispatcher is not None:
self.dispatcher.abort()
if self.heartbeater is not None:
self.heartbeater.cancel()
async def exchange(self, command, dps=None):
"""Send and receive a message, returning response from device."""