diff --git a/homeassistant/components/isy994/const.py b/homeassistant/components/isy994/const.py index 3b129776b31..30059c68c10 100644 --- a/homeassistant/components/isy994/const.py +++ b/homeassistant/components/isy994/const.py @@ -193,6 +193,7 @@ UOM_HVAC_MODE_INSTEON = "98" UOM_FAN_MODES = "99" UOM_INDEX = "25" UOM_ON_OFF = "2" +UOM_PERCENTAGE = "51" # Do not use the Home Assistant consts for the states here - we're matching exact API # responses, not using them for Home Assistant states @@ -369,7 +370,7 @@ UOM_FRIENDLY_NAME = { "48": SPEED_MILES_PER_HOUR, "49": SPEED_METERS_PER_SECOND, "50": "Ω", - "51": PERCENTAGE, + UOM_PERCENTAGE: PERCENTAGE, "52": MASS_POUNDS, "53": "pf", "54": CONCENTRATION_PARTS_PER_MILLION, diff --git a/homeassistant/components/isy994/cover.py b/homeassistant/components/isy994/cover.py index 51a26585778..bdc2bc7f6d4 100644 --- a/homeassistant/components/isy994/cover.py +++ b/homeassistant/components/isy994/cover.py @@ -53,7 +53,7 @@ class ISYCoverEntity(ISYNodeEntity, CoverEntity): if self._node.status == ISY_VALUE_UNKNOWN: return None 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] @property @@ -83,7 +83,7 @@ class ISYCoverEntity(ISYNodeEntity, CoverEntity): """Move the cover to a specific position.""" position = kwargs[ATTR_POSITION] 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): _LOGGER.error("Unable to set cover position") diff --git a/homeassistant/components/isy994/light.py b/homeassistant/components/isy994/light.py index 7f94c68714d..7ff44863f6b 100644 --- a/homeassistant/components/isy994/light.py +++ b/homeassistant/components/isy994/light.py @@ -17,6 +17,7 @@ from .const import ( CONF_RESTORE_LIGHT_STATE, DOMAIN as ISY994_DOMAIN, ISY994_NODES, + UOM_PERCENTAGE, ) from .entity import ISYNodeEntity from .helpers import migrate_old_unique_ids @@ -65,6 +66,9 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity): """Get the brightness of the ISY994 light.""" if self._node.status == ISY_VALUE_UNKNOWN: 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) def turn_off(self, **kwargs) -> None: @@ -76,7 +80,10 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity): def on_update(self, event: object) -> None: """Save brightness in the update event from the ISY994 Node.""" 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) # pylint: disable=arguments-differ @@ -84,6 +91,9 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity): """Send the turn on command to the ISY994 light device.""" if self._restore_light_state and brightness is None and 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): _LOGGER.debug("Unable to turn on light")