Skip to content

Commit

Permalink
Adjust buggy firmware turn on workaround to reduce chance of device f…
Browse files Browse the repository at this point in the history
…lash at turn on (#288)
  • Loading branch information
bdraco authored Dec 31, 2021
1 parent e7efeb8 commit b2c9dcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions flux_led/aiodevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ async def _async_turn_off_on(self) -> None:
async def async_turn_on(self) -> bool:
"""Turn on the device."""
calls = (
self._async_turn_on,
self._async_turn_on,
self._async_turn_off_on,
self._async_turn_on,
Expand Down Expand Up @@ -234,6 +235,7 @@ async def _async_turn_on_off(self) -> None:
async def async_turn_off(self) -> bool:
"""Turn off the device."""
calls = (
self._async_turn_off,
self._async_turn_off,
self._async_turn_on_off,
self._async_turn_off,
Expand Down
18 changes: 10 additions & 8 deletions tests_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,11 @@ def _updated_callback(*args, **kwargs):
with patch.object(aiodevice, "POWER_STATE_TIMEOUT", 0.025):
await asyncio.create_task(light.async_turn_off())
assert light.is_on is True
assert "Failed to turn off (1/4)" in caplog.text
assert "Failed to turn off (2/4)" in caplog.text
assert "Failed to turn off (3/4)" in caplog.text
assert "Failed to turn off (4/4)" in caplog.text
assert "Failed to turn off (1/5)" in caplog.text
assert "Failed to turn off (2/5)" in caplog.text
assert "Failed to turn off (3/5)" in caplog.text
assert "Failed to turn off (4/5)" in caplog.text
assert "Failed to turn off (5/5)" in caplog.text

with patch.object(aiodevice, "POWER_STATE_TIMEOUT", 0.025):
task = asyncio.create_task(light.async_turn_off())
Expand All @@ -397,10 +398,11 @@ def _updated_callback(*args, **kwargs):
with patch.object(aiodevice, "POWER_STATE_TIMEOUT", 0.025):
await asyncio.create_task(light.async_turn_on())
assert light.is_on is False
assert "Failed to turn on (1/4)" in caplog.text
assert "Failed to turn on (2/4)" in caplog.text
assert "Failed to turn on (3/4)" in caplog.text
assert "Failed to turn on (4/4)" in caplog.text
assert "Failed to turn on (1/5)" in caplog.text
assert "Failed to turn on (2/5)" in caplog.text
assert "Failed to turn on (3/5)" in caplog.text
assert "Failed to turn on (4/5)" in caplog.text
assert "Failed to turn on (5/5)" in caplog.text


@pytest.mark.asyncio
Expand Down

0 comments on commit b2c9dcb

Please sign in to comment.