From c4821bfa74d38a183ee21e17dd500e63423c8b28 Mon Sep 17 00:00:00 2001 From: shbatm Date: Sun, 18 Oct 2020 13:33:45 -0500 Subject: [PATCH] Improve ISY994 NodeServer sorting and format sensor display values (#42050) --- homeassistant/components/isy994/__init__.py | 3 +++ homeassistant/components/isy994/const.py | 5 +++-- homeassistant/components/isy994/sensor.py | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/isy994/__init__.py b/homeassistant/components/isy994/__init__.py index a2d3da6ed42..9fd844521d7 100644 --- a/homeassistant/components/isy994/__init__.py +++ b/homeassistant/components/isy994/__init__.py @@ -162,6 +162,9 @@ async def async_setup_entry( if not isy.connected: return False + # Trigger a status update for all nodes, not done automatically in PyISY v2.x + await hass.async_add_executor_job(isy.nodes.update) + _categorize_nodes(hass_isy_data, isy.nodes, ignore_identifier, sensor_identifier) _categorize_programs(hass_isy_data, isy.programs) _categorize_variables(hass_isy_data, isy.variables, variable_identifier) diff --git a/homeassistant/components/isy994/const.py b/homeassistant/components/isy994/const.py index e003a52c91f..3b129776b31 100644 --- a/homeassistant/components/isy994/const.py +++ b/homeassistant/components/isy994/const.py @@ -200,7 +200,7 @@ UOM_ON_OFF = "2" # Z-Wave Categories: https://www.universal-devices.com/developers/wsdk/5.0.4/4_fam.xml NODE_FILTERS = { BINARY_SENSOR: { - FILTER_UOM: [], + FILTER_UOM: [UOM_ON_OFF], FILTER_STATES: [], FILTER_NODE_DEF_ID: [ "BinaryAlarm", @@ -282,7 +282,7 @@ NODE_FILTERS = { FILTER_ZWAVE_CAT: ["109", "119"], }, SWITCH: { - FILTER_UOM: [UOM_ON_OFF, "78"], + FILTER_UOM: ["78"], FILTER_STATES: ["on", "off"], FILTER_NODE_DEF_ID: [ "AlertModuleArmed", @@ -322,6 +322,7 @@ NODE_FILTERS = { UOM_FRIENDLY_NAME = { "1": "A", + UOM_ON_OFF: "", # Binary, no unit "3": f"btu/{TIME_HOURS}", "4": TEMP_CELSIUS, "5": LENGTH_CENTIMETERS, diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index 331037fbb3c..d3d192b1b3b 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -15,6 +15,8 @@ from .const import ( ISY994_VARIABLES, UOM_DOUBLE_TEMP, UOM_FRIENDLY_NAME, + UOM_INDEX, + UOM_ON_OFF, UOM_TO_STATES, ) from .entity import ISYEntity, ISYNodeEntity @@ -58,6 +60,9 @@ class ISYSensorEntity(ISYNodeEntity): if isy_states: return isy_states + if uom in [UOM_ON_OFF, UOM_INDEX]: + return uom + return UOM_FRIENDLY_NAME.get(uom) @property @@ -74,6 +79,9 @@ class ISYSensorEntity(ISYNodeEntity): if isinstance(uom, dict): return uom.get(value, value) + if uom in [UOM_INDEX, UOM_ON_OFF]: + return self._node.formatted + # Handle ISY precision and rounding value = convert_isy_value_to_hass(value, uom, self._node.prec) @@ -88,7 +96,7 @@ class ISYSensorEntity(ISYNodeEntity): """Get the Home Assistant unit of measurement for the device.""" raw_units = self.raw_unit_of_measurement # Check if this is a known index pair UOM - if isinstance(raw_units, dict): + if isinstance(raw_units, dict) or raw_units in [UOM_ON_OFF, UOM_INDEX]: return None if raw_units in (TEMP_FAHRENHEIT, TEMP_CELSIUS, UOM_DOUBLE_TEMP): return self.hass.config.units.temperature_unit