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,6 +10,13 @@ from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||||
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
|
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_REAUTH
|
from homeassistant.config_entries import SOURCE_REAUTH
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
ATTR_CONNECTIONS,
|
||||||
|
ATTR_IDENTIFIERS,
|
||||||
|
ATTR_MANUFACTURER,
|
||||||
|
ATTR_MODEL,
|
||||||
|
ATTR_NAME,
|
||||||
|
ATTR_SUGGESTED_AREA,
|
||||||
|
ATTR_SW_VERSION,
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PROTOCOL,
|
CONF_PROTOCOL,
|
||||||
|
@ -322,25 +329,27 @@ class AppleTVManager:
|
||||||
|
|
||||||
async def _async_setup_device_registry(self):
|
async def _async_setup_device_registry(self):
|
||||||
attrs = {
|
attrs = {
|
||||||
"identifiers": {(DOMAIN, self.config_entry.unique_id)},
|
ATTR_IDENTIFIERS: {(DOMAIN, self.config_entry.unique_id)},
|
||||||
"manufacturer": "Apple",
|
ATTR_MANUFACTURER: "Apple",
|
||||||
"name": self.config_entry.data[CONF_NAME],
|
ATTR_NAME: self.config_entry.data[CONF_NAME],
|
||||||
}
|
}
|
||||||
|
|
||||||
area = attrs["name"]
|
area = attrs[ATTR_NAME]
|
||||||
name_trailer = f" {DEFAULT_NAME}"
|
name_trailer = f" {DEFAULT_NAME}"
|
||||||
if area.endswith(name_trailer):
|
if area.endswith(name_trailer):
|
||||||
area = area[: -len(name_trailer)]
|
area = area[: -len(name_trailer)]
|
||||||
attrs["suggested_area"] = area
|
attrs[ATTR_SUGGESTED_AREA] = area
|
||||||
|
|
||||||
if self.atv:
|
if self.atv:
|
||||||
dev_info = self.atv.device_info
|
dev_info = self.atv.device_info
|
||||||
|
|
||||||
attrs["model"] = DEFAULT_NAME + " " + dev_info.model.name.replace("Gen", "")
|
attrs[ATTR_MODEL] = (
|
||||||
attrs["sw_version"] = dev_info.version
|
DEFAULT_NAME + " " + dev_info.model.name.replace("Gen", "")
|
||||||
|
)
|
||||||
|
attrs[ATTR_SW_VERSION] = dev_info.version
|
||||||
|
|
||||||
if dev_info.mac:
|
if dev_info.mac:
|
||||||
attrs["connections"] = {(dr.CONNECTION_NETWORK_MAC, dev_info.mac)}
|
attrs[ATTR_CONNECTIONS] = {(dr.CONNECTION_NETWORK_MAC, dev_info.mac)}
|
||||||
|
|
||||||
device_registry = await dr.async_get_registry(self.hass)
|
device_registry = await dr.async_get_registry(self.hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
|
|
|
@ -10,7 +10,13 @@ from typing import Any
|
||||||
from aiohttp import ClientError
|
from aiohttp import ClientError
|
||||||
from bond_api import BPUPSubscriptions
|
from bond_api import BPUPSubscriptions
|
||||||
|
|
||||||
from homeassistant.const import ATTR_MODEL, ATTR_NAME, ATTR_SW_VERSION, ATTR_VIA_DEVICE
|
from homeassistant.const import (
|
||||||
|
ATTR_MODEL,
|
||||||
|
ATTR_NAME,
|
||||||
|
ATTR_SUGGESTED_AREA,
|
||||||
|
ATTR_SW_VERSION,
|
||||||
|
ATTR_VIA_DEVICE,
|
||||||
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
|
@ -65,7 +71,7 @@ class BondEntity(Entity):
|
||||||
if self._hub.bond_id is not None:
|
if self._hub.bond_id is not None:
|
||||||
device_info[ATTR_VIA_DEVICE] = (DOMAIN, self._hub.bond_id)
|
device_info[ATTR_VIA_DEVICE] = (DOMAIN, self._hub.bond_id)
|
||||||
if self._device.location is not None:
|
if self._device.location is not None:
|
||||||
device_info["suggested_area"] = self._device.location
|
device_info[ATTR_SUGGESTED_AREA] = self._device.location
|
||||||
if not self._hub.is_bridge:
|
if not self._hub.is_bridge:
|
||||||
if self._hub.model is not None:
|
if self._hub.model is not None:
|
||||||
device_info[ATTR_MODEL] = self._hub.model
|
device_info[ATTR_MODEL] = self._hub.model
|
||||||
|
|
|
@ -10,10 +10,18 @@ from pyisy.constants import (
|
||||||
)
|
)
|
||||||
from pyisy.helpers import NodeProperty
|
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.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
@ -63,7 +71,7 @@ class ISYEntity(Entity):
|
||||||
self.hass.bus.fire("isy994_control", event_data)
|
self.hass.bus.fire("isy994_control", event_data)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device_info of the device."""
|
"""Return the device_info of the device."""
|
||||||
if hasattr(self._node, "protocol") and self._node.protocol == PROTO_GROUP:
|
if hasattr(self._node, "protocol") and self._node.protocol == PROTO_GROUP:
|
||||||
# not a device
|
# not a device
|
||||||
|
@ -77,36 +85,36 @@ class ISYEntity(Entity):
|
||||||
node = self._node.parent_node
|
node = self._node.parent_node
|
||||||
basename = node.name
|
basename = node.name
|
||||||
|
|
||||||
device_info = {
|
device_info = DeviceInfo(
|
||||||
"name": basename,
|
identifiers={},
|
||||||
"identifiers": {},
|
manufacturer="Unknown",
|
||||||
"model": "Unknown",
|
model="Unknown",
|
||||||
"manufacturer": "Unknown",
|
name=basename,
|
||||||
"via_device": (DOMAIN, uuid),
|
via_device=(DOMAIN, uuid),
|
||||||
}
|
)
|
||||||
|
|
||||||
if hasattr(node, "address"):
|
if hasattr(node, "address"):
|
||||||
device_info["name"] += f" ({node.address})"
|
device_info[ATTR_NAME] += f" ({node.address})"
|
||||||
if hasattr(node, "primary_node"):
|
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
|
# ISYv5 Device Types
|
||||||
if hasattr(node, "node_def_id") and node.node_def_id is not None:
|
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
|
# Numerical Device Type
|
||||||
if hasattr(node, "type") and node.type is not None:
|
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"):
|
if hasattr(node, "protocol"):
|
||||||
device_info["manufacturer"] = node.protocol
|
device_info[ATTR_MANUFACTURER] = node.protocol
|
||||||
if node.protocol == PROTO_ZWAVE:
|
if node.protocol == PROTO_ZWAVE:
|
||||||
# Get extra information for Z-Wave Devices
|
# Get extra information for Z-Wave Devices
|
||||||
device_info["manufacturer"] += f" MfrID:{node.zwave_props.mfr_id}"
|
device_info[ATTR_MANUFACTURER] += f" MfrID:{node.zwave_props.mfr_id}"
|
||||||
device_info["model"] += (
|
device_info[ATTR_MODEL] += (
|
||||||
f" Type:{node.zwave_props.devtype_gen} "
|
f" Type:{node.zwave_props.devtype_gen} "
|
||||||
f"ProductTypeID:{node.zwave_props.prod_type_id} "
|
f"ProductTypeID:{node.zwave_props.prod_type_id} "
|
||||||
f"ProductID:{node.zwave_props.product_id}"
|
f"ProductID:{node.zwave_props.product_id}"
|
||||||
)
|
)
|
||||||
if hasattr(node, "folder") and node.folder is not None:
|
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.
|
# Note: sw_version is not exposed by the ISY for the individual devices.
|
||||||
|
|
||||||
return device_info
|
return device_info
|
||||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.components.climate.const import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_BATTERY_LEVEL,
|
ATTR_BATTERY_LEVEL,
|
||||||
|
ATTR_SUGGESTED_AREA,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
PRECISION_HALVES,
|
PRECISION_HALVES,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
|
@ -116,8 +117,6 @@ DEFAULT_MAX_TEMP = 30
|
||||||
NA_THERM = "NATherm1"
|
NA_THERM = "NATherm1"
|
||||||
NA_VALVE = "NRV"
|
NA_VALVE = "NRV"
|
||||||
|
|
||||||
SUGGESTED_AREA = "suggested_area"
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
@ -616,5 +615,5 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info for the thermostat."""
|
"""Return the device info for the thermostat."""
|
||||||
device_info: DeviceInfo = super().device_info
|
device_info: DeviceInfo = super().device_info
|
||||||
device_info["suggested_area"] = self._room_data["name"]
|
device_info[ATTR_SUGGESTED_AREA] = self._room_data["name"]
|
||||||
return device_info
|
return device_info
|
||||||
|
|
|
@ -15,6 +15,9 @@ from plugwise.smile import Smile
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
ATTR_CONFIGURATION_URL,
|
||||||
|
ATTR_MODEL,
|
||||||
|
ATTR_VIA_DEVICE,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
|
@ -199,13 +202,15 @@ class SmileGateway(CoordinatorEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
if entry := self.coordinator.config_entry:
|
if entry := self.coordinator.config_entry:
|
||||||
device_information["configuration_url"] = f"http://{entry.data[CONF_HOST]}"
|
device_information[
|
||||||
|
ATTR_CONFIGURATION_URL
|
||||||
|
] = f"http://{entry.data[CONF_HOST]}"
|
||||||
|
|
||||||
if self._model is not None:
|
if self._model is not None:
|
||||||
device_information["model"] = self._model.replace("_", " ").title()
|
device_information[ATTR_MODEL] = self._model.replace("_", " ").title()
|
||||||
|
|
||||||
if self._dev_id != self._api.gateway_id:
|
if self._dev_id != self._api.gateway_id:
|
||||||
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
|
device_information[ATTR_VIA_DEVICE] = (DOMAIN, self._api.gateway_id)
|
||||||
|
|
||||||
return device_information
|
return device_information
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,16 @@ from zwave_js_server.model.value import Value, ValueNotification
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
ATTR_CONFIG_ENTRY_ID,
|
||||||
ATTR_DEVICE_ID,
|
ATTR_DEVICE_ID,
|
||||||
ATTR_DOMAIN,
|
ATTR_DOMAIN,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
|
ATTR_IDENTIFIERS,
|
||||||
|
ATTR_MANUFACTURER,
|
||||||
|
ATTR_MODEL,
|
||||||
|
ATTR_NAME,
|
||||||
|
ATTR_SUGGESTED_AREA,
|
||||||
|
ATTR_SW_VERSION,
|
||||||
CONF_URL,
|
CONF_URL,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
)
|
)
|
||||||
|
@ -120,15 +127,17 @@ def register_node_in_dev_reg(
|
||||||
):
|
):
|
||||||
remove_device_func(device)
|
remove_device_func(device)
|
||||||
params = {
|
params = {
|
||||||
"config_entry_id": entry.entry_id,
|
ATTR_CONFIG_ENTRY_ID: entry.entry_id,
|
||||||
"identifiers": {device_id},
|
ATTR_IDENTIFIERS: {device_id},
|
||||||
"sw_version": node.firmware_version,
|
ATTR_SW_VERSION: node.firmware_version,
|
||||||
"name": node.name or node.device_config.description or f"Node {node.node_id}",
|
ATTR_NAME: node.name
|
||||||
"model": node.device_config.label,
|
or node.device_config.description
|
||||||
"manufacturer": node.device_config.manufacturer,
|
or f"Node {node.node_id}",
|
||||||
|
ATTR_MODEL: node.device_config.label,
|
||||||
|
ATTR_MANUFACTURER: node.device_config.manufacturer,
|
||||||
}
|
}
|
||||||
if node.location:
|
if node.location:
|
||||||
params["suggested_area"] = node.location
|
params[ATTR_SUGGESTED_AREA] = node.location
|
||||||
device = dev_reg.async_get_or_create(**params)
|
device = dev_reg.async_get_or_create(**params)
|
||||||
|
|
||||||
async_dispatcher_send(hass, EVENT_DEVICE_ADDED_TO_REGISTRY, device)
|
async_dispatcher_send(hass, EVENT_DEVICE_ADDED_TO_REGISTRY, device)
|
||||||
|
|
|
@ -352,8 +352,12 @@ ATTR_LOCATION: Final = "location"
|
||||||
|
|
||||||
ATTR_MODE: Final = "mode"
|
ATTR_MODE: Final = "mode"
|
||||||
|
|
||||||
|
ATTR_CONFIG_ENTRY_ID: Final = "config_entry_id"
|
||||||
|
ATTR_CONFIGURATION_URL: Final = "configuration_url"
|
||||||
|
ATTR_CONNECTIONS: Final = "connections"
|
||||||
ATTR_MANUFACTURER: Final = "manufacturer"
|
ATTR_MANUFACTURER: Final = "manufacturer"
|
||||||
ATTR_MODEL: Final = "model"
|
ATTR_MODEL: Final = "model"
|
||||||
|
ATTR_SUGGESTED_AREA: Final = "suggested_area"
|
||||||
ATTR_SW_VERSION: Final = "sw_version"
|
ATTR_SW_VERSION: Final = "sw_version"
|
||||||
ATTR_VIA_DEVICE: Final = "via_device"
|
ATTR_VIA_DEVICE: Final = "via_device"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue