mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Use constant instead of plain key name for device info attributes (#103188)
* Use constant instead of plain key name for device info connections * Some more device info constant changes
This commit is contained in:
parent
f15fb6cf5e
commit
4e3ff45a5e
@ -36,7 +36,7 @@ async def async_get_config_entry_diagnostics(
|
|||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
hass_device = device_registry.async_get_device(
|
hass_device = device_registry.async_get_device(
|
||||||
identifiers=router.device_info["identifiers"]
|
identifiers=router.device_info[ATTR_IDENTIFIERS]
|
||||||
)
|
)
|
||||||
if not hass_device:
|
if not hass_device:
|
||||||
return data
|
return data
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Base entity for the Elgato integration."""
|
"""Base entity for the Elgato integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.const import CONF_MAC
|
from homeassistant.const import ATTR_CONNECTIONS, CONF_MAC
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import (
|
||||||
CONNECTION_NETWORK_MAC,
|
CONNECTION_NETWORK_MAC,
|
||||||
DeviceInfo,
|
DeviceInfo,
|
||||||
@ -31,6 +31,6 @@ class ElgatoEntity(CoordinatorEntity[ElgatoDataUpdateCoordinator]):
|
|||||||
hw_version=str(coordinator.data.info.hardware_board_type),
|
hw_version=str(coordinator.data.info.hardware_board_type),
|
||||||
)
|
)
|
||||||
if (mac := coordinator.config_entry.data.get(CONF_MAC)) is not None:
|
if (mac := coordinator.config_entry.data.get(CONF_MAC)) is not None:
|
||||||
self._attr_device_info["connections"] = {
|
self._attr_device_info[ATTR_CONNECTIONS] = {
|
||||||
(CONNECTION_NETWORK_MAC, format_mac(mac))
|
(CONNECTION_NETWORK_MAC, format_mac(mac))
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Base entity for the Fully Kiosk Browser integration."""
|
"""Base entity for the Fully Kiosk Browser integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from homeassistant.const import ATTR_CONNECTIONS
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
@ -40,7 +41,7 @@ class FullyKioskEntity(CoordinatorEntity[FullyKioskDataUpdateCoordinator], Entit
|
|||||||
if "Mac" in coordinator.data and valid_global_mac_address(
|
if "Mac" in coordinator.data and valid_global_mac_address(
|
||||||
coordinator.data["Mac"]
|
coordinator.data["Mac"]
|
||||||
):
|
):
|
||||||
device_info["connections"] = {
|
device_info[ATTR_CONNECTIONS] = {
|
||||||
(CONNECTION_NETWORK_MAC, coordinator.data["Mac"])
|
(CONNECTION_NETWORK_MAC, coordinator.data["Mac"])
|
||||||
}
|
}
|
||||||
self._attr_device_info = device_info
|
self._attr_device_info = device_info
|
||||||
|
@ -5,7 +5,7 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.components.diagnostics import REDACTED, async_redact_data
|
from homeassistant.components.diagnostics import REDACTED, async_redact_data
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PASSWORD
|
from homeassistant.const import ATTR_IDENTIFIERS, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -36,7 +36,7 @@ async def async_get_config_entry_diagnostics(
|
|||||||
}
|
}
|
||||||
|
|
||||||
device_info = {**plenticore.device_info}
|
device_info = {**plenticore.device_info}
|
||||||
device_info["identifiers"] = REDACTED # contains serial number
|
device_info[ATTR_IDENTIFIERS] = REDACTED # contains serial number
|
||||||
data["device"] = device_info
|
data["device"] = device_info
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_MAC, CONF_MODEL, CONF_NAME
|
from homeassistant.const import (
|
||||||
|
ATTR_CONNECTIONS,
|
||||||
|
ATTR_IDENTIFIERS,
|
||||||
|
CONF_MAC,
|
||||||
|
CONF_MODEL,
|
||||||
|
CONF_NAME,
|
||||||
|
)
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
@ -28,8 +34,8 @@ class SamsungTVEntity(Entity):
|
|||||||
model=config_entry.data.get(CONF_MODEL),
|
model=config_entry.data.get(CONF_MODEL),
|
||||||
)
|
)
|
||||||
if self.unique_id:
|
if self.unique_id:
|
||||||
self._attr_device_info["identifiers"] = {(DOMAIN, self.unique_id)}
|
self._attr_device_info[ATTR_IDENTIFIERS] = {(DOMAIN, self.unique_id)}
|
||||||
if self._mac:
|
if self._mac:
|
||||||
self._attr_device_info["connections"] = {
|
self._attr_device_info[ATTR_CONNECTIONS] = {
|
||||||
(dr.CONNECTION_NETWORK_MAC, self._mac)
|
(dr.CONNECTION_NETWORK_MAC, self._mac)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ from aiomusiccast.musiccast_device import MusicCastData, MusicCastDevice
|
|||||||
|
|
||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, Platform
|
from homeassistant.const import ATTR_CONNECTIONS, ATTR_VIA_DEVICE, CONF_HOST, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.device_registry import (
|
from homeassistant.helpers.device_registry import (
|
||||||
@ -176,12 +176,12 @@ class MusicCastDeviceEntity(MusicCastEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self._zone_id == DEFAULT_ZONE:
|
if self._zone_id == DEFAULT_ZONE:
|
||||||
device_info["connections"] = {
|
device_info[ATTR_CONNECTIONS] = {
|
||||||
(CONNECTION_NETWORK_MAC, format_mac(mac))
|
(CONNECTION_NETWORK_MAC, format_mac(mac))
|
||||||
for mac in self.coordinator.data.mac_addresses.values()
|
for mac in self.coordinator.data.mac_addresses.values()
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
device_info["via_device"] = (DOMAIN, self.coordinator.data.device_id)
|
device_info[ATTR_VIA_DEVICE] = (DOMAIN, self.coordinator.data.device_id)
|
||||||
|
|
||||||
return device_info
|
return device_info
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user