From 176ed4f7ba562ab25734b847d35039afda48a6a9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 22 Oct 2021 12:31:12 +0200 Subject: [PATCH] Use DeviceInfo on components with via_device (I-T) (#58212) Co-authored-by: epenet --- .../components/iaqualink/__init__.py | 14 ++++---- .../components/insteon/insteon_entity.py | 20 +++++------ homeassistant/components/izone/climate.py | 15 +++++---- .../components/lutron_caseta/__init__.py | 20 +++++------ .../components/motion_blinds/cover.py | 15 +++++---- homeassistant/components/netgear/router.py | 16 ++++----- homeassistant/components/notion/__init__.py | 18 +++++----- homeassistant/components/plex/media_player.py | 33 ++++++++++--------- homeassistant/components/point/__init__.py | 22 ++++++------- .../components/tradfri/base_class.py | 16 ++++----- 10 files changed, 96 insertions(+), 93 deletions(-) diff --git a/homeassistant/components/iaqualink/__init__.py b/homeassistant/components/iaqualink/__init__.py index 2bd0cade3b9..7eb7256aa99 100644 --- a/homeassistant/components/iaqualink/__init__.py +++ b/homeassistant/components/iaqualink/__init__.py @@ -238,10 +238,10 @@ class AqualinkEntity(Entity): @property def device_info(self) -> DeviceInfo: """Return the device info.""" - return { - "identifiers": {(DOMAIN, self.unique_id)}, - "name": self.name, - "model": self.dev.__class__.__name__.replace("Aqualink", ""), - "manufacturer": "Jandy", - "via_device": (DOMAIN, self.dev.system.serial), - } + return DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + name=self.name, + model=self.dev.__class__.__name__.replace("Aqualink", ""), + manufacturer="Jandy", + via_device=(DOMAIN, self.dev.system.serial), + ) diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index e555725a188..f3f71e37ecf 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -9,7 +9,7 @@ from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from .const import ( DOMAIN, @@ -79,16 +79,16 @@ class InsteonEntity(Entity): return {"insteon_address": self.address, "insteon_group": self.group} @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device information.""" - return { - "identifiers": {(DOMAIN, str(self._insteon_device.address))}, - "name": f"{self._insteon_device.description} {self._insteon_device.address}", - "model": f"{self._insteon_device.model} ({self._insteon_device.cat!r}, 0x{self._insteon_device.subcat:02x})", - "sw_version": f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}", - "manufacturer": "Smart Home", - "via_device": (DOMAIN, str(devices.modem.address)), - } + return DeviceInfo( + identifiers={(DOMAIN, str(self._insteon_device.address))}, + name=f"{self._insteon_device.description} {self._insteon_device.address}", + model=f"{self._insteon_device.model} ({self._insteon_device.cat!r}, 0x{self._insteon_device.subcat:02x})", + sw_version=f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}", + manufacturer="Smart Home", + via_device=(DOMAIN, str(devices.modem.address)), + ) @callback def async_entity_update(self, name, address, value, group): diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index bd1de0f935e..ddbb59aedad 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -35,6 +35,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.typing import ConfigType @@ -483,13 +484,13 @@ class ZoneDevice(ClimateEntity): } self._supported_features |= SUPPORT_TARGET_TEMPERATURE - self._device_info = { - "identifiers": {(IZONE, controller.unique_id, zone.index)}, - "name": self.name, - "manufacturer": "IZone", - "via_device": (IZONE, controller.unique_id), - "model": zone.type.name.title(), - } + self._device_info = DeviceInfo( + identifiers={(IZONE, controller.unique_id, zone.index)}, + name=self.name, + manufacturer="IZone", + via_device=(IZONE, controller.unique_id), + model=zone.type.name.title(), + ) async def async_added_to_hass(self): """Call on adding to hass.""" diff --git a/homeassistant/components/lutron_caseta/__init__.py b/homeassistant/components/lutron_caseta/__init__.py index 4aefb2fb50e..7e3cde2ccac 100644 --- a/homeassistant/components/lutron_caseta/__init__.py +++ b/homeassistant/components/lutron_caseta/__init__.py @@ -17,7 +17,7 @@ from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from .const import ( ACTION_PRESS, @@ -329,16 +329,16 @@ class LutronCasetaDevice(Entity): return str(self.serial) @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info.""" - return { - "identifiers": {(DOMAIN, self.serial)}, - "name": self.name, - "suggested_area": self._device["name"].split("_")[0], - "manufacturer": MANUFACTURER, - "model": f"{self._device['model']} ({self._device['type']})", - "via_device": (DOMAIN, self._bridge_device["serial"]), - } + return DeviceInfo( + identifiers={(DOMAIN, self.serial)}, + name=self.name, + suggested_area=self._device["name"].split("_")[0], + manufacturer=MANUFACTURER, + model=f"{self._device['model']} ({self._device['type']})", + via_device=(DOMAIN, self._bridge_device["serial"]), + ) @property def extra_state_attributes(self): diff --git a/homeassistant/components/motion_blinds/cover.py b/homeassistant/components/motion_blinds/cover.py index 16e5255240c..1e4251c22f2 100644 --- a/homeassistant/components/motion_blinds/cover.py +++ b/homeassistant/components/motion_blinds/cover.py @@ -17,6 +17,7 @@ from homeassistant.components.cover import ( CoverEntity, ) from homeassistant.helpers import config_validation as cv, entity_platform +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ( @@ -138,13 +139,13 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity): self._attr_device_class = device_class self._attr_name = f"{blind.blind_type}-{blind.mac[12:]}" self._attr_unique_id = blind.mac - self._attr_device_info = { - "identifiers": {(DOMAIN, blind.mac)}, - "manufacturer": MANUFACTURER, - "name": f"{blind.blind_type}-{blind.mac[12:]}", - "model": blind.blind_type, - "via_device": (DOMAIN, config_entry.unique_id), - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, blind.mac)}, + manufacturer=MANUFACTURER, + name=f"{blind.blind_type}-{blind.mac[12:]}", + model=blind.blind_type, + via_device=(DOMAIN, config_entry.unique_id), + ) @property def available(self): diff --git a/homeassistant/components/netgear/router.py b/homeassistant/components/netgear/router.py index 12abac53c38..3c2497f2131 100644 --- a/homeassistant/components/netgear/router.py +++ b/homeassistant/components/netgear/router.py @@ -23,7 +23,7 @@ from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.typing import HomeAssistantType @@ -273,14 +273,14 @@ class NetgearDeviceEntity(Entity): return self._name @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device information.""" - return { - "connections": {(CONNECTION_NETWORK_MAC, self._mac)}, - "default_name": self._device_name, - "default_model": self._device["device_model"], - "via_device": (DOMAIN, self._router.unique_id), - } + return DeviceInfo( + connections={(CONNECTION_NETWORK_MAC, self._mac)}, + default_name=self._device_name, + default_model=self._device["device_model"], + via_device=(DOMAIN, self._router.unique_id), + ) @property def should_poll(self) -> bool: diff --git a/homeassistant/components/notion/__init__.py b/homeassistant/components/notion/__init__.py index a65e8ab338c..74fd2b90117 100644 --- a/homeassistant/components/notion/__init__.py +++ b/homeassistant/components/notion/__init__.py @@ -17,7 +17,7 @@ from homeassistant.helpers import ( config_validation as cv, device_registry as dr, ) -from homeassistant.helpers.entity import EntityDescription +from homeassistant.helpers.entity import DeviceInfo, EntityDescription from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -147,14 +147,14 @@ class NotionEntity(CoordinatorEntity): bridge = self.coordinator.data["bridges"].get(bridge_id, {}) sensor = self.coordinator.data["sensors"][sensor_id] - self._attr_device_info = { - "identifiers": {(DOMAIN, sensor["hardware_id"])}, - "manufacturer": "Silicon Labs", - "model": sensor["hardware_revision"], - "name": str(sensor["name"]), - "sw_version": sensor["firmware_version"], - "via_device": (DOMAIN, bridge.get("hardware_id")), - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, sensor["hardware_id"])}, + manufacturer="Silicon Labs", + model=sensor["hardware_revision"], + name=str(sensor["name"]), + sw_version=sensor["firmware_version"], + via_device=(DOMAIN, bridge.get("hardware_id")), + ) self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} self._attr_name = f'{sensor["name"]}: {description.name}' diff --git a/homeassistant/components/plex/media_player.py b/homeassistant/components/plex/media_player.py index 2e89ede121d..5a60c1e8b32 100644 --- a/homeassistant/components/plex/media_player.py +++ b/homeassistant/components/plex/media_player.py @@ -27,6 +27,7 @@ from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.helpers.network import is_internal_request @@ -523,28 +524,28 @@ class PlexMediaPlayer(MediaPlayerEntity): return attributes @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return a device description for device registry.""" if self.machine_identifier is None: return None if self.device_product in TRANSIENT_DEVICE_MODELS: - return { - "identifiers": {(PLEX_DOMAIN, "plex.tv-clients")}, - "name": "Plex Client Service", - "manufacturer": "Plex", - "model": "Plex Clients", - "entry_type": "service", - } + return DeviceInfo( + identifiers={(PLEX_DOMAIN, "plex.tv-clients")}, + name="Plex Client Service", + manufacturer="Plex", + model="Plex Clients", + entry_type="service", + ) - return { - "identifiers": {(PLEX_DOMAIN, self.machine_identifier)}, - "manufacturer": self.device_platform or "Plex", - "model": self.device_product or self.device_make, - "name": self.name, - "sw_version": self.device_version, - "via_device": (PLEX_DOMAIN, self.plex_server.machine_identifier), - } + return DeviceInfo( + identifiers={(PLEX_DOMAIN, self.machine_identifier)}, + manufacturer=self.device_platform or "Plex", + model=self.device_product or self.device_make, + name=self.name, + sw_version=self.device_version, + via_device=(PLEX_DOMAIN, self.plex_server.machine_identifier), + ) async def async_browse_media(self, media_content_type=None, media_content_id=None): """Implement the websocket media browsing helper.""" diff --git a/homeassistant/components/point/__init__.py b/homeassistant/components/point/__init__.py index 66f640cb7be..45b7dbb9e3e 100644 --- a/homeassistant/components/point/__init__.py +++ b/homeassistant/components/point/__init__.py @@ -21,7 +21,7 @@ from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, ) -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.event import async_track_time_interval from homeassistant.util.dt import as_local, parse_datetime, utc_from_timestamp @@ -308,20 +308,20 @@ class MinutPointEntity(Entity): return attrs @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return a device description for device registry.""" device = self.device.device - return { - "connections": { + return DeviceInfo( + connections={ (device_registry.CONNECTION_NETWORK_MAC, device["device_mac"]) }, - "identifieres": device["device_id"], - "manufacturer": "Minut", - "model": f"Point v{device['hardware_version']}", - "name": device["description"], - "sw_version": device["firmware"]["installed"], - "via_device": (DOMAIN, device["home"]), - } + identifieres=device["device_id"], + manufacturer="Minut", + model=f"Point v{device['hardware_version']}", + name=device["description"], + sw_version=device["firmware"]["installed"], + via_device=(DOMAIN, device["home"]), + ) @property def name(self): diff --git a/homeassistant/components/tradfri/base_class.py b/homeassistant/components/tradfri/base_class.py index b0679a2a8ce..1222e9b7792 100644 --- a/homeassistant/components/tradfri/base_class.py +++ b/homeassistant/components/tradfri/base_class.py @@ -109,14 +109,14 @@ class TradfriBaseDevice(TradfriBaseClass): def device_info(self) -> DeviceInfo: """Return the device info.""" info = self._device.device_info - return { - "identifiers": {(DOMAIN, self._device.id)}, - "manufacturer": info.manufacturer, - "model": info.model_number, - "name": self._attr_name, - "sw_version": info.firmware_version, - "via_device": (DOMAIN, self._gateway_id), - } + return DeviceInfo( + identifiers={(DOMAIN, self._device.id)}, + manufacturer=info.manufacturer, + model=info.model_number, + name=self._attr_name, + sw_version=info.firmware_version, + via_device=(DOMAIN, self._gateway_id), + ) def _refresh(self, device: Device) -> None: """Refresh the device data."""