From 37f51767a40246a4a036a48b46da52f6941bc175 Mon Sep 17 00:00:00 2001 From: Erik Hendrix Date: Sat, 6 Mar 2021 12:57:16 -0700 Subject: [PATCH] Only need to lock once we send, not before --- pymyq/device.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pymyq/device.py b/pymyq/device.py index 16203fa..929e27f 100644 --- a/pymyq/device.py +++ b/pymyq/device.py @@ -170,33 +170,33 @@ async def _send_state_command( f"Cannot change state of device type: {self.device_type}" ) - async with self._send_command_lock: - # If currently there is a wait_for_state task running, - # then wait until it completes first. - if self._wait_for_state_task is not None: - # Return wait task if we're currently waiting for same task to be completed - if self.state == intermediate_state and not wait_for_state: - _LOGGER.debug( - "Command %s for %s was already send, returning wait task for it instead", - command, - self.name, - ) - return self._wait_for_state_task - + # If currently there is a wait_for_state task running, + # then wait until it completes first. + if self._wait_for_state_task is not None: + # Return wait task if we're currently waiting for same task to be completed + if self.state == intermediate_state and not wait_for_state: _LOGGER.debug( - "Another command for %s is still in progress, waiting for it to complete first before issuing command %s", - self.name, + "Command %s for %s was already send, returning wait task for it instead", command, + self.name, ) - await self._wait_for_state_task + return self._wait_for_state_task - # We return true if state is already closed. - if self.state == to_state: - _LOGGER.debug( - "Device %s is in state %s, nothing to do.", self.name, to_state - ) - return True + _LOGGER.debug( + "Another command for %s is still in progress, waiting for it to complete first before issuing command %s", + self.name, + command, + ) + await self._wait_for_state_task + + # We return true if state is already closed. + if self.state == to_state: + _LOGGER.debug( + "Device %s is in state %s, nothing to do.", self.name, to_state + ) + return True + async with self._send_command_lock: _LOGGER.debug("Sending command %s for %s", command, self.name) await self.account.api.request( method="put",