Close connection properly on error
This commit is contained in:
committed by
rospogrigio
parent
2565074c9c
commit
f971646333
@@ -108,7 +108,7 @@ class TuyaDevice(pytuya.TuyaListener):
|
||||
for entity in config_entry[CONF_ENTITIES]:
|
||||
self._dps_to_request[entity[CONF_ID]] = None
|
||||
|
||||
def connect(self, delay=None):
|
||||
def connect(self):
|
||||
"""Connet to device if not already connected."""
|
||||
if self._connect_task is None:
|
||||
self._connect_task = asyncio.ensure_future(self._make_connection())
|
||||
|
@@ -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."""
|
||||
|
Reference in New Issue
Block a user