From 2df13d01187a4fac2f9038facc180eb2c2543712 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Sun, 24 Oct 2021 05:34:45 -0400 Subject: [PATCH] Use DeviceInfo Class N-O (#58314) --- homeassistant/components/nanoleaf/light.py | 2 +- homeassistant/components/neato/camera.py | 2 +- homeassistant/components/neato/sensor.py | 2 +- homeassistant/components/neato/switch.py | 2 +- homeassistant/components/neato/vacuum.py | 17 +++++------ homeassistant/components/nest/device_info.py | 14 ++++----- .../components/nest/legacy/__init__.py | 16 +++++----- .../components/nest/legacy/camera.py | 15 +++++----- .../components/nest/legacy/climate.py | 17 ++++++----- homeassistant/components/nexia/entity.py | 22 +++++++------- .../components/nmap_tracker/device_tracker.py | 10 +++---- homeassistant/components/nut/sensor.py | 16 ++++------ homeassistant/components/nws/__init__.py | 15 +++++----- homeassistant/components/omnilogic/common.py | 22 +++++--------- homeassistant/components/ondilo_ico/sensor.py | 17 ++++++----- homeassistant/components/onvif/base.py | 29 +++++++++---------- .../components/opentherm_gw/binary_sensor.py | 18 ++++++------ .../components/opentherm_gw/climate.py | 18 ++++++------ .../components/opentherm_gw/sensor.py | 18 ++++++------ .../components/openweathermap/sensor.py | 13 +++++---- .../components/openweathermap/weather.py | 15 +++++----- .../components/ovo_energy/__init__.py | 12 ++++---- .../components/owntracks/device_tracker.py | 5 ++-- 23 files changed, 155 insertions(+), 162 deletions(-) diff --git a/homeassistant/components/nanoleaf/light.py b/homeassistant/components/nanoleaf/light.py index af9faf21b79..6203431d609 100644 --- a/homeassistant/components/nanoleaf/light.py +++ b/homeassistant/components/nanoleaf/light.py @@ -84,9 +84,9 @@ class NanoleafLight(LightEntity): self._attr_name = self._nanoleaf.name self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, self._nanoleaf.serial_no)}, - name=self._nanoleaf.name, manufacturer=self._nanoleaf.manufacturer, model=self._nanoleaf.model, + name=self._nanoleaf.name, sw_version=self._nanoleaf.firmware_version, ) self._attr_min_mireds = math.ceil( diff --git a/homeassistant/components/neato/camera.py b/homeassistant/components/neato/camera.py index ee70116a7d3..6d4de68b456 100644 --- a/homeassistant/components/neato/camera.py +++ b/homeassistant/components/neato/camera.py @@ -132,7 +132,7 @@ class NeatoCleaningMap(Camera): @property def device_info(self) -> DeviceInfo: """Device info for neato robot.""" - return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}} + return DeviceInfo(identifiers={(NEATO_DOMAIN, self._robot_serial)}) @property def extra_state_attributes(self) -> dict[str, Any]: diff --git a/homeassistant/components/neato/sensor.py b/homeassistant/components/neato/sensor.py index 2d54e89bb04..9a5da4c1950 100644 --- a/homeassistant/components/neato/sensor.py +++ b/homeassistant/components/neato/sensor.py @@ -103,4 +103,4 @@ class NeatoSensor(SensorEntity): @property def device_info(self) -> DeviceInfo: """Device info for neato robot.""" - return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}} + return DeviceInfo(identifiers={(NEATO_DOMAIN, self._robot_serial)}) diff --git a/homeassistant/components/neato/switch.py b/homeassistant/components/neato/switch.py index 0e0d49f2b28..65d296bcb28 100644 --- a/homeassistant/components/neato/switch.py +++ b/homeassistant/components/neato/switch.py @@ -109,7 +109,7 @@ class NeatoConnectedSwitch(ToggleEntity): @property def device_info(self) -> DeviceInfo: """Device info for neato robot.""" - return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}} + return DeviceInfo(identifiers={(NEATO_DOMAIN, self._robot_serial)}) def turn_on(self, **kwargs: Any) -> None: """Turn the switch on.""" diff --git a/homeassistant/components/neato/vacuum.py b/homeassistant/components/neato/vacuum.py index 527cd4dce23..0ebf7c70bf2 100644 --- a/homeassistant/components/neato/vacuum.py +++ b/homeassistant/components/neato/vacuum.py @@ -338,15 +338,14 @@ class NeatoConnectedVacuum(StateVacuumEntity): @property def device_info(self) -> DeviceInfo: """Device info for neato robot.""" - info: DeviceInfo = { - "identifiers": {(NEATO_DOMAIN, self._robot_serial)}, - "name": self._name, - } - if self._robot_stats: - info["manufacturer"] = self._robot_stats["battery"]["vendor"] - info["model"] = self._robot_stats["model"] - info["sw_version"] = self._robot_stats["firmware"] - return info + stats = self._robot_stats + return DeviceInfo( + identifiers={(NEATO_DOMAIN, self._robot_serial)}, + manufacturer=stats["battery"]["vendor"] if stats else None, + model=stats["model"] if stats else None, + name=self._name, + sw_version=stats["firmware"] if stats else None, + ) def start(self) -> None: """Start cleaning or resume cleaning.""" diff --git a/homeassistant/components/nest/device_info.py b/homeassistant/components/nest/device_info.py index 605f3c48446..714e9cb00da 100644 --- a/homeassistant/components/nest/device_info.py +++ b/homeassistant/components/nest/device_info.py @@ -30,13 +30,11 @@ class NestDeviceInfo: def device_info(self) -> DeviceInfo: """Return device specific attributes.""" return DeviceInfo( - { - # The API "name" field is a unique device identifier. - "identifiers": {(DOMAIN, self._device.name)}, - "name": self.device_name, - "manufacturer": self.device_brand, - "model": self.device_model, - } + # The API "name" field is a unique device identifier. + identifiers={(DOMAIN, self._device.name)}, + manufacturer=self.device_brand, + model=self.device_model, + name=self.device_name, ) @property @@ -45,7 +43,7 @@ class NestDeviceInfo: if InfoTrait.NAME in self._device.traits: trait: InfoTrait = self._device.traits[InfoTrait.NAME] if trait.custom_name: - return trait.custom_name + return str(trait.custom_name) # Build a name from the room/structure. Note: This room/structure name # is not associated with a home assistant Area. if parent_relations := self._device.parent_relations: diff --git a/homeassistant/components/nest/legacy/__init__.py b/homeassistant/components/nest/legacy/__init__.py index 76ecf16b67b..85ff98f6420 100644 --- a/homeassistant/components/nest/legacy/__init__.py +++ b/homeassistant/components/nest/legacy/__init__.py @@ -21,7 +21,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from . import local_auth from .const import DATA_NEST, DATA_NEST_CONFIG, DOMAIN, SIGNAL_NEST_UPDATE @@ -377,7 +377,7 @@ class NestSensorDevice(Entity): return f"{self.device.serial}-{self.variable}" @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return information about the device.""" if not hasattr(self.device, "name_long"): name = self.structure.name @@ -393,12 +393,12 @@ class NestSensorDevice(Entity): else: model = None - return { - "identifiers": {(DOMAIN, self.device.serial)}, - "name": name, - "manufacturer": "Nest Labs", - "model": model, - } + return DeviceInfo( + identifiers={(DOMAIN, self.device.serial)}, + manufacturer="Nest Labs", + model=model, + name=name, + ) def update(self): """Do not use NestSensorDevice directly.""" diff --git a/homeassistant/components/nest/legacy/camera.py b/homeassistant/components/nest/legacy/camera.py index 3ef0089d2bc..0b6b7a649a6 100644 --- a/homeassistant/components/nest/legacy/camera.py +++ b/homeassistant/components/nest/legacy/camera.py @@ -7,6 +7,7 @@ import logging import requests from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_ON_OFF, Camera +from homeassistant.helpers.entity import DeviceInfo from homeassistant.util.dt import utcnow from .const import DATA_NEST, DOMAIN @@ -61,14 +62,14 @@ class NestCamera(Camera): return self.device.device_id @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return information about the device.""" - return { - "identifiers": {(DOMAIN, self.device.device_id)}, - "name": self.device.name_long, - "manufacturer": "Nest Labs", - "model": "Camera", - } + return DeviceInfo( + identifiers={(DOMAIN, self.device.device_id)}, + manufacturer="Nest Labs", + model="Camera", + name=self.device.name_long, + ) @property def should_poll(self): diff --git a/homeassistant/components/nest/legacy/climate.py b/homeassistant/components/nest/legacy/climate.py index 17448d9be8c..3e0eb5ac16b 100644 --- a/homeassistant/components/nest/legacy/climate.py +++ b/homeassistant/components/nest/legacy/climate.py @@ -32,6 +32,7 @@ from homeassistant.const import ( TEMP_FAHRENHEIT, ) from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from .const import DATA_NEST, DOMAIN, SIGNAL_NEST_UPDATE @@ -166,15 +167,15 @@ class NestThermostat(ClimateEntity): return self.device.serial @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return information about the device.""" - return { - "identifiers": {(DOMAIN, self.device.device_id)}, - "name": self.device.name_long, - "manufacturer": "Nest Labs", - "model": "Thermostat", - "sw_version": self.device.software_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self.device.device_id)}, + manufacturer="Nest Labs", + model="Thermostat", + name=self.device.name_long, + sw_version=self.device.software_version, + ) @property def name(self): diff --git a/homeassistant/components/nexia/entity.py b/homeassistant/components/nexia/entity.py index 87e06fb05cf..06d3b90e048 100644 --- a/homeassistant/components/nexia/entity.py +++ b/homeassistant/components/nexia/entity.py @@ -1,7 +1,7 @@ """The nexia integration base entity.""" - from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import ( @@ -11,6 +11,7 @@ from .const import ( SIGNAL_THERMOSTAT_UPDATE, SIGNAL_ZONE_UPDATE, ) +from .coordinator import NexiaDataUpdateCoordinator class NexiaEntity(CoordinatorEntity): @@ -49,16 +50,17 @@ class NexiaThermostatEntity(NexiaEntity): self._thermostat = thermostat @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device_info of the device.""" - return { - "identifiers": {(DOMAIN, self._thermostat.thermostat_id)}, - "name": self._thermostat.get_name(), - "model": self._thermostat.get_model(), - "sw_version": self._thermostat.get_firmware(), - "manufacturer": MANUFACTURER, - "configuration_url": self.coordinator.nexia_home.root_url, - } + assert isinstance(self.coordinator, NexiaDataUpdateCoordinator) + return DeviceInfo( + configuration_url=self.coordinator.nexia_home.root_url, + identifiers={(DOMAIN, self._thermostat.thermostat_id)}, + manufacturer=MANUFACTURER, + model=self._thermostat.get_model(), + name=self._thermostat.get_name(), + sw_version=self._thermostat.get_firmware(), + ) async def async_added_to_hass(self): """Listen for signals for services.""" diff --git a/homeassistant/components/nmap_tracker/device_tracker.py b/homeassistant/components/nmap_tracker/device_tracker.py index b63280951a6..d1115fa8934 100644 --- a/homeassistant/components/nmap_tracker/device_tracker.py +++ b/homeassistant/components/nmap_tracker/device_tracker.py @@ -172,11 +172,11 @@ class NmapTrackerEntity(ScannerEntity): @property def device_info(self) -> DeviceInfo: """Return the device information.""" - return { - "connections": {(CONNECTION_NETWORK_MAC, self._mac_address)}, - "default_manufacturer": self._device.manufacturer, - "default_name": self.name, - } + return DeviceInfo( + connections={(CONNECTION_NETWORK_MAC, self._mac_address)}, + default_manufacturer=self._device.manufacturer, + default_name=self.name, + ) @property def should_poll(self) -> bool: diff --git a/homeassistant/components/nut/sensor.py b/homeassistant/components/nut/sensor.py index c533a095270..7ec6e28401f 100644 --- a/homeassistant/components/nut/sensor.py +++ b/homeassistant/components/nut/sensor.py @@ -5,12 +5,8 @@ import logging from homeassistant.components.nut import PyNUTData from homeassistant.components.sensor import SensorEntity, SensorEntityDescription -from homeassistant.const import ( - ATTR_IDENTIFIERS, - ATTR_NAME, - CONF_RESOURCES, - STATE_UNKNOWN, -) +from homeassistant.const import CONF_RESOURCES, STATE_UNKNOWN +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -81,10 +77,10 @@ class NUTSensor(CoordinatorEntity, SensorEntity): self._attr_entity_registry_enabled_default = enabled_default self._attr_name = f"{device_name} {sensor_description.name}" self._attr_unique_id = f"{unique_id}_{sensor_description.key}" - self._attr_device_info = { - ATTR_IDENTIFIERS: {(DOMAIN, unique_id)}, - ATTR_NAME: device_name, - } + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, unique_id)}, + name=device_name, + ) self._attr_device_info.update(data.device_info) @property diff --git a/homeassistant/components/nws/__init__.py b/homeassistant/components/nws/__init__.py index 0f0886c5f41..6f5bdd145c9 100644 --- a/homeassistant/components/nws/__init__.py +++ b/homeassistant/components/nws/__init__.py @@ -12,6 +12,7 @@ from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import debounce from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.util.dt import utcnow @@ -168,11 +169,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload_ok -def device_info(latitude, longitude): +def device_info(latitude, longitude) -> DeviceInfo: """Return device registry information.""" - return { - "identifiers": {(DOMAIN, base_unique_id(latitude, longitude))}, - "name": f"NWS: {latitude}, {longitude}", - "manufacturer": "National Weather Service", - "entry_type": "service", - } + return DeviceInfo( + entry_type="service", + identifiers={(DOMAIN, base_unique_id(latitude, longitude))}, + manufacturer="National Weather Service", + name=f"NWS: {latitude}, {longitude}", + ) diff --git a/homeassistant/components/omnilogic/common.py b/homeassistant/components/omnilogic/common.py index 798c5abd69e..78685036e06 100644 --- a/homeassistant/components/omnilogic/common.py +++ b/homeassistant/components/omnilogic/common.py @@ -6,13 +6,8 @@ import logging from omnilogic import OmniLogic, OmniLogicException from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - ATTR_IDENTIFIERS, - ATTR_MANUFACTURER, - ATTR_MODEL, - ATTR_NAME, -) from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -152,15 +147,14 @@ class OmniLogicEntity(CoordinatorEntity): return self._attrs @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Define the device as back yard/MSP System.""" - - return { - ATTR_IDENTIFIERS: {(DOMAIN, self._msp_system_id)}, - ATTR_NAME: self._backyard_name, - ATTR_MANUFACTURER: "Hayward", - ATTR_MODEL: "OmniLogic", - } + return DeviceInfo( + identifiers={(DOMAIN, self._msp_system_id)}, + manufacturer="Hayward", + model="OmniLogic", + name=self._backyard_name, + ) def check_guard(state_key, item, entity_setting): diff --git a/homeassistant/components/ondilo_ico/sensor.py b/homeassistant/components/ondilo_ico/sensor.py index 693d685f77c..e02682ae298 100644 --- a/homeassistant/components/ondilo_ico/sensor.py +++ b/homeassistant/components/ondilo_ico/sensor.py @@ -16,6 +16,7 @@ from homeassistant.const import ( PERCENTAGE, TEMP_CELSIUS, ) +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -169,13 +170,13 @@ class OndiloICO(CoordinatorEntity, SensorEntity): return self._devdata()["value"] @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info for the sensor.""" pooldata = self._pooldata() - return { - "identifiers": {(DOMAIN, pooldata["ICO"]["serial_number"])}, - "name": self._device_name, - "manufacturer": "Ondilo", - "model": "ICO", - "sw_version": pooldata["ICO"]["sw_version"], - } + return DeviceInfo( + identifiers={(DOMAIN, pooldata["ICO"]["serial_number"])}, + manufacturer="Ondilo", + model="ICO", + name=self._device_name, + sw_version=pooldata["ICO"]["sw_version"], + ) diff --git a/homeassistant/components/onvif/base.py b/homeassistant/components/onvif/base.py index ab41fcc8f29..e4046f3c800 100644 --- a/homeassistant/components/onvif/base.py +++ b/homeassistant/components/onvif/base.py @@ -1,6 +1,6 @@ """Base classes for ONVIF entities.""" from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import DeviceInfo, Entity from .const import DOMAIN from .device import ONVIFDevice @@ -21,14 +21,14 @@ class ONVIFBaseEntity(Entity): return self.device.available @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return a device description for device registry.""" - device_info = { - "manufacturer": self.device.info.manufacturer, - "model": self.device.info.model, - "name": self.device.name, - "sw_version": self.device.info.fw_version, - "identifiers": { + connections = None + if self.device.info.mac: + connections = {(CONNECTION_NETWORK_MAC, self.device.info.mac)} + return DeviceInfo( + connections=connections, + identifiers={ # MAC address is not always available, and given the number # of non-conformant ONVIF devices we have historically supported, # we can not guarantee serial number either. Due to this, we have @@ -37,11 +37,8 @@ class ONVIFBaseEntity(Entity): # See: https://github.com/home-assistant/core/issues/35883 (DOMAIN, self.device.info.mac or self.device.info.serial_number) }, - } - - if self.device.info.mac: - device_info["connections"] = { - (CONNECTION_NETWORK_MAC, self.device.info.mac) - } - - return device_info + manufacturer=self.device.info.manufacturer, + model=self.device.info.model, + name=self.device.name, + sw_version=self.device.info.fw_version, + ) diff --git a/homeassistant/components/opentherm_gw/binary_sensor.py b/homeassistant/components/opentherm_gw/binary_sensor.py index a896b37a26b..81160729c4b 100644 --- a/homeassistant/components/opentherm_gw/binary_sensor.py +++ b/homeassistant/components/opentherm_gw/binary_sensor.py @@ -6,7 +6,7 @@ from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySenso from homeassistant.const import CONF_ID from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import async_generate_entity_id +from homeassistant.helpers.entity import DeviceInfo, async_generate_entity_id from homeassistant.helpers.entity_registry import async_get_registry from . import DOMAIN @@ -131,15 +131,15 @@ class OpenThermBinarySensor(BinarySensorEntity): return self._friendly_name @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device info.""" - return { - "identifiers": {(DOMAIN, self._gateway.gw_id)}, - "name": self._gateway.name, - "manufacturer": "Schelte Bron", - "model": "OpenTherm Gateway", - "sw_version": self._gateway.gw_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._gateway.gw_id)}, + manufacturer="Schelte Bron", + model="OpenTherm Gateway", + name=self._gateway.name, + sw_version=self._gateway.gw_version, + ) @property def unique_id(self): diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index 294088ee608..269a154dd6c 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -25,7 +25,7 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import async_generate_entity_id +from homeassistant.helpers.entity import DeviceInfo, async_generate_entity_id from . import DOMAIN from .const import ( @@ -171,15 +171,15 @@ class OpenThermClimate(ClimateEntity): return self.friendly_name @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device info.""" - return { - "identifiers": {(DOMAIN, self._gateway.gw_id)}, - "name": self._gateway.name, - "manufacturer": "Schelte Bron", - "model": "OpenTherm Gateway", - "sw_version": self._gateway.gw_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._gateway.gw_id)}, + manufacturer="Schelte Bron", + model="OpenTherm Gateway", + name=self._gateway.name, + sw_version=self._gateway.gw_version, + ) @property def unique_id(self): diff --git a/homeassistant/components/opentherm_gw/sensor.py b/homeassistant/components/opentherm_gw/sensor.py index 28f139f188f..a29dd319176 100644 --- a/homeassistant/components/opentherm_gw/sensor.py +++ b/homeassistant/components/opentherm_gw/sensor.py @@ -6,7 +6,7 @@ from homeassistant.components.sensor import ENTITY_ID_FORMAT, SensorEntity from homeassistant.const import CONF_ID from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect -from homeassistant.helpers.entity import async_generate_entity_id +from homeassistant.helpers.entity import DeviceInfo, async_generate_entity_id from homeassistant.helpers.entity_registry import async_get_registry from . import DOMAIN @@ -135,15 +135,15 @@ class OpenThermSensor(SensorEntity): return self._friendly_name @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return device info.""" - return { - "identifiers": {(DOMAIN, self._gateway.gw_id)}, - "name": self._gateway.name, - "manufacturer": "Schelte Bron", - "model": "OpenTherm Gateway", - "sw_version": self._gateway.gw_version, - } + return DeviceInfo( + identifiers={(DOMAIN, self._gateway.gw_id)}, + manufacturer="Schelte Bron", + model="OpenTherm Gateway", + name=self._gateway.name, + sw_version=self._gateway.gw_version, + ) @property def unique_id(self): diff --git a/homeassistant/components/openweathermap/sensor.py b/homeassistant/components/openweathermap/sensor.py index 6da352abf0a..13b282b5ef6 100644 --- a/homeassistant/components/openweathermap/sensor.py +++ b/homeassistant/components/openweathermap/sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.const import ATTR_ATTRIBUTION +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from .const import ( @@ -70,12 +71,12 @@ class AbstractOpenWeatherMapSensor(SensorEntity): self._attr_name = f"{name} {description.name}" self._attr_unique_id = unique_id split_unique_id = unique_id.split("-") - self._attr_device_info = { - "identifiers": {(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")}, - "name": DEFAULT_NAME, - "manufacturer": MANUFACTURER, - "entry_type": "service", - } + self._attr_device_info = DeviceInfo( + entry_type="service", + identifiers={(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")}, + manufacturer=MANUFACTURER, + name=DEFAULT_NAME, + ) @property def attribution(self): diff --git a/homeassistant/components/openweathermap/weather.py b/homeassistant/components/openweathermap/weather.py index ffd3e4b7269..f80566be329 100644 --- a/homeassistant/components/openweathermap/weather.py +++ b/homeassistant/components/openweathermap/weather.py @@ -1,6 +1,7 @@ """Support for the OpenWeatherMap (OWM) service.""" from homeassistant.components.weather import WeatherEntity from homeassistant.const import PRESSURE_HPA, PRESSURE_INHG, TEMP_CELSIUS +from homeassistant.helpers.entity import DeviceInfo from homeassistant.util.pressure import convert as pressure_convert from .const import ( @@ -58,14 +59,14 @@ class OpenWeatherMapWeather(WeatherEntity): return self._unique_id @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info.""" - return { - "identifiers": {(DOMAIN, self._unique_id)}, - "name": DEFAULT_NAME, - "manufacturer": MANUFACTURER, - "entry_type": "service", - } + return DeviceInfo( + entry_type="service", + identifiers={(DOMAIN, self._unique_id)}, + manufacturer=MANUFACTURER, + name=DEFAULT_NAME, + ) @property def should_poll(self): diff --git a/homeassistant/components/ovo_energy/__init__.py b/homeassistant/components/ovo_energy/__init__.py index f8c23b4f4f0..cb3fba80378 100644 --- a/homeassistant/components/ovo_energy/__init__.py +++ b/homeassistant/components/ovo_energy/__init__.py @@ -111,9 +111,9 @@ class OVOEnergyDeviceEntity(OVOEnergyEntity): @property def device_info(self) -> DeviceInfo: """Return device information about this OVO Energy instance.""" - return { - "identifiers": {(DOMAIN, self._client.account_id)}, - "manufacturer": "OVO Energy", - "name": self._client.username, - "entry_type": "service", - } + return DeviceInfo( + entry_type="service", + identifiers={(DOMAIN, self._client.account_id)}, + manufacturer="OVO Energy", + name=self._client.username, + ) diff --git a/homeassistant/components/owntracks/device_tracker.py b/homeassistant/components/owntracks/device_tracker.py index d50e5b9c414..7ba9346013f 100644 --- a/homeassistant/components/owntracks/device_tracker.py +++ b/homeassistant/components/owntracks/device_tracker.py @@ -13,6 +13,7 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers import device_registry +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.restore_state import RestoreEntity from . import DOMAIN as OT_DOMAIN @@ -117,9 +118,9 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity): return self._data.get("source_type", SOURCE_TYPE_GPS) @property - def device_info(self): + def device_info(self) -> DeviceInfo: """Return the device info.""" - return {"name": self.name, "identifiers": {(OT_DOMAIN, self._dev_id)}} + return DeviceInfo(identifiers={(OT_DOMAIN, self._dev_id)}, name=self.name) async def async_added_to_hass(self): """Call when entity about to be added to Home Assistant."""