Use DeviceInfo Class N-O (#58314)

This commit is contained in:
Robert Hillis 2021-10-24 05:34:45 -04:00 committed by GitHub
parent 0c94fcecf6
commit 2df13d0118
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 155 additions and 162 deletions

View file

@ -84,9 +84,9 @@ class NanoleafLight(LightEntity):
self._attr_name = self._nanoleaf.name self._attr_name = self._nanoleaf.name
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._nanoleaf.serial_no)}, identifiers={(DOMAIN, self._nanoleaf.serial_no)},
name=self._nanoleaf.name,
manufacturer=self._nanoleaf.manufacturer, manufacturer=self._nanoleaf.manufacturer,
model=self._nanoleaf.model, model=self._nanoleaf.model,
name=self._nanoleaf.name,
sw_version=self._nanoleaf.firmware_version, sw_version=self._nanoleaf.firmware_version,
) )
self._attr_min_mireds = math.ceil( self._attr_min_mireds = math.ceil(

View file

@ -132,7 +132,7 @@ class NeatoCleaningMap(Camera):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Device info for neato robot.""" """Device info for neato robot."""
return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}} return DeviceInfo(identifiers={(NEATO_DOMAIN, self._robot_serial)})
@property @property
def extra_state_attributes(self) -> dict[str, Any]: def extra_state_attributes(self) -> dict[str, Any]:

View file

@ -103,4 +103,4 @@ class NeatoSensor(SensorEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Device info for neato robot.""" """Device info for neato robot."""
return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}} return DeviceInfo(identifiers={(NEATO_DOMAIN, self._robot_serial)})

View file

@ -109,7 +109,7 @@ class NeatoConnectedSwitch(ToggleEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Device info for neato robot.""" """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: def turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""

View file

@ -338,15 +338,14 @@ class NeatoConnectedVacuum(StateVacuumEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Device info for neato robot.""" """Device info for neato robot."""
info: DeviceInfo = { stats = self._robot_stats
"identifiers": {(NEATO_DOMAIN, self._robot_serial)}, return DeviceInfo(
"name": self._name, identifiers={(NEATO_DOMAIN, self._robot_serial)},
} manufacturer=stats["battery"]["vendor"] if stats else None,
if self._robot_stats: model=stats["model"] if stats else None,
info["manufacturer"] = self._robot_stats["battery"]["vendor"] name=self._name,
info["model"] = self._robot_stats["model"] sw_version=stats["firmware"] if stats else None,
info["sw_version"] = self._robot_stats["firmware"] )
return info
def start(self) -> None: def start(self) -> None:
"""Start cleaning or resume cleaning.""" """Start cleaning or resume cleaning."""

View file

@ -30,13 +30,11 @@ class NestDeviceInfo:
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return device specific attributes.""" """Return device specific attributes."""
return DeviceInfo( return DeviceInfo(
{
# The API "name" field is a unique device identifier. # The API "name" field is a unique device identifier.
"identifiers": {(DOMAIN, self._device.name)}, identifiers={(DOMAIN, self._device.name)},
"name": self.device_name, manufacturer=self.device_brand,
"manufacturer": self.device_brand, model=self.device_model,
"model": self.device_model, name=self.device_name,
}
) )
@property @property
@ -45,7 +43,7 @@ class NestDeviceInfo:
if InfoTrait.NAME in self._device.traits: if InfoTrait.NAME in self._device.traits:
trait: InfoTrait = self._device.traits[InfoTrait.NAME] trait: InfoTrait = self._device.traits[InfoTrait.NAME]
if trait.custom_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 # Build a name from the room/structure. Note: This room/structure name
# is not associated with a home assistant Area. # is not associated with a home assistant Area.
if parent_relations := self._device.parent_relations: if parent_relations := self._device.parent_relations:

View file

@ -21,7 +21,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send 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 . import local_auth
from .const import DATA_NEST, DATA_NEST_CONFIG, DOMAIN, SIGNAL_NEST_UPDATE 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}" return f"{self.device.serial}-{self.variable}"
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return information about the device.""" """Return information about the device."""
if not hasattr(self.device, "name_long"): if not hasattr(self.device, "name_long"):
name = self.structure.name name = self.structure.name
@ -393,12 +393,12 @@ class NestSensorDevice(Entity):
else: else:
model = None model = None
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device.serial)}, identifiers={(DOMAIN, self.device.serial)},
"name": name, manufacturer="Nest Labs",
"manufacturer": "Nest Labs", model=model,
"model": model, name=name,
} )
def update(self): def update(self):
"""Do not use NestSensorDevice directly.""" """Do not use NestSensorDevice directly."""

View file

@ -7,6 +7,7 @@ import logging
import requests import requests
from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_ON_OFF, Camera from homeassistant.components.camera import PLATFORM_SCHEMA, SUPPORT_ON_OFF, Camera
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
from .const import DATA_NEST, DOMAIN from .const import DATA_NEST, DOMAIN
@ -61,14 +62,14 @@ class NestCamera(Camera):
return self.device.device_id return self.device.device_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return information about the device.""" """Return information about the device."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device.device_id)}, identifiers={(DOMAIN, self.device.device_id)},
"name": self.device.name_long, manufacturer="Nest Labs",
"manufacturer": "Nest Labs", model="Camera",
"model": "Camera", name=self.device.name_long,
} )
@property @property
def should_poll(self): def should_poll(self):

View file

@ -32,6 +32,7 @@ from homeassistant.const import (
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
) )
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
from .const import DATA_NEST, DOMAIN, SIGNAL_NEST_UPDATE from .const import DATA_NEST, DOMAIN, SIGNAL_NEST_UPDATE
@ -166,15 +167,15 @@ class NestThermostat(ClimateEntity):
return self.device.serial return self.device.serial
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return information about the device.""" """Return information about the device."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device.device_id)}, identifiers={(DOMAIN, self.device.device_id)},
"name": self.device.name_long, manufacturer="Nest Labs",
"manufacturer": "Nest Labs", model="Thermostat",
"model": "Thermostat", name=self.device.name_long,
"sw_version": self.device.software_version, sw_version=self.device.software_version,
} )
@property @property
def name(self): def name(self):

View file

@ -1,7 +1,7 @@
"""The nexia integration base entity.""" """The nexia integration base entity."""
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ( from .const import (
@ -11,6 +11,7 @@ from .const import (
SIGNAL_THERMOSTAT_UPDATE, SIGNAL_THERMOSTAT_UPDATE,
SIGNAL_ZONE_UPDATE, SIGNAL_ZONE_UPDATE,
) )
from .coordinator import NexiaDataUpdateCoordinator
class NexiaEntity(CoordinatorEntity): class NexiaEntity(CoordinatorEntity):
@ -49,16 +50,17 @@ class NexiaThermostatEntity(NexiaEntity):
self._thermostat = thermostat self._thermostat = thermostat
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device_info of the device.""" """Return the device_info of the device."""
return { assert isinstance(self.coordinator, NexiaDataUpdateCoordinator)
"identifiers": {(DOMAIN, self._thermostat.thermostat_id)}, return DeviceInfo(
"name": self._thermostat.get_name(), configuration_url=self.coordinator.nexia_home.root_url,
"model": self._thermostat.get_model(), identifiers={(DOMAIN, self._thermostat.thermostat_id)},
"sw_version": self._thermostat.get_firmware(), manufacturer=MANUFACTURER,
"manufacturer": MANUFACTURER, model=self._thermostat.get_model(),
"configuration_url": self.coordinator.nexia_home.root_url, name=self._thermostat.get_name(),
} sw_version=self._thermostat.get_firmware(),
)
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Listen for signals for services.""" """Listen for signals for services."""

View file

@ -172,11 +172,11 @@ class NmapTrackerEntity(ScannerEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return the device information.""" """Return the device information."""
return { return DeviceInfo(
"connections": {(CONNECTION_NETWORK_MAC, self._mac_address)}, connections={(CONNECTION_NETWORK_MAC, self._mac_address)},
"default_manufacturer": self._device.manufacturer, default_manufacturer=self._device.manufacturer,
"default_name": self.name, default_name=self.name,
} )
@property @property
def should_poll(self) -> bool: def should_poll(self) -> bool:

View file

@ -5,12 +5,8 @@ import logging
from homeassistant.components.nut import PyNUTData from homeassistant.components.nut import PyNUTData
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.const import ( from homeassistant.const import CONF_RESOURCES, STATE_UNKNOWN
ATTR_IDENTIFIERS, from homeassistant.helpers.entity import DeviceInfo
ATTR_NAME,
CONF_RESOURCES,
STATE_UNKNOWN,
)
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
@ -81,10 +77,10 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
self._attr_entity_registry_enabled_default = enabled_default self._attr_entity_registry_enabled_default = enabled_default
self._attr_name = f"{device_name} {sensor_description.name}" self._attr_name = f"{device_name} {sensor_description.name}"
self._attr_unique_id = f"{unique_id}_{sensor_description.key}" self._attr_unique_id = f"{unique_id}_{sensor_description.key}"
self._attr_device_info = { self._attr_device_info = DeviceInfo(
ATTR_IDENTIFIERS: {(DOMAIN, unique_id)}, identifiers={(DOMAIN, unique_id)},
ATTR_NAME: device_name, name=device_name,
} )
self._attr_device_info.update(data.device_info) self._attr_device_info.update(data.device_info)
@property @property

View file

@ -12,6 +12,7 @@ from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import debounce from homeassistant.helpers import debounce
from homeassistant.helpers.aiohttp_client import async_get_clientsession 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.event import async_track_point_in_utc_time
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util.dt import utcnow from homeassistant.util.dt import utcnow
@ -168,11 +169,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return unload_ok return unload_ok
def device_info(latitude, longitude): def device_info(latitude, longitude) -> DeviceInfo:
"""Return device registry information.""" """Return device registry information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, base_unique_id(latitude, longitude))}, entry_type="service",
"name": f"NWS: {latitude}, {longitude}", identifiers={(DOMAIN, base_unique_id(latitude, longitude))},
"manufacturer": "National Weather Service", manufacturer="National Weather Service",
"entry_type": "service", name=f"NWS: {latitude}, {longitude}",
} )

View file

@ -6,13 +6,8 @@ import logging
from omnilogic import OmniLogic, OmniLogicException from omnilogic import OmniLogic, OmniLogicException
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
@ -152,15 +147,14 @@ class OmniLogicEntity(CoordinatorEntity):
return self._attrs return self._attrs
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Define the device as back yard/MSP System.""" """Define the device as back yard/MSP System."""
return DeviceInfo(
return { identifiers={(DOMAIN, self._msp_system_id)},
ATTR_IDENTIFIERS: {(DOMAIN, self._msp_system_id)}, manufacturer="Hayward",
ATTR_NAME: self._backyard_name, model="OmniLogic",
ATTR_MANUFACTURER: "Hayward", name=self._backyard_name,
ATTR_MODEL: "OmniLogic", )
}
def check_guard(state_key, item, entity_setting): def check_guard(state_key, item, entity_setting):

View file

@ -16,6 +16,7 @@ from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
@ -169,13 +170,13 @@ class OndiloICO(CoordinatorEntity, SensorEntity):
return self._devdata()["value"] return self._devdata()["value"]
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info for the sensor.""" """Return the device info for the sensor."""
pooldata = self._pooldata() pooldata = self._pooldata()
return { return DeviceInfo(
"identifiers": {(DOMAIN, pooldata["ICO"]["serial_number"])}, identifiers={(DOMAIN, pooldata["ICO"]["serial_number"])},
"name": self._device_name, manufacturer="Ondilo",
"manufacturer": "Ondilo", model="ICO",
"model": "ICO", name=self._device_name,
"sw_version": pooldata["ICO"]["sw_version"], sw_version=pooldata["ICO"]["sw_version"],
} )

View file

@ -1,6 +1,6 @@
"""Base classes for ONVIF entities.""" """Base classes for ONVIF entities."""
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC 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 .const import DOMAIN
from .device import ONVIFDevice from .device import ONVIFDevice
@ -21,14 +21,14 @@ class ONVIFBaseEntity(Entity):
return self.device.available return self.device.available
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return a device description for device registry.""" """Return a device description for device registry."""
device_info = { connections = None
"manufacturer": self.device.info.manufacturer, if self.device.info.mac:
"model": self.device.info.model, connections = {(CONNECTION_NETWORK_MAC, self.device.info.mac)}
"name": self.device.name, return DeviceInfo(
"sw_version": self.device.info.fw_version, connections=connections,
"identifiers": { identifiers={
# MAC address is not always available, and given the number # MAC address is not always available, and given the number
# of non-conformant ONVIF devices we have historically supported, # of non-conformant ONVIF devices we have historically supported,
# we can not guarantee serial number either. Due to this, we have # 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 # See: https://github.com/home-assistant/core/issues/35883
(DOMAIN, self.device.info.mac or self.device.info.serial_number) (DOMAIN, self.device.info.mac or self.device.info.serial_number)
}, },
} manufacturer=self.device.info.manufacturer,
model=self.device.info.model,
if self.device.info.mac: name=self.device.name,
device_info["connections"] = { sw_version=self.device.info.fw_version,
(CONNECTION_NETWORK_MAC, self.device.info.mac) )
}
return device_info

View file

@ -6,7 +6,7 @@ from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySenso
from homeassistant.const import CONF_ID from homeassistant.const import CONF_ID
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect 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 homeassistant.helpers.entity_registry import async_get_registry
from . import DOMAIN from . import DOMAIN
@ -131,15 +131,15 @@ class OpenThermBinarySensor(BinarySensorEntity):
return self._friendly_name return self._friendly_name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device info.""" """Return device info."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._gateway.gw_id)}, identifiers={(DOMAIN, self._gateway.gw_id)},
"name": self._gateway.name, manufacturer="Schelte Bron",
"manufacturer": "Schelte Bron", model="OpenTherm Gateway",
"model": "OpenTherm Gateway", name=self._gateway.name,
"sw_version": self._gateway.gw_version, sw_version=self._gateway.gw_version,
} )
@property @property
def unique_id(self): def unique_id(self):

View file

@ -25,7 +25,7 @@ from homeassistant.const import (
) )
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect 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 . import DOMAIN
from .const import ( from .const import (
@ -171,15 +171,15 @@ class OpenThermClimate(ClimateEntity):
return self.friendly_name return self.friendly_name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device info.""" """Return device info."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._gateway.gw_id)}, identifiers={(DOMAIN, self._gateway.gw_id)},
"name": self._gateway.name, manufacturer="Schelte Bron",
"manufacturer": "Schelte Bron", model="OpenTherm Gateway",
"model": "OpenTherm Gateway", name=self._gateway.name,
"sw_version": self._gateway.gw_version, sw_version=self._gateway.gw_version,
} )
@property @property
def unique_id(self): def unique_id(self):

View file

@ -6,7 +6,7 @@ from homeassistant.components.sensor import ENTITY_ID_FORMAT, SensorEntity
from homeassistant.const import CONF_ID from homeassistant.const import CONF_ID
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect 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 homeassistant.helpers.entity_registry import async_get_registry
from . import DOMAIN from . import DOMAIN
@ -135,15 +135,15 @@ class OpenThermSensor(SensorEntity):
return self._friendly_name return self._friendly_name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device info.""" """Return device info."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._gateway.gw_id)}, identifiers={(DOMAIN, self._gateway.gw_id)},
"name": self._gateway.name, manufacturer="Schelte Bron",
"manufacturer": "Schelte Bron", model="OpenTherm Gateway",
"model": "OpenTherm Gateway", name=self._gateway.name,
"sw_version": self._gateway.gw_version, sw_version=self._gateway.gw_version,
} )
@property @property
def unique_id(self): def unique_id(self):

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import ( from .const import (
@ -70,12 +71,12 @@ class AbstractOpenWeatherMapSensor(SensorEntity):
self._attr_name = f"{name} {description.name}" self._attr_name = f"{name} {description.name}"
self._attr_unique_id = unique_id self._attr_unique_id = unique_id
split_unique_id = unique_id.split("-") split_unique_id = unique_id.split("-")
self._attr_device_info = { self._attr_device_info = DeviceInfo(
"identifiers": {(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")}, entry_type="service",
"name": DEFAULT_NAME, identifiers={(DOMAIN, f"{split_unique_id[0]}-{split_unique_id[1]}")},
"manufacturer": MANUFACTURER, manufacturer=MANUFACTURER,
"entry_type": "service", name=DEFAULT_NAME,
} )
@property @property
def attribution(self): def attribution(self):

View file

@ -1,6 +1,7 @@
"""Support for the OpenWeatherMap (OWM) service.""" """Support for the OpenWeatherMap (OWM) service."""
from homeassistant.components.weather import WeatherEntity from homeassistant.components.weather import WeatherEntity
from homeassistant.const import PRESSURE_HPA, PRESSURE_INHG, TEMP_CELSIUS 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 homeassistant.util.pressure import convert as pressure_convert
from .const import ( from .const import (
@ -58,14 +59,14 @@ class OpenWeatherMapWeather(WeatherEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info.""" """Return the device info."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._unique_id)}, entry_type="service",
"name": DEFAULT_NAME, identifiers={(DOMAIN, self._unique_id)},
"manufacturer": MANUFACTURER, manufacturer=MANUFACTURER,
"entry_type": "service", name=DEFAULT_NAME,
} )
@property @property
def should_poll(self): def should_poll(self):

View file

@ -111,9 +111,9 @@ class OVOEnergyDeviceEntity(OVOEnergyEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return device information about this OVO Energy instance.""" """Return device information about this OVO Energy instance."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._client.account_id)}, entry_type="service",
"manufacturer": "OVO Energy", identifiers={(DOMAIN, self._client.account_id)},
"name": self._client.username, manufacturer="OVO Energy",
"entry_type": "service", name=self._client.username,
} )

View file

@ -13,6 +13,7 @@ from homeassistant.const import (
) )
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers import device_registry from homeassistant.helpers import device_registry
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.restore_state import RestoreEntity
from . import DOMAIN as OT_DOMAIN from . import DOMAIN as OT_DOMAIN
@ -117,9 +118,9 @@ class OwnTracksEntity(TrackerEntity, RestoreEntity):
return self._data.get("source_type", SOURCE_TYPE_GPS) return self._data.get("source_type", SOURCE_TYPE_GPS)
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info.""" """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): async def async_added_to_hass(self):
"""Call when entity about to be added to Home Assistant.""" """Call when entity about to be added to Home Assistant."""