From 05671557f0ce6ae6a8ee33aead593616079d5b2a Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Sat, 23 Oct 2021 14:42:50 -0400 Subject: [PATCH] Use DeviceInfo Class I-K (#58300) --- .../components/ialarm/alarm_control_panel.py | 13 +++++---- .../components/iaqualink/__init__.py | 4 +-- .../components/icloud/device_tracker.py | 12 ++++---- homeassistant/components/icloud/sensor.py | 12 ++++---- .../components/insteon/insteon_entity.py | 6 ++-- homeassistant/components/ios/sensor.py | 17 +++++------ homeassistant/components/iotawatt/sensor.py | 14 ++++------ homeassistant/components/ipp/entity.py | 23 ++++++--------- homeassistant/components/izone/climate.py | 28 ++++++------------- homeassistant/components/juicenet/entity.py | 6 ++-- .../keenetic_ndms2/device_tracker.py | 17 +++++------ .../components/keenetic_ndms2/router.py | 17 +++++------ homeassistant/components/kodi/media_player.py | 13 +++++---- .../components/konnected/binary_sensor.py | 9 +++--- homeassistant/components/konnected/sensor.py | 3 +- homeassistant/components/konnected/switch.py | 8 ++---- .../components/kostal_plenticore/helper.py | 15 +++++----- homeassistant/components/kraken/sensor.py | 13 +++++---- homeassistant/components/kulersky/light.py | 13 +++++---- 19 files changed, 114 insertions(+), 129 deletions(-) diff --git a/homeassistant/components/ialarm/alarm_control_panel.py b/homeassistant/components/ialarm/alarm_control_panel.py index fc758dd6175..bb5f5386ecd 100644 --- a/homeassistant/components/ialarm/alarm_control_panel.py +++ b/homeassistant/components/ialarm/alarm_control_panel.py @@ -4,6 +4,7 @@ from homeassistant.components.alarm_control_panel.const import ( SUPPORT_ALARM_ARM_AWAY, SUPPORT_ALARM_ARM_HOME, ) +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DATA_COORDINATOR, DOMAIN @@ -19,13 +20,13 @@ class IAlarmPanel(CoordinatorEntity, AlarmControlPanelEntity): """Representation of an iAlarm device.""" @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device info for this device.""" - return { - "identifiers": {(DOMAIN, self.unique_id)}, - "name": self.name, - "manufacturer": "Antifurto365 - Meian", - } + return DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + manufacturer="Antifurto365 - Meian", + name=self.name, + ) @property def unique_id(self): diff --git a/homeassistant/components/iaqualink/__init__.py b/homeassistant/components/iaqualink/__init__.py index 7eb7256aa99..856674f1345 100644 --- a/homeassistant/components/iaqualink/__init__.py +++ b/homeassistant/components/iaqualink/__init__.py @@ -240,8 +240,8 @@ class AqualinkEntity(Entity): """Return the device info.""" return DeviceInfo( identifiers={(DOMAIN, self.unique_id)}, - name=self.name, - model=self.dev.__class__.__name__.replace("Aqualink", ""), manufacturer="Jandy", + model=self.dev.__class__.__name__.replace("Aqualink", ""), + name=self.name, via_device=(DOMAIN, self.dev.system.serial), ) diff --git a/homeassistant/components/icloud/device_tracker.py b/homeassistant/components/icloud/device_tracker.py index 233df6a7556..d255d29b6ee 100644 --- a/homeassistant/components/icloud/device_tracker.py +++ b/homeassistant/components/icloud/device_tracker.py @@ -115,12 +115,12 @@ class IcloudTrackerEntity(TrackerEntity): @property def device_info(self) -> DeviceInfo: """Return the device information.""" - return { - "identifiers": {(DOMAIN, self._device.unique_id)}, - "name": self._device.name, - "manufacturer": "Apple", - "model": self._device.device_model, - } + return DeviceInfo( + identifiers={(DOMAIN, self._device.unique_id)}, + manufacturer="Apple", + model=self._device.device_model, + name=self._device.name, + ) async def async_added_to_hass(self): """Register state update callback.""" diff --git a/homeassistant/components/icloud/sensor.py b/homeassistant/components/icloud/sensor.py index 5469eadc998..6de8a49daf1 100644 --- a/homeassistant/components/icloud/sensor.py +++ b/homeassistant/components/icloud/sensor.py @@ -93,12 +93,12 @@ class IcloudDeviceBatterySensor(SensorEntity): @property def device_info(self) -> DeviceInfo: """Return the device information.""" - return { - "identifiers": {(DOMAIN, self._device.unique_id)}, - "name": self._device.name, - "manufacturer": "Apple", - "model": self._device.device_model, - } + return DeviceInfo( + identifiers={(DOMAIN, self._device.unique_id)}, + manufacturer="Apple", + model=self._device.device_model, + name=self._device.name, + ) @property def should_poll(self) -> bool: diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index f3f71e37ecf..aa2d4367225 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -83,10 +83,10 @@ class InsteonEntity(Entity): """Return device information.""" 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", + model=f"{self._insteon_device.model} ({self._insteon_device.cat!r}, 0x{self._insteon_device.subcat:02x})", + name=f"{self._insteon_device.description} {self._insteon_device.address}", + sw_version=f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}", via_device=(DOMAIN, str(devices.modem.address)), ) diff --git a/homeassistant/components/ios/sensor.py b/homeassistant/components/ios/sensor.py index c3c1ad2b8ce..d8d779155bd 100644 --- a/homeassistant/components/ios/sensor.py +++ b/homeassistant/components/ios/sensor.py @@ -6,6 +6,7 @@ from homeassistant.components.sensor import SensorEntity, SensorEntityDescriptio from homeassistant.const import PERCENTAGE from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.icon import icon_for_battery_level from .const import DOMAIN @@ -59,20 +60,20 @@ class IOSSensor(SensorEntity): self._attr_unique_id = f"{description.key}_{device_id}" @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return information about the device.""" - return { - "identifiers": { + return DeviceInfo( + identifiers={ ( ios.DOMAIN, self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_PERMANENT_ID], ) }, - "name": self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_NAME], - "manufacturer": "Apple", - "model": self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_TYPE], - "sw_version": self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_SYSTEM_VERSION], - } + manufacturer="Apple", + model=self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_TYPE], + name=self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_NAME], + sw_version=self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_SYSTEM_VERSION], + ) @property def extra_state_attributes(self): diff --git a/homeassistant/components/iotawatt/sensor.py b/homeassistant/components/iotawatt/sensor.py index ec2918b0ce6..1da5100ea9f 100644 --- a/homeassistant/components/iotawatt/sensor.py +++ b/homeassistant/components/iotawatt/sensor.py @@ -191,15 +191,13 @@ class IotaWattSensor(update_coordinator.CoordinatorEntity, SensorEntity): return self._sensor_data.getName() @property - def device_info(self) -> entity.DeviceInfo | None: + def device_info(self) -> entity.DeviceInfo: """Return device info.""" - return { - "connections": { - (CONNECTION_NETWORK_MAC, self._sensor_data.hub_mac_address) - }, - "manufacturer": "IoTaWatt", - "model": "IoTaWatt", - } + return entity.DeviceInfo( + connections={(CONNECTION_NETWORK_MAC, self._sensor_data.hub_mac_address)}, + manufacturer="IoTaWatt", + model="IoTaWatt", + ) @callback def _handle_coordinator_update(self) -> None: diff --git a/homeassistant/components/ipp/entity.py b/homeassistant/components/ipp/entity.py index 55a0e76a658..7bd01b4cd12 100644 --- a/homeassistant/components/ipp/entity.py +++ b/homeassistant/components/ipp/entity.py @@ -1,13 +1,6 @@ """Entities for The Internet Printing Protocol (IPP) integration.""" from __future__ import annotations -from homeassistant.const import ( - ATTR_IDENTIFIERS, - ATTR_MANUFACTURER, - ATTR_MODEL, - ATTR_NAME, - ATTR_SW_VERSION, -) from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -37,15 +30,15 @@ class IPPEntity(CoordinatorEntity): self._attr_entity_registry_enabled_default = enabled_default @property - def device_info(self) -> DeviceInfo: + def device_info(self) -> DeviceInfo | None: """Return device information about this IPP device.""" if self._device_id is None: return None - return { - ATTR_IDENTIFIERS: {(DOMAIN, self._device_id)}, - ATTR_NAME: self.coordinator.data.info.name, - ATTR_MANUFACTURER: self.coordinator.data.info.manufacturer, - ATTR_MODEL: self.coordinator.data.info.model, - ATTR_SW_VERSION: self.coordinator.data.info.version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._device_id)}, + manufacturer=self.coordinator.data.info.manufacturer, + model=self.coordinator.data.info.model, + name=self.coordinator.data.info.name, + sw_version=self.coordinator.data.info.version, + ) diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index ddbb59aedad..67d121d760e 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -161,12 +161,12 @@ class ControllerDevice(ClimateEntity): self._fan_to_pizone[_IZONE_FAN_TO_HA[fan]] = fan self._available = True - self._device_info = { - "identifiers": {(IZONE, self.unique_id)}, - "name": self.name, - "manufacturer": "IZone", - "model": self._controller.sys_type, - } + self._attr_device_info = DeviceInfo( + identifiers={(IZONE, self.unique_id)}, + manufacturer="IZone", + model=self._controller.sys_type, + name=self.name, + ) # Create the zones self.zones = {} @@ -246,11 +246,6 @@ class ControllerDevice(ClimateEntity): for zone in self.zones.values(): zone.async_schedule_update_ha_state() - @property - def device_info(self): - """Return the device info for the iZone system.""" - return self._device_info - @property def unique_id(self): """Return the ID of the controller device.""" @@ -484,12 +479,12 @@ class ZoneDevice(ClimateEntity): } self._supported_features |= SUPPORT_TARGET_TEMPERATURE - self._device_info = DeviceInfo( + self._attr_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(), + name=self.name, + via_device=(IZONE, controller.unique_id), ) async def async_added_to_hass(self): @@ -517,11 +512,6 @@ class ZoneDevice(ClimateEntity): """Return True if unable to access real state of the entity.""" return self._controller.assumed_state - @property - def device_info(self): - """Return the device info for the iZone system.""" - return self._device_info - @property def unique_id(self): """Return the ID of the controller device.""" diff --git a/homeassistant/components/juicenet/entity.py b/homeassistant/components/juicenet/entity.py index d3b2aa41d19..4b4e5764a5e 100644 --- a/homeassistant/components/juicenet/entity.py +++ b/homeassistant/components/juicenet/entity.py @@ -24,8 +24,8 @@ class JuiceNetDevice(CoordinatorEntity): def device_info(self) -> DeviceInfo: """Return device information about this JuiceNet Device.""" return DeviceInfo( - identifiers={(DOMAIN, self.device.id)}, - name=self.device.name, - manufacturer="JuiceNet", configuration_url=f"https://home.juice.net/Portal/Details?unitID={self.device.id}", + identifiers={(DOMAIN, self.device.id)}, + manufacturer="JuiceNet", + name=self.device.name, ) diff --git a/homeassistant/components/keenetic_ndms2/device_tracker.py b/homeassistant/components/keenetic_ndms2/device_tracker.py index a08d8c72f0c..4ec353045c7 100644 --- a/homeassistant/components/keenetic_ndms2/device_tracker.py +++ b/homeassistant/components/keenetic_ndms2/device_tracker.py @@ -26,6 +26,7 @@ from homeassistant.helpers import entity_registry import homeassistant.helpers.config_validation as cv from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo import homeassistant.util.dt as dt_util from .const import ( @@ -217,17 +218,13 @@ class KeeneticTracker(ScannerEntity): return None @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return a client description for device registry.""" - info = { - "connections": {(CONNECTION_NETWORK_MAC, self._device.mac)}, - "identifiers": {(DOMAIN, self._device.mac)}, - } - - if self._device.name: - info["name"] = self._device.name - - return info + return DeviceInfo( + connections={(CONNECTION_NETWORK_MAC, self._device.mac)}, + identifiers={(DOMAIN, self._device.mac)}, + name=self._device.name if self._device.name else None, + ) async def async_added_to_hass(self): """Client entity created.""" diff --git a/homeassistant/components/keenetic_ndms2/router.py b/homeassistant/components/keenetic_ndms2/router.py index 8da8034a162..fdab10ea55e 100644 --- a/homeassistant/components/keenetic_ndms2/router.py +++ b/homeassistant/components/keenetic_ndms2/router.py @@ -19,6 +19,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.event import async_call_later import homeassistant.util.dt as dt_util @@ -66,15 +67,15 @@ class KeeneticRouter: return self.config_entry.data[CONF_HOST] @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the host of this hub.""" - return { - "identifiers": {(DOMAIN, f"router-{self.config_entry.entry_id}")}, - "manufacturer": self.manufacturer, - "model": self.model, - "name": self.name, - "sw_version": self.firmware, - } + return DeviceInfo( + identifiers={(DOMAIN, f"router-{self.config_entry.entry_id}")}, + manufacturer=self.manufacturer, + model=self.model, + name=self.name, + sw_version=self.firmware, + ) @property def name(self): diff --git a/homeassistant/components/kodi/media_player.py b/homeassistant/components/kodi/media_player.py index 9fd46de026c..1e4298c447e 100644 --- a/homeassistant/components/kodi/media_player.py +++ b/homeassistant/components/kodi/media_player.py @@ -62,6 +62,7 @@ from homeassistant.helpers import ( device_registry, entity_platform, ) +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.network import is_internal_request import homeassistant.util.dt as dt_util @@ -345,13 +346,13 @@ class KodiEntity(MediaPlayerEntity): return self._unique_id @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device info for this device.""" - return { - "identifiers": {(DOMAIN, self.unique_id)}, - "name": self.name, - "manufacturer": "Kodi", - } + return DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + manufacturer="Kodi", + name=self.name, + ) @property def state(self): diff --git a/homeassistant/components/konnected/binary_sensor.py b/homeassistant/components/konnected/binary_sensor.py index dc7a15758d9..2647d43a44e 100644 --- a/homeassistant/components/konnected/binary_sensor.py +++ b/homeassistant/components/konnected/binary_sensor.py @@ -10,6 +10,7 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN as KONNECTED_DOMAIN @@ -66,11 +67,11 @@ class KonnectedBinarySensor(BinarySensorEntity): return self._device_class @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info.""" - return { - "identifiers": {(KONNECTED_DOMAIN, self._device_id)}, - } + return DeviceInfo( + identifiers={(KONNECTED_DOMAIN, self._device_id)}, + ) async def async_added_to_hass(self): """Store entity_id and register state change callback.""" diff --git a/homeassistant/components/konnected/sensor.py b/homeassistant/components/konnected/sensor.py index ae43e771068..0b835e3fdce 100644 --- a/homeassistant/components/konnected/sensor.py +++ b/homeassistant/components/konnected/sensor.py @@ -15,6 +15,7 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from .const import DOMAIN as KONNECTED_DOMAIN, SIGNAL_DS18B20_NEW @@ -111,7 +112,7 @@ class KonnectedSensor(SensorEntity): name += f" {description.name}" self._attr_name = name - self._attr_device_info = {"identifiers": {(KONNECTED_DOMAIN, device_id)}} + self._attr_device_info = DeviceInfo(identifiers={(KONNECTED_DOMAIN, device_id)}) @property def native_value(self): diff --git a/homeassistant/components/konnected/switch.py b/homeassistant/components/konnected/switch.py index 9c9f8193dcd..687d29f182c 100644 --- a/homeassistant/components/konnected/switch.py +++ b/homeassistant/components/konnected/switch.py @@ -11,7 +11,7 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import ToggleEntity +from homeassistant.helpers.entity import DeviceInfo, ToggleEntity from .const import ( CONF_ACTIVATION, @@ -77,11 +77,9 @@ class KonnectedSwitch(ToggleEntity): return device_data.get("panel") @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info.""" - return { - "identifiers": {(KONNECTED_DOMAIN, self._device_id)}, - } + return DeviceInfo(identifiers={(KONNECTED_DOMAIN, self._device_id)}) @property def available(self): diff --git a/homeassistant/components/kostal_plenticore/helper.py b/homeassistant/components/kostal_plenticore/helper.py index 2a21cb4ee55..32dfc9b2fd9 100644 --- a/homeassistant/components/kostal_plenticore/helper.py +++ b/homeassistant/components/kostal_plenticore/helper.py @@ -13,6 +13,7 @@ from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_ST from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.event import async_call_later from homeassistant.helpers.update_coordinator import DataUpdateCoordinator @@ -84,14 +85,14 @@ class Plenticore: prod1 = device_local["Branding:ProductName1"] prod2 = device_local["Branding:ProductName2"] - self.device_info = { - "identifiers": {(DOMAIN, device_local["Properties:SerialNo"])}, - "manufacturer": "Kostal", - "model": f"{prod1} {prod2}", - "name": settings["scb:network"]["Hostname"], - "sw_version": f'IOC: {device_local["Properties:VersionIOC"]}' + self.device_info = DeviceInfo( + identifiers={(DOMAIN, device_local["Properties:SerialNo"])}, + manufacturer="Kostal", + model=f"{prod1} {prod2}", + name=settings["scb:network"]["Hostname"], + sw_version=f'IOC: {device_local["Properties:VersionIOC"]}' + f' MC: {device_local["Properties:VersionMC"]}', - } + ) return True diff --git a/homeassistant/components/kraken/sensor.py b/homeassistant/components/kraken/sensor.py index b7d38d4796b..d2b2cfeae70 100644 --- a/homeassistant/components/kraken/sensor.py +++ b/homeassistant/components/kraken/sensor.py @@ -9,6 +9,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -112,12 +113,12 @@ class KrakenSensor(CoordinatorEntity[Optional[KrakenResponse]], SensorEntity): self._received_data_at_least_once = False self._available = True - self._attr_device_info = { - "identifiers": {(DOMAIN, f"{source_asset}_{self._target_asset}")}, - "name": self._device_name, - "manufacturer": "Kraken.com", - "entry_type": "service", - } + self._attr_device_info = DeviceInfo( + entry_type="service", + identifiers={(DOMAIN, f"{source_asset}_{self._target_asset}")}, + manufacturer="Kraken.com", + name=self._device_name, + ) async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" diff --git a/homeassistant/components/kulersky/light.py b/homeassistant/components/kulersky/light.py index 6e04dbdfcfd..f8d85960550 100644 --- a/homeassistant/components/kulersky/light.py +++ b/homeassistant/components/kulersky/light.py @@ -15,6 +15,7 @@ from homeassistant.components.light import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval @@ -97,13 +98,13 @@ class KulerskyLight(LightEntity): return self._light.address @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Device info for this light.""" - return { - "identifiers": {(DOMAIN, self.unique_id)}, - "name": self.name, - "manufacturer": "Brightech", - } + return DeviceInfo( + identifiers={(DOMAIN, self.unique_id)}, + manufacturer="Brightech", + name=self.name, + ) @property def is_on(self):