diff --git a/onyx_client/enum/device_type.py b/onyx_client/enum/device_type.py index cc1f46c..b5c4a13 100644 --- a/onyx_client/enum/device_type.py +++ b/onyx_client/enum/device_type.py @@ -17,6 +17,7 @@ class DeviceType(Enum): PERGOLA_AWNING_ROOF = auto() PERGOLA_SIDE = auto() PERGOLA_SLAT_ROOF = auto() + DIMMABLE_LIGHT = auto() UNKNOWN = 9999 def string(self) -> str: @@ -36,6 +37,13 @@ def is_shutter(self) -> bool: self.PERGOLA_SLAT_ROOF, ] + def is_light(self) -> bool: + """Check if the type corresponds to any kind of light.""" + return self in [ + self.BASIC_LIGHT, + self.DIMMABLE_LIGHT, + ] + @staticmethod def convert(lower: str): """Get the device type from the Onyx API's type information. diff --git a/onyx_client/utils/device_type.py b/onyx_client/utils/device_type.py index 16dadb8..76ff9d9 100644 --- a/onyx_client/utils/device_type.py +++ b/onyx_client/utils/device_type.py @@ -25,7 +25,7 @@ def is_light(device_type: DeviceType, properties: dict) -> bool: device_type: the device type to check properties: the property map to check if no explicit type is specified""" if device_type is not None: - return device_type == DeviceType.BASIC_LIGHT + return device_type.is_light() return _in_keys(properties, Light.keys()) diff --git a/tests/enum/test_device_type.py b/tests/enum/test_device_type.py index 10f58f0..e510802 100644 --- a/tests/enum/test_device_type.py +++ b/tests/enum/test_device_type.py @@ -24,3 +24,7 @@ def test_is_shutter(self): assert DeviceType.PERGOLA_AWNING_ROOF.is_shutter() assert DeviceType.PERGOLA_SIDE.is_shutter() assert DeviceType.PERGOLA_SLAT_ROOF.is_shutter() + + def test_is_light(self): + assert DeviceType.BASIC_LIGHT.is_light() + assert DeviceType.DIMMABLE_LIGHT.is_light() diff --git a/tests/test_client.py b/tests/test_client.py index 50510e0..efd6c02 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -698,6 +698,32 @@ async def test_device_light_no_data(self, mock_response, client): assert device.actual_brightness is None assert device.dim_duration is None + @pytest.mark.asyncio + async def test_device_dimmable_light(self, mock_response, client): + mock_response.get( + f"{API_URL}/box/finger/api/{API_VERSION}/devices/device", + status=200, + payload={ + "name": "device", + "type": "dimmable_light", + "properties": { + "target_brightness": {"value": 1, "minimum": 10}, + "actual_brightness": {"value": 2, "minimum": 1, "maximum": 10}, + "dim_duration": {"value": 3, "minimum": 1, "maximum": 10}, + }, + "actions": ["stop"], + }, + ) + device = await client.device("device") + assert isinstance(device, Light) + assert device.device_type == DeviceType.DIMMABLE_LIGHT + assert device.device_mode.mode is None + assert len(device.device_mode.values) == 0 + assert device.actions == [Action.STOP] + assert device.target_brightness is not None + assert device.actual_brightness is not None + assert device.dim_duration is not None + @pytest.mark.asyncio async def test_device_click(self, mock_response, client): mock_response.get( diff --git a/tests/utils/test_device_type.py b/tests/utils/test_device_type.py index 577d4ba..1ceeb4a 100644 --- a/tests/utils/test_device_type.py +++ b/tests/utils/test_device_type.py @@ -12,6 +12,13 @@ def test_is_shutter(): assert is_shutter(DeviceType.ROLLERSHUTTER, {}) + assert is_shutter(DeviceType.AWNING, {}) + assert is_shutter(DeviceType.RAFFSTORE_90, {}) + assert is_shutter(DeviceType.RAFFSTORE_180, {}) + assert is_shutter(DeviceType.VENEER, {}) + assert is_shutter(DeviceType.PERGOLA_AWNING_ROOF, {}) + assert is_shutter(DeviceType.PERGOLA_SIDE, {}) + assert is_shutter(DeviceType.PERGOLA_SLAT_ROOF, {}) assert not is_shutter(DeviceType.WEATHER, {}) assert not is_shutter(None, {}) assert not is_shutter(None, None) @@ -21,6 +28,7 @@ def test_is_shutter(): def test_is_light(): assert is_light(DeviceType.BASIC_LIGHT, {}) + assert is_light(DeviceType.DIMMABLE_LIGHT, {}) assert not is_light(DeviceType.WEATHER, {}) assert not is_light(None, {}) assert not is_light(None, None)