Skip to content

Commit

Permalink
Added support for LaMetric SKY devices and SoundURL model for notific…
Browse files Browse the repository at this point in the history
…ation (#720)

Co-authored-by: Franck Nijhof <[email protected]>
  • Loading branch information
lm-db and frenck authored Dec 12, 2024
1 parent 5d9599a commit 11771af
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/demetriek/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Range,
Simple,
Sound,
SoundURL,
User,
Wifi,
)
Expand Down Expand Up @@ -69,6 +70,7 @@
"Range",
"Simple",
"Sound",
"SoundURL",
"User",
"Wifi",
"WifiMode",
Expand Down
1 change: 1 addition & 0 deletions src/demetriek/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DisplayType(str, Enum):
GRAYSCALE = "grayscale"
MIXED = "mixed"
MONOCHROME = "monochrome"
FULL_RGB = "full_rgb"


class NotificationIconType(str, Enum):
Expand Down
10 changes: 9 additions & 1 deletion src/demetriek/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
LaMetricConnectionTimeoutError,
LaMetricError,
)
from .models import Audio, Bluetooth, Device, Display, Notification, Wifi
from .models import (
Audio,
Bluetooth,
Device,
Display,
Notification,
Wifi,
)

if TYPE_CHECKING:
from .const import BrightnessMode
Expand Down Expand Up @@ -137,6 +144,7 @@ async def device(self) -> Device:
ssid=response["wifi"].get("essid"),
rssi=response["wifi"].get("strength"),
)

return Device.from_dict(response)

async def display(
Expand Down
17 changes: 13 additions & 4 deletions src/demetriek/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Display(DataClassORJSONMixin):
)
height: int
on: bool | None = None
screensaver: DisplayScreensaver
screensaver: DisplayScreensaver | None = None
width: int


Expand All @@ -96,8 +96,8 @@ class Wifi(DataClassORJSONMixin):
class Device(DataClassORJSONMixin):
"""Object holding the state of an LaMetric device."""

audio: Audio
bluetooth: Bluetooth
audio: Audio | None = None
bluetooth: Bluetooth | None = None
device_id: str = field(metadata=field_options(alias="id"))
display: Display
mode: DeviceMode
Expand Down Expand Up @@ -179,13 +179,22 @@ class Config(BaseConfig):
allow_deserialization_not_by_alias = True


@dataclass(kw_only=True)
class SoundURL(DataClassORJSONMixin):
"""Sound URL model configuration."""

url: str
type: str = "mp3"
fallback: Sound | None = None


@dataclass(kw_only=True)
class Model(DataClassORJSONMixin):
"""Object holding the notification model of an LaMetric device."""

cycles: int = 1
frames: list[Chart | Goal | Simple]
sound: Sound | None = None
sound: SoundURL | Sound | None


@dataclass(kw_only=True)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ async def test_get_device(aresponses: ResponsesMockServer) -> None:
assert device.os_version == "2.2.2"
assert device.mode is DeviceMode.AUTO
assert device.model == "LM 37X8"
assert device.audio
assert device.audio.volume == 100
assert device.audio.volume_range
assert device.audio.volume_range.range_min == 0
assert device.audio.volume_range.range_max == 100
assert device.audio.volume_limit
assert device.audio.volume_limit.range_min == 0
assert device.audio.volume_limit.range_max == 100
assert device.bluetooth
assert device.bluetooth.available is True
assert device.bluetooth.name == "LM1234"
assert device.bluetooth.active is False
Expand All @@ -69,6 +71,7 @@ async def test_get_device(aresponses: ResponsesMockServer) -> None:
assert device.display.width == 37
assert device.display.height == 8
assert device.display.display_type is DisplayType.MIXED
assert device.display.screensaver
assert device.display.screensaver.enabled is False
assert device.wifi.active is True
assert device.wifi.available is True
Expand Down Expand Up @@ -103,13 +106,15 @@ async def test_get_device2(aresponses: ResponsesMockServer) -> None:
assert device.os_version == "2.2.2"
assert device.mode is DeviceMode.SCHEDULE
assert device.model == "LM 37X8"
assert device.audio
assert device.audio.volume == 100
assert device.audio.volume_range
assert device.audio.volume_range.range_min == 0
assert device.audio.volume_range.range_max == 100
assert device.audio.volume_limit
assert device.audio.volume_limit.range_min == 0
assert device.audio.volume_limit.range_max == 100
assert device.bluetooth
assert device.bluetooth.available is True
assert device.bluetooth.name == "LM1234"
assert device.bluetooth.active is False
Expand Down
1 change: 1 addition & 0 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ async def response_handler(request: aiohttp.ClientResponse) -> Response:
assert display.width == 37
assert display.height == 8
assert display.display_type is DisplayType.MIXED
assert display.screensaver
assert display.screensaver.enabled is False
assert display.on is True

0 comments on commit 11771af

Please sign in to comment.