Skip to content

Commit

Permalink
Improve docstring and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane610 committed Jul 7, 2022
1 parent be1e6dc commit d79bcaf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions pydeconz/models/light/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ class CoverAction(enum.Enum):


class Cover(LightBase):
"""Cover and Damper class.
Position 0 means open and 100 means closed.
"""
"""Cover and Damper class."""

raw: TypedCover

Expand All @@ -47,18 +44,23 @@ def is_open(self) -> bool:
def lift(self) -> int:
"""Amount of closed position.
0 is fully open.
100 is fully closed.
Supported values:
0-100 - 0 is open / 100 is closed
"""
return self.raw["state"]["lift"]

@property
def tilt(self) -> int | None:
"""Amount of tilt.
0 is fully open.
100 is fully closed.
Supported values:
0-100 - 0 is open / 100 is closed
"""
if "tilt" in self.raw["state"]:
return self.raw["state"]["tilt"]
return None

@property
def supports_tilt(self) -> bool:
"""Supports tilt."""
return "tilt" in self.raw["state"]
8 changes: 6 additions & 2 deletions tests/lights/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def test_light_cover(mock_aioresponse, deconz_light, deconz_called_with):
assert cover.is_open is True
assert cover.lift == 0
assert cover.tilt is None
assert cover.supports_tilt is False

assert cover.reachable is True

Expand All @@ -78,12 +79,15 @@ async def test_light_cover(mock_aioresponse, deconz_light, deconz_called_with):
cover.register_callback(mock_callback := Mock())
assert cover._callbacks

event = {"state": {"lift": 50, "open": True}}
cover.update(event)
cover.update({"state": {"lift": 50, "open": True}})
assert cover.is_open is True
assert cover.lift == 50
mock_callback.assert_called_once()
assert cover.changed_keys == {"state", "lift", "open"}

cover.update({"state": {"tilt": 25, "open": True}})
assert cover.tilt == 25
assert cover.supports_tilt is True

cover.remove_callback(mock_callback)
assert not cover._callbacks

0 comments on commit d79bcaf

Please sign in to comment.