Skip to content

Commit

Permalink
Only need to lock once we send, not before
Browse files Browse the repository at this point in the history
  • Loading branch information
ehendrix23 committed Mar 6, 2021
1 parent a603011 commit 37f5176
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions pymyq/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 37f5176

Please sign in to comment.