deCONZ normalizes cover values to follow zigbee spec (#26240)
parent
1e61d50fc5
commit
d156648c55
|
@ -14,8 +14,6 @@ from .const import COVER_TYPES, DAMPERS, NEW_LIGHT, WINDOW_COVERS
|
||||||
from .deconz_device import DeconzDevice
|
from .deconz_device import DeconzDevice
|
||||||
from .gateway import get_gateway_from_config_entry
|
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):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Old way of setting up deCONZ platforms."""
|
"""Old way of setting up deCONZ platforms."""
|
||||||
|
@ -35,13 +33,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
for light in lights:
|
for light in lights:
|
||||||
|
|
||||||
if light.type in COVER_TYPES:
|
if light.type in COVER_TYPES:
|
||||||
if light.modelid in ZIGBEE_SPEC:
|
entities.append(DeconzCover(light, gateway))
|
||||||
entities.append(DeconzCoverZigbeeSpec(light, gateway))
|
|
||||||
|
|
||||||
else:
|
|
||||||
entities.append(DeconzCover(light, gateway))
|
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
@ -69,14 +62,12 @@ class DeconzCover(DeconzDevice, CoverDevice):
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self):
|
def current_cover_position(self):
|
||||||
"""Return the current position of the cover."""
|
"""Return the current position of the cover."""
|
||||||
if self.is_closed:
|
return 100 - int(self._device.brightness / 255 * 100)
|
||||||
return 0
|
|
||||||
return int(self._device.brightness / 255 * 100)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_closed(self):
|
def is_closed(self):
|
||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
return not self._device.state
|
return self._device.state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
|
@ -96,9 +87,9 @@ class DeconzCover(DeconzDevice, CoverDevice):
|
||||||
position = kwargs[ATTR_POSITION]
|
position = kwargs[ATTR_POSITION]
|
||||||
data = {"on": False}
|
data = {"on": False}
|
||||||
|
|
||||||
if position > 0:
|
if position < 100:
|
||||||
data["on"] = True
|
data["on"] = True
|
||||||
data["bri"] = int(position / 100 * 255)
|
data["bri"] = 255 - int(position / 100 * 255)
|
||||||
|
|
||||||
await self._device.async_set_state(data)
|
await self._device.async_set_state(data)
|
||||||
|
|
||||||
|
@ -116,28 +107,3 @@ class DeconzCover(DeconzDevice, CoverDevice):
|
||||||
"""Stop cover."""
|
"""Stop cover."""
|
||||||
data = {"bri_inc": 0}
|
data = {"bri_inc": 0}
|
||||||
await self._device.async_set_state(data)
|
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)
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ SUPPORTED_COVERS = {
|
||||||
"id": "Cover 1 id",
|
"id": "Cover 1 id",
|
||||||
"name": "Cover 1 name",
|
"name": "Cover 1 name",
|
||||||
"type": "Level controllable output",
|
"type": "Level controllable output",
|
||||||
"state": {"bri": 255, "reachable": True},
|
"state": {"bri": 255, "on": False, "reachable": True},
|
||||||
"modelid": "Not zigbee spec",
|
"modelid": "Not zigbee spec",
|
||||||
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
},
|
},
|
||||||
|
@ -24,7 +24,7 @@ SUPPORTED_COVERS = {
|
||||||
"id": "Cover 2 id",
|
"id": "Cover 2 id",
|
||||||
"name": "Cover 2 name",
|
"name": "Cover 2 name",
|
||||||
"type": "Window covering device",
|
"type": "Window covering device",
|
||||||
"state": {"bri": 255, "reachable": True},
|
"state": {"bri": 255, "on": True, "reachable": True},
|
||||||
"modelid": "lumi.curtain",
|
"modelid": "lumi.curtain",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ async def test_cover(hass):
|
||||||
|
|
||||||
cover_1 = hass.states.get("cover.cover_1_name")
|
cover_1 = hass.states.get("cover.cover_1_name")
|
||||||
assert cover_1 is not None
|
assert cover_1 is not None
|
||||||
assert cover_1.state == "closed"
|
assert cover_1.state == "open"
|
||||||
|
|
||||||
gateway.api.lights["1"].async_update({})
|
gateway.api.lights["1"].async_update({})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue