Skip to content

Commit

Permalink
Add additional coverage (#163)
Browse files Browse the repository at this point in the history
* Add additional coverage

* add test for parsing addressable messages
  • Loading branch information
bdraco authored Nov 15, 2021
1 parent 44c67dc commit 128c0b8
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,80 @@ def _updated_callback(*args, **kwargs):
assert "Failed to turn on (3/3)" in caplog.text


@pytest.mark.asyncio
async def test_turn_on_off_via_power_state_message(
mock_aio_protocol, caplog: pytest.LogCaptureFixture
):
"""Test we can turn on and off via power state message."""
light = AIOWifiLedBulb("192.168.1.166")

def _updated_callback(*args, **kwargs):
pass

task = asyncio.create_task(light.async_setup(_updated_callback))
await mock_aio_protocol()
light._aio_protocol.data_received(
b"\x81\x25\x23\x61\x05\x10\xb6\x00\x98\x19\x04\x25\x0f\xde"
)
await task

task = asyncio.create_task(light.async_turn_off())
# Wait for the future to get added
await asyncio.sleep(0)
light._ignore_next_power_state_update = False
light._aio_protocol.data_received(b"\x0F\x71\x24\xA4")
await asyncio.sleep(0)
assert light.is_on is False
await task

task = asyncio.create_task(light.async_turn_on())
await asyncio.sleep(0)
light._ignore_next_power_state_update = False
light._aio_protocol.data_received(b"\x0F\x71\x23\xA3")
await asyncio.sleep(0)
assert light.is_on is True
await task


@pytest.mark.asyncio
async def test_turn_on_off_via_assessable_state_message(
mock_aio_protocol, caplog: pytest.LogCaptureFixture
):
"""Test we can turn on and off via addressable state message."""
light = AIOWifiLedBulb("192.168.1.166")

def _updated_callback(*args, **kwargs):
pass

task = asyncio.create_task(light.async_setup(_updated_callback))
await mock_aio_protocol()
light._aio_protocol.data_received(
b"\x81\xA2#\x25\x01\x10\x64\x00\x00\x00\x04\x00\xf0\xd4"
)
await task

task = asyncio.create_task(light.async_turn_off())
# Wait for the future to get added
await asyncio.sleep(0)
light._ignore_next_power_state_update = False
light._aio_protocol.data_received(
b"\xB0\xB1\xB2\xB3\x00\x01\x01\x23\x00\x0E\x81\xA3\x24\x25\xFF\x47\x64\xFF\xFF\x00\x01\x00\x1E\x34\x61"
)
await asyncio.sleep(0)
assert light.is_on is False
await task

task = asyncio.create_task(light.async_turn_on())
await asyncio.sleep(0)
light._ignore_next_power_state_update = False
light._aio_protocol.data_received(
b"\xB0\xB1\xB2\xB3\x00\x01\x01\x24\x00\x0E\x81\xA3\x23\x25\x5F\x21\x64\xFF\xFF\x00\x01\x00\x1E\x6D\xD4"
)
await asyncio.sleep(0)
assert light.is_on is True
await task


@pytest.mark.asyncio
async def test_shutdown(mock_aio_protocol):
"""Test we can shutdown."""
Expand Down

0 comments on commit 128c0b8

Please sign in to comment.