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:
Knapoc 2020-03-16 15:44:59 +01:00 committed by GitHub
parent 8d68f34650
commit 7ec7306ea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View File

@ -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)

View File

@ -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