From 666b79cb707742097648491a93dab61e31dd20df Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 15 Apr 2022 20:47:34 -1000 Subject: [PATCH] Enable push updates for socket protocol (#370) --- flux_led/protocol.py | 10 ++++++++++ tests_aio.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/flux_led/protocol.py b/flux_led/protocol.py index c472e297..e0fb0e95 100755 --- a/flux_led/protocol.py +++ b/flux_led/protocol.py @@ -2072,6 +2072,16 @@ def construct_device_config( class ProtocolLEDENETSocket(ProtocolLEDENET8Byte): + @property + def power_push_updates(self) -> bool: + """If True the protocol pushes power state updates when controlled via ir/rf/app.""" + return True + + @property + def state_push_updates(self) -> bool: + """If True the protocol pushes state updates when controlled via ir/rf/app.""" + return True + @property def name(self) -> str: """The name of the protocol.""" diff --git a/tests_aio.py b/tests_aio.py index 9808e561..3132d823 100644 --- a/tests_aio.py +++ b/tests_aio.py @@ -2585,6 +2585,29 @@ def _updated_callback(*args, **kwargs): assert str(timers[3]) == "[ON ] 17:48 SuMoTuWeThFrSa " +@pytest.mark.asyncio +async def test_sockets_push_updates( + mock_aio_protocol, caplog: pytest.LogCaptureFixture +): + """Test we can get the timers.""" + socket = AIOWifiLedBulb("192.168.1.166") + + def _updated_callback(*args, **kwargs): + pass + + task = asyncio.create_task(socket.async_setup(_updated_callback)) + transport, protocol = await mock_aio_protocol() + socket._aio_protocol.data_received( + b"\x81\x97\x23\x61\x05\x10\xb6\x00\x98\x19\x04\x25\x0f\x50" + ) + socket._aio_protocol.data_received(b"\xf0\x32\xf0\xf0\xf0\xf0\xe2") + + await task + assert socket.model_num == 0x97 + assert socket._protocol.power_push_updates is True + assert socket._protocol.state_push_updates is True + + @pytest.mark.asyncio async def test_async_get_timers_8_byte_device( mock_aio_protocol, caplog: pytest.LogCaptureFixture