From 8f7a502f4c7fe553c2ad46e813e1ece8a2ec01fd Mon Sep 17 00:00:00 2001 From: Eugene Prystupa Date: Fri, 31 Jul 2020 18:25:22 -0400 Subject: [PATCH] Add a typed helper for set brightness command --- bond_api/action.py | 5 +++++ setup.py | 2 +- tests/test_bond.py | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bond_api/action.py b/bond_api/action.py index 9224a2b..59b48fb 100644 --- a/bond_api/action.py +++ b/bond_api/action.py @@ -128,6 +128,11 @@ def turn_light_off() -> 'Action': """Turns off the fan light.""" return Action(Action.TURN_LIGHT_OFF) + @staticmethod + def set_brightness(brightness: int) -> 'Action': + """Sets brightness of the light as percentage value, 1-100.""" + return Action(Action.SET_BRIGHTNESS, brightness) + @staticmethod def set_flame(flame: int) -> 'Action': """Sets the flame to given intensity in percent.""" diff --git a/setup.py b/setup.py index c1334b6..d8e2137 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="bond_api", - version="0.1.7", + version="0.1.8", packages=find_packages(exclude=['tests']), author="Eugene Prystupa", diff --git a/tests/test_bond.py b/tests/test_bond.py index ae97035..dedc640 100644 --- a/tests/test_bond.py +++ b/tests/test_bond.py @@ -208,6 +208,21 @@ def callback(_url, **kwargs): await bond.action("test-device-id", Action.turn_light_off()) +@pytest.mark.asyncio +async def test_set_brightness(bond: Bond): + """Tests set_brightness action delegates to API.""" + with aioresponses() as response: + def callback(_url, **kwargs): + assert kwargs.get("json") == {"argument": 50} + return CallbackResult() + + response.put( + "http://test-host/v2/devices/test-device-id/actions/SetBrightness", + callback=callback + ) + await bond.action("test-device-id", Action.set_brightness(50)) + + @pytest.mark.asyncio async def test_set_direction_forward(bond: Bond): """Tests set_direction action delegates to API with correct value for forward."""