Merge branch 'sibowler-fix_semaphore_release_error' into stability_fixes

This commit is contained in:
rospogrigio
2023-01-24 17:58:10 +01:00
committed by GitHub Actions
2 changed files with 13 additions and 10 deletions

View File

@@ -196,7 +196,9 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
) )
self._interface.add_dps_to_request(self.dps_to_request) self._interface.add_dps_to_request(self.dps_to_request)
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
self.warning(f"Connect to {self._dev_config_entry[CONF_HOST]} failed attempting to connect") self.warning(
f"Connect to {self._dev_config_entry[CONF_HOST]} failed attempting to connect"
)
if self._interface is not None: if self._interface is not None:
await self._interface.close() await self._interface.close()
self._interface = None self._interface = None
@@ -231,14 +233,10 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
self._interface.start_heartbeat() self._interface.start_heartbeat()
self.status_updated(status) self.status_updated(status)
else: else:
self.error( self.error(f"Initial state update failed, giving up: %r", ex)
f"Initial state update failed, giving up: %r", ex
)
# return # return
except (UnicodeDecodeError, json.decoder.JSONDecodeError) as ex: except (UnicodeDecodeError, json.decoder.JSONDecodeError) as ex:
self.exception( self.exception(f"Initial state update failed, trying key update")
f"Initial state update failed, trying key update"
)
await self.update_local_key() await self.update_local_key()
if self._interface is not None: if self._interface is not None:

View File

@@ -449,7 +449,9 @@ class MessageDispatcher(ContextualLogger):
try: try:
await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
except asyncio.TimeoutError: except asyncio.TimeoutError:
self.warning("Command %d timed out waiting for sequence number %d", cmd, seqno) self.warning(
"Command %d timed out waiting for sequence number %d", cmd, seqno
)
del self.listeners[seqno] del self.listeners[seqno]
raise raise
@@ -479,8 +481,11 @@ class MessageDispatcher(ContextualLogger):
if msg.seqno in self.listeners: if msg.seqno in self.listeners:
# self.debug("Dispatching sequence number %d", msg.seqno) # self.debug("Dispatching sequence number %d", msg.seqno)
sem = self.listeners[msg.seqno] sem = self.listeners[msg.seqno]
self.listeners[msg.seqno] = msg if isinstance(sem, asyncio.Semaphore):
sem.release() self.listeners[msg.seqno] = msg
sem.release()
else:
self.debug("Got additional message without request - skipping: %s", sem)
elif msg.cmd == HEART_BEAT: elif msg.cmd == HEART_BEAT:
self.debug("Got heartbeat response") self.debug("Got heartbeat response")
if self.HEARTBEAT_SEQNO in self.listeners: if self.HEARTBEAT_SEQNO in self.listeners: