deCONZ normalizes cover values to follow zigbee spec (#26240)

pull/26254/head
Robert Svensson 2019-08-27 21:06:14 +02:00 committed by Paulus Schoutsen
parent 1e61d50fc5
commit d156648c55
2 changed files with 8 additions and 42 deletions

View File

@ -14,8 +14,6 @@ from .const import COVER_TYPES, DAMPERS, NEW_LIGHT, WINDOW_COVERS
from .deconz_device import DeconzDevice
from .gateway import get_gateway_from_config_entry
ZIGBEE_SPEC = ["lumi.curtain"]
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Old way of setting up deCONZ platforms."""
@ -35,13 +33,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities = []
for light in lights:
if light.type in COVER_TYPES:
if light.modelid in ZIGBEE_SPEC:
entities.append(DeconzCoverZigbeeSpec(light, gateway))
else:
entities.append(DeconzCover(light, gateway))
entities.append(DeconzCover(light, gateway))
async_add_entities(entities, True)
@ -69,14 +62,12 @@ class DeconzCover(DeconzDevice, CoverDevice):
@property
def current_cover_position(self):
"""Return the current position of the cover."""
if self.is_closed:
return 0
return int(self._device.brightness / 255 * 100)
return 100 - int(self._device.brightness / 255 * 100)
@property
def is_closed(self):
"""Return if the cover is closed."""
return not self._device.state
return self._device.state
@property
def device_class(self):
@ -96,9 +87,9 @@ class DeconzCover(DeconzDevice, CoverDevice):
position = kwargs[ATTR_POSITION]
data = {"on": False}
if position > 0:
if position < 100:
data["on"] = True
data["bri"] = int(position / 100 * 255)
data["bri"] = 255 - int(position / 100 * 255)
await self._device.async_set_state(data)
@ -116,28 +107,3 @@ class DeconzCover(DeconzDevice, CoverDevice):
"""Stop cover."""
data = {"bri_inc": 0}
await self._device.async_set_state(data)
class DeconzCoverZigbeeSpec(DeconzCover):
"""Zigbee spec is the inverse of how deCONZ normally reports attributes."""
@property
def current_cover_position(self):
"""Return the current position of the cover."""
return 100 - int(self._device.brightness / 255 * 100)
@property
def is_closed(self):
"""Return if the cover is closed."""
return self._device.state
async def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
position = kwargs[ATTR_POSITION]
data = {"on": False}
if position < 100:
data["on"] = True
data["bri"] = 255 - int(position / 100 * 255)
await self._device.async_set_state(data)

View File

@ -16,7 +16,7 @@ SUPPORTED_COVERS = {
"id": "Cover 1 id",
"name": "Cover 1 name",
"type": "Level controllable output",
"state": {"bri": 255, "reachable": True},
"state": {"bri": 255, "on": False, "reachable": True},
"modelid": "Not zigbee spec",
"uniqueid": "00:00:00:00:00:00:00:00-00",
},
@ -24,7 +24,7 @@ SUPPORTED_COVERS = {
"id": "Cover 2 id",
"name": "Cover 2 name",
"type": "Window covering device",
"state": {"bri": 255, "reachable": True},
"state": {"bri": 255, "on": True, "reachable": True},
"modelid": "lumi.curtain",
},
}
@ -107,7 +107,7 @@ async def test_cover(hass):
cover_1 = hass.states.get("cover.cover_1_name")
assert cover_1 is not None
assert cover_1.state == "closed"
assert cover_1.state == "open"
gateway.api.lights["1"].async_update({})