mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Fix dimming for ISY994 Z-Wave devices using percent instead of 8-bit brightness values (#42915)
This commit is contained in:
parent
bf9f3e1997
commit
121872c546
@ -193,6 +193,7 @@ UOM_HVAC_MODE_INSTEON = "98"
|
|||||||
UOM_FAN_MODES = "99"
|
UOM_FAN_MODES = "99"
|
||||||
UOM_INDEX = "25"
|
UOM_INDEX = "25"
|
||||||
UOM_ON_OFF = "2"
|
UOM_ON_OFF = "2"
|
||||||
|
UOM_PERCENTAGE = "51"
|
||||||
|
|
||||||
# Do not use the Home Assistant consts for the states here - we're matching exact API
|
# Do not use the Home Assistant consts for the states here - we're matching exact API
|
||||||
# responses, not using them for Home Assistant states
|
# responses, not using them for Home Assistant states
|
||||||
@ -369,7 +370,7 @@ UOM_FRIENDLY_NAME = {
|
|||||||
"48": SPEED_MILES_PER_HOUR,
|
"48": SPEED_MILES_PER_HOUR,
|
||||||
"49": SPEED_METERS_PER_SECOND,
|
"49": SPEED_METERS_PER_SECOND,
|
||||||
"50": "Ω",
|
"50": "Ω",
|
||||||
"51": PERCENTAGE,
|
UOM_PERCENTAGE: PERCENTAGE,
|
||||||
"52": MASS_POUNDS,
|
"52": MASS_POUNDS,
|
||||||
"53": "pf",
|
"53": "pf",
|
||||||
"54": CONCENTRATION_PARTS_PER_MILLION,
|
"54": CONCENTRATION_PARTS_PER_MILLION,
|
||||||
|
@ -53,7 +53,7 @@ class ISYCoverEntity(ISYNodeEntity, CoverEntity):
|
|||||||
if self._node.status == ISY_VALUE_UNKNOWN:
|
if self._node.status == ISY_VALUE_UNKNOWN:
|
||||||
return None
|
return None
|
||||||
if self._node.uom == UOM_8_BIT_RANGE:
|
if self._node.uom == UOM_8_BIT_RANGE:
|
||||||
return int(self._node.status * 100 / 255)
|
return round(self._node.status * 100.0 / 255.0)
|
||||||
return sorted((0, self._node.status, 100))[1]
|
return sorted((0, self._node.status, 100))[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -83,7 +83,7 @@ class ISYCoverEntity(ISYNodeEntity, CoverEntity):
|
|||||||
"""Move the cover to a specific position."""
|
"""Move the cover to a specific position."""
|
||||||
position = kwargs[ATTR_POSITION]
|
position = kwargs[ATTR_POSITION]
|
||||||
if self._node.uom == UOM_8_BIT_RANGE:
|
if self._node.uom == UOM_8_BIT_RANGE:
|
||||||
position = int(position * 255 / 100)
|
position = round(position * 255.0 / 100.0)
|
||||||
if not self._node.turn_on(val=position):
|
if not self._node.turn_on(val=position):
|
||||||
_LOGGER.error("Unable to set cover position")
|
_LOGGER.error("Unable to set cover position")
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from .const import (
|
|||||||
CONF_RESTORE_LIGHT_STATE,
|
CONF_RESTORE_LIGHT_STATE,
|
||||||
DOMAIN as ISY994_DOMAIN,
|
DOMAIN as ISY994_DOMAIN,
|
||||||
ISY994_NODES,
|
ISY994_NODES,
|
||||||
|
UOM_PERCENTAGE,
|
||||||
)
|
)
|
||||||
from .entity import ISYNodeEntity
|
from .entity import ISYNodeEntity
|
||||||
from .helpers import migrate_old_unique_ids
|
from .helpers import migrate_old_unique_ids
|
||||||
@ -65,6 +66,9 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
|
|||||||
"""Get the brightness of the ISY994 light."""
|
"""Get the brightness of the ISY994 light."""
|
||||||
if self._node.status == ISY_VALUE_UNKNOWN:
|
if self._node.status == ISY_VALUE_UNKNOWN:
|
||||||
return None
|
return None
|
||||||
|
# Special Case for ISY Z-Wave Devices using % instead of 0-255:
|
||||||
|
if self._node.uom == UOM_PERCENTAGE:
|
||||||
|
return round(self._node.status * 255.0 / 100.0)
|
||||||
return int(self._node.status)
|
return int(self._node.status)
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs) -> None:
|
||||||
@ -76,7 +80,10 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
|
|||||||
def on_update(self, event: object) -> None:
|
def on_update(self, event: object) -> None:
|
||||||
"""Save brightness in the update event from the ISY994 Node."""
|
"""Save brightness in the update event from the ISY994 Node."""
|
||||||
if self._node.status not in (0, ISY_VALUE_UNKNOWN):
|
if self._node.status not in (0, ISY_VALUE_UNKNOWN):
|
||||||
self._last_brightness = self._node.status
|
if self._node.uom == UOM_PERCENTAGE:
|
||||||
|
self._last_brightness = round(self._node.status * 255.0 / 100.0)
|
||||||
|
else:
|
||||||
|
self._last_brightness = self._node.status
|
||||||
super().on_update(event)
|
super().on_update(event)
|
||||||
|
|
||||||
# pylint: disable=arguments-differ
|
# pylint: disable=arguments-differ
|
||||||
@ -84,6 +91,9 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
|
|||||||
"""Send the turn on command to the ISY994 light device."""
|
"""Send the turn on command to the ISY994 light device."""
|
||||||
if self._restore_light_state and brightness is None and self._last_brightness:
|
if self._restore_light_state and brightness is None and self._last_brightness:
|
||||||
brightness = self._last_brightness
|
brightness = self._last_brightness
|
||||||
|
# Special Case for ISY Z-Wave Devices using % instead of 0-255:
|
||||||
|
if brightness is not None and self._node.uom == UOM_PERCENTAGE:
|
||||||
|
brightness = round(brightness * 100.0 / 255.0)
|
||||||
if not self._node.turn_on(val=brightness):
|
if not self._node.turn_on(val=brightness):
|
||||||
_LOGGER.debug("Unable to turn on light")
|
_LOGGER.debug("Unable to turn on light")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user