Skip to content

Commit

Permalink
unified on/off state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
litinoveweedle committed Jan 19, 2025
1 parent 04a2e6e commit 5c7a956
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 33 deletions.
43 changes: 40 additions & 3 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,50 @@ async def _send_command(self, state, speed, direction, oscillate):

try:
if state == STATE_OFF:
if "off" in self._commands:
await self._controller.send(self._commands["off"])
await asyncio.sleep(self._delay)
if "off" in self._commands.keys() and isinstance(
self._commands["off"], str
):
if (
"on" in self._commands.keys()
and isinstance(self._commands["on"], str)
and self._commands["on"] == self._commands["off"]
and self._state == STATE_OFF
):
# prevent to resend 'off' command if same as 'on' and device is already off
_LOGGER.debug(
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"off",
)
else:
_LOGGER.debug("Found 'off' operation mode command.")
await self._controller.send(self._commands["off"])
await asyncio.sleep(self._delay)
else:
_LOGGER.error("Missing device IR code for 'off' mode.")
return
else:
if "on" in self._commands.keys() and isinstance(
self._commands["on"], str
):
if (
"off" in self._commands.keys()
and isinstance(self._commands["off"], str)
and self._commands["off"] == self._commands["on"]
and self._state == STATE_ON
):
# prevent to resend 'on' command if same as 'off' and device is already on
_LOGGER.debug(
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"on",
)
else:
# if on code is not present, the on bit can be still set later in the all operation/fan codes"""
_LOGGER.debug("Found 'on' operation mode command.")
await self._controller.send(self._commands["on"])
await asyncio.sleep(self._delay)

if oscillate:
if "oscillate" in self._commands:
await self._controller.send(self._commands["oscillate"])
Expand Down
69 changes: 39 additions & 30 deletions custom_components/smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,40 +223,49 @@ async def _send_command(self, state, commands):

try:
if state == STATE_OFF:
if (
"on" in self._commands.keys()
and isinstance(self._commands["on"], str)
and self._commands["on"] == self._commands["off"]
and self._state == STATE_OFF
if "off" in self._commands.keys() and isinstance(
self._commands["off"], str
):
# prevent to resend 'off' command if same as 'on' and device is already off
_LOGGER.debug(
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"off",
)
if (
"on" in self._commands.keys()
and isinstance(self._commands["on"], str)
and self._commands["on"] == self._commands["off"]
and self._state == STATE_OFF
):
# prevent to resend 'off' command if same as 'on' and device is already off
_LOGGER.debug(
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"off",
)
else:
_LOGGER.debug("Found 'off' operation mode command.")
await self._controller.send(self._commands["off"])
await asyncio.sleep(self._delay)
else:
_LOGGER.debug("Found 'off' operation mode command.")
await self._controller.send(self._commands["off"])
await asyncio.sleep(self._delay)
_LOGGER.error("Missing device IR code for 'off' mode.")
return
else:
if (
"off" in self._commands.keys()
and isinstance(self._commands["off"], str)
and self._commands["off"] == self._commands["on"]
and self._state == STATE_ON
if "on" in self._commands.keys() and isinstance(
self._commands["on"], str
):
# prevent to resend 'on' command if same as 'off' and device is already on
_LOGGER.debug(
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"on",
)
else:
# if on code is not present, the on bit can be still set later in the all operation/fan codes"""
_LOGGER.debug("Found 'on' operation mode command.")
await self._controller.send(self._commands["on"])
await asyncio.sleep(self._delay)
if (
"off" in self._commands.keys()
and isinstance(self._commands["off"], str)
and self._commands["off"] == self._commands["on"]
and self._state == STATE_ON
):
# prevent to resend 'on' command if same as 'off' and device is already on
_LOGGER.debug(
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"on",
)
else:
# if on code is not present, the on bit can be still set later in the all operation/fan codes"""
_LOGGER.debug("Found 'on' operation mode command.")
await self._controller.send(self._commands["on"])
await asyncio.sleep(self._delay)

for keys in commands:
data = self._commands
Expand Down

0 comments on commit 5c7a956

Please sign in to comment.