Skip to content

Commit

Permalink
Extend support for LaMetric SKY on state (#562)
Browse files Browse the repository at this point in the history
Co-authored-by: Franck Nijhof <[email protected]>
  • Loading branch information
spyfly and frenck authored Dec 12, 2024
1 parent e4ff266 commit 5d9599a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/demetriek/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async def display(
brightness: int | None = None,
brightness_mode: BrightnessMode | None = None,
screensaver_enabled: bool | None = None,
on: bool | None = None,
) -> Display:
"""Get or set LaMetric device display information.
Expand All @@ -153,6 +154,7 @@ async def display(
brightness: Brightness level to set.
brightness_mode: Brightness mode to set.
screensaver_enabled: Whether the screensaver should be enabled.
on: Whether the display should be turned on or off.
Returns:
-------
Expand All @@ -171,6 +173,9 @@ async def display(
if screensaver_enabled is not None:
data["screensaver"] = {"enabled": screensaver_enabled}

if on is not None:
data["on"] = on

if data:
response = await self._request(
"/api/v2/device/display",
Expand Down
1 change: 1 addition & 0 deletions src/demetriek/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Display(DataClassORJSONMixin):
default=None, metadata=field_options(alias="type")
)
height: int
on: bool | None = None
screensaver: DisplayScreensaver
width: int

Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/display.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"min": 0
},
"height": 8,
"on": true,
"screensaver": {
"enabled": false,
"modes": {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/display_set.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"min": 0
},
"height": 8,
"on": true,
"screensaver": {
"enabled": false,
"modes": {
Expand Down
4 changes: 4 additions & 0 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def test_get_display(aresponses: ResponsesMockServer) -> None:
assert display.width == 37
assert display.height == 8
assert display.display_type is DisplayType.MIXED
assert display.on is True


async def test_set_display(aresponses: ResponsesMockServer) -> None:
Expand All @@ -46,6 +47,7 @@ async def response_handler(request: aiohttp.ClientResponse) -> Response:
"screensaver": {
"enabled": False,
},
"on": True,
}
return aresponses.Response(
status=200,
Expand All @@ -61,6 +63,7 @@ async def response_handler(request: aiohttp.ClientResponse) -> Response:
brightness=99,
brightness_mode=BrightnessMode.MANUAL,
screensaver_enabled=False,
on=True,
)

assert display
Expand All @@ -70,3 +73,4 @@ async def response_handler(request: aiohttp.ClientResponse) -> Response:
assert display.height == 8
assert display.display_type is DisplayType.MIXED
assert display.screensaver.enabled is False
assert display.on is True

0 comments on commit 5d9599a

Please sign in to comment.