Skip to content

Commit

Permalink
Add a typed helper for set brightness command
Browse files Browse the repository at this point in the history
  • Loading branch information
prystupa committed Jul 31, 2020
1 parent a371cc6 commit 8f7a502
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bond_api/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="bond_api",
version="0.1.7",
version="0.1.8",
packages=find_packages(exclude=['tests']),

author="Eugene Prystupa",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 8f7a502

Please sign in to comment.