Skip to content

Commit

Permalink
Fix sensors overwriting device class and bump PyISYoX to fix NLS issu…
Browse files Browse the repository at this point in the history
…es (#109)
  • Loading branch information
shbatm authored Jul 6, 2023
1 parent 3294341 commit fbd5656
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions custom_components/isy994/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"iot_class": "local_push",
"issue_tracker": "http://github.com/shbatm/hacs-isy994/issues",
"loggers": ["pyisyox"],
"requirements": ["pyisyox==1.0.0a9"],
"requirements": ["pyisyox==1.0.0a10"],
"ssdp": [
{
"deviceType": "urn:udi-com:device:X_Insteon_Lighting_Device:1",
"manufacturer": "Universal Devices Inc."
}
],
"version": "4.0.15"
"version": "4.0.16"
}
29 changes: 18 additions & 11 deletions custom_components/isy994/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,31 @@ async def async_setup_entry(

def get_native_uom(
uom: str | list, node: Node, control: str = PROP_STATUS
) -> tuple[str | None, dict[int, str] | None]:
"""Get the native UoM and Options Dict for the ISY sensor device."""
) -> tuple[str | None, dict[int, str] | None, bool]:
"""Get the native UoM and Options Dict for the ISY sensor device.
Returns a tuple of the Native UOM, the Options List if it exists,
and whether or not the UOM is enumerated.
"""
# Backwards compatibility for ISYv4 Firmware:
if isinstance(uom, list):
return (UOM_FRIENDLY_NAME.get(uom[0], uom[0]), None)
return (UOM_FRIENDLY_NAME.get(uom[0], uom[0]), None, False)
# Special cases for ISY UOM index units:
if isy_states := UOM_TO_STATES.get(uom):
return (None, isy_states)
return (None, isy_states, True)
if (
uom == UOM_INDEX
and (node_def := node.get_node_def()) is not None
and (editor := node_def.status_editors.get(control))
):
return (None, editor.values)
return (None, editor.values, True)
# Handle on/off or unlisted index types
if uom in (UOM_ON_OFF, UOM_INDEX):
return (None, None)
return (None, None, True)
# Assume double-temp matches current Hass unit (no way to confirm)
if uom == UOM_DOUBLE_TEMP:
return (hass.config.units.temperature_unit, None)
return (UOM_FRIENDLY_NAME.get(uom), None)
return (hass.config.units.temperature_unit, None, False)
return (UOM_FRIENDLY_NAME.get(uom), None, False)

for node, control in entity_list:
_LOGGER.debug("Loading %s %s", node.name, COMMAND_FRIENDLY_NAME.get(control))
Expand All @@ -160,11 +164,14 @@ def get_native_uom(
options_dict = None

if (prop := node.aux_properties.get(control)) is not None:
if prop.uom in (UOM_ON_OFF, UOM_INDEX):
# Lookup native units and options list if it has one
native_uom, options_dict, is_enum = get_native_uom(prop.uom, node, control)

if is_enum:
# This is an ISY Enum-type Sensor with an Options List, force Enum Class
device_class = SensorDeviceClass.ENUM
state_class = None
native_uom, options_dict = get_native_uom(prop.uom, node, control)
if native_uom is None and device_class != SensorDeviceClass.ENUM:
elif native_uom is None:
# Unknown UOMs will cause errors with device classes expecting numeric values
# they will use the ISY formatted value and may or may not have a unit embedded.
# this should only apply for new UoM that have not been added to PyISYOX yet.
Expand Down

0 comments on commit fbd5656

Please sign in to comment.