Add new attribute constants for DeviceInfo registration (#58289)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
380cff167e
commit
9ae7f0ecd7
7 changed files with 81 additions and 41 deletions
|
@ -10,10 +10,18 @@ from pyisy.constants import (
|
|||
)
|
||||
from pyisy.helpers import NodeProperty
|
||||
|
||||
from homeassistant.const import STATE_OFF, STATE_ON
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_SUGGESTED_AREA,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
@ -63,7 +71,7 @@ class ISYEntity(Entity):
|
|||
self.hass.bus.fire("isy994_control", event_data)
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device_info of the device."""
|
||||
if hasattr(self._node, "protocol") and self._node.protocol == PROTO_GROUP:
|
||||
# not a device
|
||||
|
@ -77,36 +85,36 @@ class ISYEntity(Entity):
|
|||
node = self._node.parent_node
|
||||
basename = node.name
|
||||
|
||||
device_info = {
|
||||
"name": basename,
|
||||
"identifiers": {},
|
||||
"model": "Unknown",
|
||||
"manufacturer": "Unknown",
|
||||
"via_device": (DOMAIN, uuid),
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={},
|
||||
manufacturer="Unknown",
|
||||
model="Unknown",
|
||||
name=basename,
|
||||
via_device=(DOMAIN, uuid),
|
||||
)
|
||||
|
||||
if hasattr(node, "address"):
|
||||
device_info["name"] += f" ({node.address})"
|
||||
device_info[ATTR_NAME] += f" ({node.address})"
|
||||
if hasattr(node, "primary_node"):
|
||||
device_info["identifiers"] = {(DOMAIN, f"{uuid}_{node.address}")}
|
||||
device_info[ATTR_IDENTIFIERS] = {(DOMAIN, f"{uuid}_{node.address}")}
|
||||
# ISYv5 Device Types
|
||||
if hasattr(node, "node_def_id") and node.node_def_id is not None:
|
||||
device_info["model"] = node.node_def_id
|
||||
device_info[ATTR_MODEL] = node.node_def_id
|
||||
# Numerical Device Type
|
||||
if hasattr(node, "type") and node.type is not None:
|
||||
device_info["model"] += f" {node.type}"
|
||||
device_info[ATTR_MODEL] += f" {node.type}"
|
||||
if hasattr(node, "protocol"):
|
||||
device_info["manufacturer"] = node.protocol
|
||||
device_info[ATTR_MANUFACTURER] = node.protocol
|
||||
if node.protocol == PROTO_ZWAVE:
|
||||
# Get extra information for Z-Wave Devices
|
||||
device_info["manufacturer"] += f" MfrID:{node.zwave_props.mfr_id}"
|
||||
device_info["model"] += (
|
||||
device_info[ATTR_MANUFACTURER] += f" MfrID:{node.zwave_props.mfr_id}"
|
||||
device_info[ATTR_MODEL] += (
|
||||
f" Type:{node.zwave_props.devtype_gen} "
|
||||
f"ProductTypeID:{node.zwave_props.prod_type_id} "
|
||||
f"ProductID:{node.zwave_props.product_id}"
|
||||
)
|
||||
if hasattr(node, "folder") and node.folder is not None:
|
||||
device_info["suggested_area"] = node.folder
|
||||
device_info[ATTR_SUGGESTED_AREA] = node.folder
|
||||
# Note: sw_version is not exposed by the ISY for the individual devices.
|
||||
|
||||
return device_info
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue