mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Update deconz/cover.py to adapt rest-api changes (#32351)
* Update cover.py to adapt rest-api changes * adjust test to reflect max brightness changes * implement test for rest-api cover position of 255
This commit is contained in:
parent
8d68f34650
commit
7ec7306ea8
@ -61,7 +61,7 @@ class DeconzCover(DeconzDevice, CoverDevice):
|
||||
@property
|
||||
def current_cover_position(self):
|
||||
"""Return the current position of the cover."""
|
||||
return 100 - int(self._device.brightness / 255 * 100)
|
||||
return 100 - int(self._device.brightness / 254 * 100)
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
@ -88,7 +88,7 @@ class DeconzCover(DeconzDevice, CoverDevice):
|
||||
|
||||
if position < 100:
|
||||
data["on"] = True
|
||||
data["bri"] = 255 - int(position / 100 * 255)
|
||||
data["bri"] = 254 - int(position / 100 * 254)
|
||||
|
||||
await self._device.async_set_state(data)
|
||||
|
||||
|
@ -14,7 +14,7 @@ COVERS = {
|
||||
"id": "Level controllable cover id",
|
||||
"name": "Level controllable cover",
|
||||
"type": "Level controllable output",
|
||||
"state": {"bri": 255, "on": False, "reachable": True},
|
||||
"state": {"bri": 254, "on": False, "reachable": True},
|
||||
"modelid": "Not zigbee spec",
|
||||
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||
},
|
||||
@ -22,7 +22,7 @@ COVERS = {
|
||||
"id": "Window covering device id",
|
||||
"name": "Window covering device",
|
||||
"type": "Window covering device",
|
||||
"state": {"bri": 255, "on": True, "reachable": True},
|
||||
"state": {"bri": 254, "on": True, "reachable": True},
|
||||
"modelid": "lumi.curtain",
|
||||
"uniqueid": "00:00:00:00:00:00:00:01-00",
|
||||
},
|
||||
@ -33,6 +33,14 @@ COVERS = {
|
||||
"state": {"reachable": True},
|
||||
"uniqueid": "00:00:00:00:00:00:00:02-00",
|
||||
},
|
||||
"4": {
|
||||
"id": "deconz old brightness cover id",
|
||||
"name": "deconz old brightness cover",
|
||||
"type": "Level controllable output",
|
||||
"state": {"bri": 255, "on": False, "reachable": True},
|
||||
"modelid": "Not zigbee spec",
|
||||
"uniqueid": "00:00:00:00:00:00:00:03-00",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -62,7 +70,8 @@ async def test_cover(hass):
|
||||
assert "cover.level_controllable_cover" in gateway.deconz_ids
|
||||
assert "cover.window_covering_device" in gateway.deconz_ids
|
||||
assert "cover.unsupported_cover" not in gateway.deconz_ids
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert "cover.deconz_old_brightness_cover" in gateway.deconz_ids
|
||||
assert len(hass.states.async_all()) == 4
|
||||
|
||||
level_controllable_cover = hass.states.get("cover.level_controllable_cover")
|
||||
assert level_controllable_cover.state == "open"
|
||||
@ -105,7 +114,7 @@ async def test_cover(hass):
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
set_callback.assert_called_with(
|
||||
"put", "/lights/1/state", json={"on": True, "bri": 255}
|
||||
"put", "/lights/1/state", json={"on": True, "bri": 254}
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
@ -120,6 +129,23 @@ async def test_cover(hass):
|
||||
await hass.async_block_till_done()
|
||||
set_callback.assert_called_with("put", "/lights/1/state", json={"bri_inc": 0})
|
||||
|
||||
"""Test that a reported cover position of 255 (deconz-rest-api < 2.05.73) is interpreted correctly."""
|
||||
deconz_old_brightness_cover = hass.states.get("cover.deconz_old_brightness_cover")
|
||||
assert deconz_old_brightness_cover.state == "open"
|
||||
|
||||
state_changed_event = {
|
||||
"t": "event",
|
||||
"e": "changed",
|
||||
"r": "lights",
|
||||
"id": "4",
|
||||
"state": {"on": True},
|
||||
}
|
||||
gateway.api.event_handler(state_changed_event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
deconz_old_brightness_cover = hass.states.get("cover.deconz_old_brightness_cover")
|
||||
assert deconz_old_brightness_cover.attributes["current_position"] == 0
|
||||
|
||||
await gateway.async_reset()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user