Skip to content

Commit

Permalink
fix: add dimmable light mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
muhlba91 committed Dec 11, 2023
1 parent d9fb32c commit bd85d11
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
8 changes: 8 additions & 0 deletions onyx_client/enum/device_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion onyx_client/utils/device_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand Down
4 changes: 4 additions & 0 deletions tests/enum/test_device_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
26 changes: 26 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions tests/utils/test_device_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit bd85d11

Please sign in to comment.