Add new attribute constants for DeviceInfo registration (#58289)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/58309/head
parent
380cff167e
commit
9ae7f0ecd7
|
@ -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.config_entries import SOURCE_REAUTH
|
||||
from homeassistant.const import (
|
||||
ATTR_CONNECTIONS,
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_SUGGESTED_AREA,
|
||||
ATTR_SW_VERSION,
|
||||
CONF_ADDRESS,
|
||||
CONF_NAME,
|
||||
CONF_PROTOCOL,
|
||||
|
@ -322,25 +329,27 @@ class AppleTVManager:
|
|||
|
||||
async def _async_setup_device_registry(self):
|
||||
attrs = {
|
||||
"identifiers": {(DOMAIN, self.config_entry.unique_id)},
|
||||
"manufacturer": "Apple",
|
||||
"name": self.config_entry.data[CONF_NAME],
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, self.config_entry.unique_id)},
|
||||
ATTR_MANUFACTURER: "Apple",
|
||||
ATTR_NAME: self.config_entry.data[CONF_NAME],
|
||||
}
|
||||
|
||||
area = attrs["name"]
|
||||
area = attrs[ATTR_NAME]
|
||||
name_trailer = f" {DEFAULT_NAME}"
|
||||
if area.endswith(name_trailer):
|
||||
area = area[: -len(name_trailer)]
|
||||
attrs["suggested_area"] = area
|
||||
attrs[ATTR_SUGGESTED_AREA] = area
|
||||
|
||||
if self.atv:
|
||||
dev_info = self.atv.device_info
|
||||
|
||||
attrs["model"] = DEFAULT_NAME + " " + dev_info.model.name.replace("Gen", "")
|
||||
attrs["sw_version"] = dev_info.version
|
||||
attrs[ATTR_MODEL] = (
|
||||
DEFAULT_NAME + " " + dev_info.model.name.replace("Gen", "")
|
||||
)
|
||||
attrs[ATTR_SW_VERSION] = dev_info.version
|
||||
|
||||
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.async_get_or_create(
|
||||
|
|
|
@ -10,7 +10,13 @@ from typing import Any
|
|||
from aiohttp import ClientError
|
||||
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.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
@ -65,7 +71,7 @@ class BondEntity(Entity):
|
|||
if self._hub.bond_id is not None:
|
||||
device_info[ATTR_VIA_DEVICE] = (DOMAIN, self._hub.bond_id)
|
||||
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 self._hub.model is not None:
|
||||
device_info[ATTR_MODEL] = self._hub.model
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.components.climate.const import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
ATTR_SUGGESTED_AREA,
|
||||
ATTR_TEMPERATURE,
|
||||
PRECISION_HALVES,
|
||||
STATE_OFF,
|
||||
|
@ -116,8 +117,6 @@ DEFAULT_MAX_TEMP = 30
|
|||
NA_THERM = "NATherm1"
|
||||
NA_VALVE = "NRV"
|
||||
|
||||
SUGGESTED_AREA = "suggested_area"
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -616,5 +615,5 @@ class NetatmoThermostat(NetatmoBase, ClimateEntity):
|
|||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info for the thermostat."""
|
||||
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
|
||||
|
|
|
@ -15,6 +15,9 @@ from plugwise.smile import Smile
|
|||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_CONFIGURATION_URL,
|
||||
ATTR_MODEL,
|
||||
ATTR_VIA_DEVICE,
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
|
@ -199,13 +202,15 @@ class SmileGateway(CoordinatorEntity):
|
|||
)
|
||||
|
||||
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:
|
||||
device_information["model"] = self._model.replace("_", " ").title()
|
||||
device_information[ATTR_MODEL] = self._model.replace("_", " ").title()
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -18,9 +18,16 @@ from zwave_js_server.model.value import Value, ValueNotification
|
|||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_CONFIG_ENTRY_ID,
|
||||
ATTR_DEVICE_ID,
|
||||
ATTR_DOMAIN,
|
||||
ATTR_ENTITY_ID,
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_SUGGESTED_AREA,
|
||||
ATTR_SW_VERSION,
|
||||
CONF_URL,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
)
|
||||
|
@ -120,15 +127,17 @@ def register_node_in_dev_reg(
|
|||
):
|
||||
remove_device_func(device)
|
||||
params = {
|
||||
"config_entry_id": entry.entry_id,
|
||||
"identifiers": {device_id},
|
||||
"sw_version": node.firmware_version,
|
||||
"name": node.name or node.device_config.description or f"Node {node.node_id}",
|
||||
"model": node.device_config.label,
|
||||
"manufacturer": node.device_config.manufacturer,
|
||||
ATTR_CONFIG_ENTRY_ID: entry.entry_id,
|
||||
ATTR_IDENTIFIERS: {device_id},
|
||||
ATTR_SW_VERSION: node.firmware_version,
|
||||
ATTR_NAME: node.name
|
||||
or node.device_config.description
|
||||
or f"Node {node.node_id}",
|
||||
ATTR_MODEL: node.device_config.label,
|
||||
ATTR_MANUFACTURER: node.device_config.manufacturer,
|
||||
}
|
||||
if node.location:
|
||||
params["suggested_area"] = node.location
|
||||
params[ATTR_SUGGESTED_AREA] = node.location
|
||||
device = dev_reg.async_get_or_create(**params)
|
||||
|
||||
async_dispatcher_send(hass, EVENT_DEVICE_ADDED_TO_REGISTRY, device)
|
||||
|
|
|
@ -352,8 +352,12 @@ ATTR_LOCATION: Final = "location"
|
|||
|
||||
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_MODEL: Final = "model"
|
||||
ATTR_SUGGESTED_AREA: Final = "suggested_area"
|
||||
ATTR_SW_VERSION: Final = "sw_version"
|
||||
ATTR_VIA_DEVICE: Final = "via_device"
|
||||
|
||||
|
|
Loading…
Reference in New Issue