mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Assign ISY994 program entities to hub device, simplify device info (#85224)
This commit is contained in:
parent
11df364b10
commit
ef759e9c63
@ -15,15 +15,7 @@ from pyisy.helpers import EventListener, NodeProperty
|
|||||||
from pyisy.nodes import Node
|
from pyisy.nodes import Node
|
||||||
from pyisy.programs import Program
|
from pyisy.programs import Program
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, STATE_OFF, STATE_ON
|
||||||
ATTR_IDENTIFIERS,
|
|
||||||
ATTR_MANUFACTURER,
|
|
||||||
ATTR_MODEL,
|
|
||||||
ATTR_NAME,
|
|
||||||
ATTR_SUGGESTED_AREA,
|
|
||||||
STATE_OFF,
|
|
||||||
STATE_ON,
|
|
||||||
)
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||||
@ -87,57 +79,47 @@ class ISYEntity(Entity):
|
|||||||
|
|
||||||
basename = self._name or str(self._node.name)
|
basename = self._name or str(self._node.name)
|
||||||
|
|
||||||
if hasattr(node, "protocol") and node.protocol == PROTO_GROUP:
|
if node.protocol == PROTO_GROUP and len(node.controllers) == 1:
|
||||||
# If Group has only 1 Controller, link to that device, otherwise link to ISY Hub
|
# If Group has only 1 Controller, link to that device instead of the hub
|
||||||
if len(node.controllers) != 1:
|
|
||||||
return DeviceInfo(identifiers={(DOMAIN, uuid)})
|
|
||||||
|
|
||||||
node = isy.nodes.get_by_id(node.controllers[0])
|
node = isy.nodes.get_by_id(node.controllers[0])
|
||||||
basename = node.name
|
basename = node.name
|
||||||
|
|
||||||
if hasattr(node, "parent_node") and node.parent_node is not None:
|
if hasattr(node, "parent_node"): # Verify this is a Node class
|
||||||
# This is not the parent node, get the parent node.
|
if node.parent_node is not None:
|
||||||
node = node.parent_node
|
# This is not the parent node, get the parent node.
|
||||||
basename = node.name
|
node = node.parent_node
|
||||||
|
basename = node.name
|
||||||
|
else:
|
||||||
|
# Default to the hub device if parent node is not a physical device
|
||||||
|
return DeviceInfo(identifiers={(DOMAIN, uuid)})
|
||||||
|
|
||||||
device_info = DeviceInfo(
|
device_info = DeviceInfo(
|
||||||
manufacturer="Unknown",
|
identifiers={(DOMAIN, f"{uuid}_{node.address}")},
|
||||||
model="Unknown",
|
manufacturer=node.protocol,
|
||||||
name=basename,
|
name=f"{basename} ({(str(node.address).rpartition(' ')[0] or node.address)})",
|
||||||
via_device=(DOMAIN, uuid),
|
via_device=(DOMAIN, uuid),
|
||||||
configuration_url=url,
|
configuration_url=url,
|
||||||
|
suggested_area=node.folder,
|
||||||
)
|
)
|
||||||
|
|
||||||
if hasattr(node, "address"):
|
# ISYv5 Device Types can provide model and manufacturer
|
||||||
assert isinstance(node.address, str)
|
model: str = "Unknown"
|
||||||
device_info[
|
if node.node_def_id is not None:
|
||||||
ATTR_NAME
|
model = str(node.node_def_id)
|
||||||
] = f"{basename} ({(node.address.rpartition(' ')[0] or node.address)})"
|
|
||||||
if hasattr(node, "primary_node"):
|
# Numerical Device Type
|
||||||
device_info[ATTR_IDENTIFIERS] = {(DOMAIN, f"{uuid}_{node.address}")}
|
if node.type is not None:
|
||||||
# ISYv5 Device Types
|
model += f" ({node.type})"
|
||||||
if hasattr(node, "node_def_id") and node.node_def_id is not None:
|
|
||||||
model: str = str(node.node_def_id)
|
# Get extra information for Z-Wave Devices
|
||||||
# Numerical Device Type
|
if node.protocol == PROTO_ZWAVE:
|
||||||
if hasattr(node, "type") and node.type is not None:
|
device_info[ATTR_MANUFACTURER] = f"Z-Wave MfrID:{node.zwave_props.mfr_id}"
|
||||||
model += f" {node.type}"
|
model += (
|
||||||
device_info[ATTR_MODEL] = model
|
f" Type:{node.zwave_props.devtype_gen} "
|
||||||
if hasattr(node, "protocol"):
|
f"ProductTypeID:{node.zwave_props.prod_type_id} "
|
||||||
model = str(device_info[ATTR_MODEL])
|
f"ProductID:{node.zwave_props.product_id}"
|
||||||
manufacturer = str(node.protocol)
|
)
|
||||||
if node.protocol == PROTO_ZWAVE:
|
device_info[ATTR_MODEL] = model
|
||||||
# Get extra information for Z-Wave Devices
|
|
||||||
manufacturer += f" MfrID:{node.zwave_props.mfr_id}"
|
|
||||||
model += (
|
|
||||||
f" Type:{node.zwave_props.devtype_gen} "
|
|
||||||
f"ProductTypeID:{node.zwave_props.prod_type_id} "
|
|
||||||
f"ProductID:{node.zwave_props.product_id}"
|
|
||||||
)
|
|
||||||
device_info[ATTR_MANUFACTURER] = manufacturer
|
|
||||||
device_info[ATTR_MODEL] = model
|
|
||||||
if hasattr(node, "folder") and node.folder is not None:
|
|
||||||
device_info[ATTR_SUGGESTED_AREA] = node.folder
|
|
||||||
# Note: sw_version is not exposed by the ISY for the individual devices.
|
|
||||||
|
|
||||||
return device_info
|
return device_info
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user