From 4e3ff45a5e15366a857c0cd0e06b18dd0140533a Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Thu, 2 Nov 2023 21:59:25 +0100 Subject: [PATCH] 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 --- homeassistant/components/asuswrt/diagnostics.py | 2 +- homeassistant/components/elgato/entity.py | 4 ++-- homeassistant/components/fully_kiosk/entity.py | 3 ++- .../components/kostal_plenticore/diagnostics.py | 4 ++-- homeassistant/components/samsungtv/entity.py | 12 +++++++++--- .../components/yamaha_musiccast/__init__.py | 6 +++--- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/asuswrt/diagnostics.py b/homeassistant/components/asuswrt/diagnostics.py index 61de4c866db..0a3cc809c32 100644 --- a/homeassistant/components/asuswrt/diagnostics.py +++ b/homeassistant/components/asuswrt/diagnostics.py @@ -36,7 +36,7 @@ async def async_get_config_entry_diagnostics( device_registry = dr.async_get(hass) entity_registry = er.async_get(hass) hass_device = device_registry.async_get_device( - identifiers=router.device_info["identifiers"] + identifiers=router.device_info[ATTR_IDENTIFIERS] ) if not hass_device: return data diff --git a/homeassistant/components/elgato/entity.py b/homeassistant/components/elgato/entity.py index 1bbd32f5b44..3f46b51d7b7 100644 --- a/homeassistant/components/elgato/entity.py +++ b/homeassistant/components/elgato/entity.py @@ -1,7 +1,7 @@ """Base entity for the Elgato integration.""" from __future__ import annotations -from homeassistant.const import CONF_MAC +from homeassistant.const import ATTR_CONNECTIONS, CONF_MAC from homeassistant.helpers.device_registry import ( CONNECTION_NETWORK_MAC, DeviceInfo, @@ -31,6 +31,6 @@ class ElgatoEntity(CoordinatorEntity[ElgatoDataUpdateCoordinator]): hw_version=str(coordinator.data.info.hardware_board_type), ) 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)) } diff --git a/homeassistant/components/fully_kiosk/entity.py b/homeassistant/components/fully_kiosk/entity.py index 2fe367643ee..fcb6f35eb11 100644 --- a/homeassistant/components/fully_kiosk/entity.py +++ b/homeassistant/components/fully_kiosk/entity.py @@ -1,6 +1,7 @@ """Base entity for the Fully Kiosk Browser integration.""" from __future__ import annotations +from homeassistant.const import ATTR_CONNECTIONS from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo from homeassistant.helpers.entity import Entity 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( coordinator.data["Mac"] ): - device_info["connections"] = { + device_info[ATTR_CONNECTIONS] = { (CONNECTION_NETWORK_MAC, coordinator.data["Mac"]) } self._attr_device_info = device_info diff --git a/homeassistant/components/kostal_plenticore/diagnostics.py b/homeassistant/components/kostal_plenticore/diagnostics.py index 2e061d35528..eef9f05537f 100644 --- a/homeassistant/components/kostal_plenticore/diagnostics.py +++ b/homeassistant/components/kostal_plenticore/diagnostics.py @@ -5,7 +5,7 @@ from typing import Any from homeassistant.components.diagnostics import REDACTED, async_redact_data 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 .const import DOMAIN @@ -36,7 +36,7 @@ async def async_get_config_entry_diagnostics( } device_info = {**plenticore.device_info} - device_info["identifiers"] = REDACTED # contains serial number + device_info[ATTR_IDENTIFIERS] = REDACTED # contains serial number data["device"] = device_info return data diff --git a/homeassistant/components/samsungtv/entity.py b/homeassistant/components/samsungtv/entity.py index dbfd7c44730..384a7a21528 100644 --- a/homeassistant/components/samsungtv/entity.py +++ b/homeassistant/components/samsungtv/entity.py @@ -2,7 +2,13 @@ from __future__ import annotations 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.device_registry import DeviceInfo from homeassistant.helpers.entity import Entity @@ -28,8 +34,8 @@ class SamsungTVEntity(Entity): model=config_entry.data.get(CONF_MODEL), ) 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: - self._attr_device_info["connections"] = { + self._attr_device_info[ATTR_CONNECTIONS] = { (dr.CONNECTION_NETWORK_MAC, self._mac) } diff --git a/homeassistant/components/yamaha_musiccast/__init__.py b/homeassistant/components/yamaha_musiccast/__init__.py index 9e8b8fed530..307171487bc 100644 --- a/homeassistant/components/yamaha_musiccast/__init__.py +++ b/homeassistant/components/yamaha_musiccast/__init__.py @@ -10,7 +10,7 @@ from aiomusiccast.musiccast_device import MusicCastData, MusicCastDevice from homeassistant.components import ssdp 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.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import ( @@ -176,12 +176,12 @@ class MusicCastDeviceEntity(MusicCastEntity): ) if self._zone_id == DEFAULT_ZONE: - device_info["connections"] = { + device_info[ATTR_CONNECTIONS] = { (CONNECTION_NETWORK_MAC, format_mac(mac)) for mac in self.coordinator.data.mac_addresses.values() } 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