Skip to content

Commit

Permalink
Merge pull request #96 from litinoveweedle/delay_between_commands
Browse files Browse the repository at this point in the history
force delay after sending any IR command
  • Loading branch information
litinoveweedle authored Aug 2, 2024
2 parents 004114c + 4c02235 commit 8634105
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
42 changes: 12 additions & 30 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,34 +560,13 @@ async def _send_command(

try:
if state == STATE_OFF:
if (
self._hvac_mode == HVACMode.COOL
and "off_cool" in self._commands.keys()
and isinstance(self._commands["off_cool"], str)
off_mode = "off_" + self._hvac_mode
if off_mode in self._commands.keys() and isinstance(
self._commands[off_mode], str
):
_LOGGER.debug("Found 'off_cool' operation mode command.")
await self._controller.send(self._commands["off_cool"])
elif (
self._hvac_mode == HVACMode.HEAT
and "off_heat" in self._commands.keys()
and isinstance(self._commands["off_heat"], str)
):
_LOGGER.debug("Found 'off_heat' operation mode command.")
await self._controller.send(self._commands["off_heat"])
elif (
self._hvac_mode == HVACMode.FAN_ONLY
and "off_fan_only" in self._commands.keys()
and isinstance(self._commands["off_fan_only"], str)
):
_LOGGER.debug("Found 'off_fan_only' operation mode command.")
await self._controller.send(self._commands["off_fan_only"])
elif (
self._hvac_mode == HVACMode.DRY
and "off_dry" in self._commands.keys()
and isinstance(self._commands["off_dry"], str)
):
_LOGGER.debug("Found 'off_dry' operation mode command.")
await self._controller.send(self._commands["off_dry"])
_LOGGER.debug("Found '%s' operation mode command.", off_mode)
await self._controller.send(self._commands[off_mode])
await asyncio.sleep(self._delay)
elif "off" in self._commands.keys() and isinstance(
self._commands["off"], str
):
Expand All @@ -599,16 +578,18 @@ async def _send_command(
):
# 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",
"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 any of off/off_cool/off_heat/off_fan operation mode."
"Missing device IR code for 'off' or '%s' operation mode.",
off_mode,
)
return
else:
Expand All @@ -626,7 +607,7 @@ async def _send_command(
):
# 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",
"As 'on' and 'off' commands are identical and device is already in requested '%s' state, skipping sending '%s' command",
self._state,
"on",
)
Expand Down Expand Up @@ -788,6 +769,7 @@ async def _send_command(
return

await self._controller.send(commands)
await asyncio.sleep(self._delay)

self._on_by_remote = False
self._state = state
Expand Down
3 changes: 3 additions & 0 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ async def _send_command(self, state, speed, direction, oscillate):
if state == STATE_OFF:
if "off" in self._commands:
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 oscillate:
if "oscillate" in self._commands:
await self._controller.send(self._commands["oscillate"])
await asyncio.sleep(self._delay)
else:
_LOGGER.error(
"Missing device IR code for 'oscillate' mode."
Expand All @@ -300,6 +302,7 @@ async def _send_command(self, state, speed, direction, oscillate):
await self._controller.send(
self._commands[direction][speed]
)
await asyncio.sleep(self._delay)
else:
_LOGGER.error(
"Missing device IR code for direction '%s' speed '%s'.",
Expand Down

0 comments on commit 8634105

Please sign in to comment.