diff --git a/src/demetriek/__init__.py b/src/demetriek/__init__.py index 211a3304..414603ce 100644 --- a/src/demetriek/__init__.py +++ b/src/demetriek/__init__.py @@ -35,6 +35,7 @@ Range, Simple, Sound, + SoundURL, User, Wifi, ) @@ -69,6 +70,7 @@ "Range", "Simple", "Sound", + "SoundURL", "User", "Wifi", "WifiMode", diff --git a/src/demetriek/const.py b/src/demetriek/const.py index 32f83ca2..a6652a61 100644 --- a/src/demetriek/const.py +++ b/src/demetriek/const.py @@ -34,6 +34,7 @@ class DisplayType(str, Enum): GRAYSCALE = "grayscale" MIXED = "mixed" MONOCHROME = "monochrome" + FULL_RGB = "full_rgb" class NotificationIconType(str, Enum): diff --git a/src/demetriek/device.py b/src/demetriek/device.py index 1256c7de..5c48f547 100644 --- a/src/demetriek/device.py +++ b/src/demetriek/device.py @@ -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 @@ -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( diff --git a/src/demetriek/models.py b/src/demetriek/models.py index 3fc2981e..1b05a627 100644 --- a/src/demetriek/models.py +++ b/src/demetriek/models.py @@ -73,7 +73,7 @@ class Display(DataClassORJSONMixin): ) height: int on: bool | None = None - screensaver: DisplayScreensaver + screensaver: DisplayScreensaver | None = None width: int @@ -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 @@ -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) diff --git a/tests/test_device.py b/tests/test_device.py index f870c650..7daf890f 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -51,6 +51,7 @@ 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 @@ -58,6 +59,7 @@ async def test_get_device(aresponses: ResponsesMockServer) -> None: 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 @@ -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 @@ -103,6 +106,7 @@ 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 @@ -110,6 +114,7 @@ async def test_get_device2(aresponses: ResponsesMockServer) -> None: 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 diff --git a/tests/test_display.py b/tests/test_display.py index bec4ab95..3fae093b 100644 --- a/tests/test_display.py +++ b/tests/test_display.py @@ -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