Use DeviceInfo Class H (#58276)

This commit is contained in:
Robert Hillis 2021-10-23 09:35:33 -04:00 committed by GitHub
parent f176dc512c
commit 4a8e9df026
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 110 additions and 103 deletions

View file

@ -10,6 +10,7 @@ import aioharmony.exceptions as aioexc
from aioharmony.harmonyapi import HarmonyAPI as HarmonyClient
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.entity import DeviceInfo
from .const import ACTIVITY_POWER_OFF
from .subscriber import HarmonySubscriberMixin
@ -82,20 +83,20 @@ class HarmonyData(HarmonySubscriberMixin):
"""Return the current activity tuple."""
return self._client.current_activity
def device_info(self, domain: str):
def device_info(self, domain: str) -> DeviceInfo:
"""Return hub device info."""
model = "Harmony Hub"
if "ethernetStatus" in self._client.hub_config.info:
model = "Harmony Hub Pro 2400"
return {
"identifiers": {(domain, self.unique_id)},
"manufacturer": "Logitech",
"sw_version": self._client.hub_config.info.get(
return DeviceInfo(
identifiers={(domain, self.unique_id)},
manufacturer="Logitech",
model=model,
name=self.name,
sw_version=self._client.hub_config.info.get(
"hubSwVersion", self._client.fw_version
),
"name": self.name,
"model": model,
}
)
async def connect(self) -> bool:
"""Connect to the Harmony Hub."""

View file

@ -4,7 +4,7 @@ from __future__ import annotations
from typing import Any
from homeassistant.const import ATTR_NAME
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import DOMAIN, HassioDataUpdateCoordinator
@ -26,7 +26,7 @@ class HassioAddonEntity(CoordinatorEntity):
self._addon_slug = addon[ATTR_SLUG]
self._attr_name = f"{addon[ATTR_NAME]}: {entity_description.name}"
self._attr_unique_id = f"{addon[ATTR_SLUG]}_{entity_description.key}"
self._attr_device_info = {"identifiers": {(DOMAIN, addon[ATTR_SLUG])}}
self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, addon[ATTR_SLUG])})
class HassioOSEntity(CoordinatorEntity):
@ -42,4 +42,4 @@ class HassioOSEntity(CoordinatorEntity):
self.entity_description = entity_description
self._attr_name = f"Home Assistant Operating System: {entity_description.name}"
self._attr_unique_id = f"home_assistant_os_{entity_description.key}"
self._attr_device_info = {"identifiers": {(DOMAIN, "OS")}}
self._attr_device_info = DeviceInfo(identifiers={(DOMAIN, "OS")})

View file

@ -255,13 +255,13 @@ class HeosMediaPlayer(MediaPlayerEntity):
@property
def device_info(self) -> DeviceInfo:
"""Get attributes about the device."""
return {
"identifiers": {(HEOS_DOMAIN, self._player.player_id)},
"name": self._player.name,
"model": self._player.model,
"manufacturer": "HEOS",
"sw_version": self._player.version,
}
return DeviceInfo(
identifiers={(HEOS_DOMAIN, self._player.player_id)},
manufacturer="HEOS",
model=self._player.model,
name=self._player.name,
sw_version=self._player.version,
)
@property
def extra_state_attributes(self) -> dict:

View file

@ -51,9 +51,9 @@ class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
name=self.device["device_name"],
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)

View file

@ -122,9 +122,9 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
name=self.device["device_name"],
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)

View file

@ -45,9 +45,9 @@ class HiveDeviceLight(HiveEntity, LightEntity):
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
name=self.device["device_name"],
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)

View file

@ -40,9 +40,9 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
name=self.device["device_name"],
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)

View file

@ -39,9 +39,9 @@ class HiveDevicePlug(HiveEntity, SwitchEntity):
if self.device["hiveType"] == "activeplug":
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
name=self.device["device_name"],
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)

View file

@ -83,9 +83,9 @@ class HiveWaterHeater(HiveEntity, WaterHeaterEntity):
"""Return device information."""
return DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
name=self.device["device_name"],
model=self.device["deviceData"]["model"],
manufacturer=self.device["deviceData"]["manufacturer"],
model=self.device["deviceData"]["model"],
name=self.device["device_name"],
sw_version=self.device["deviceData"]["version"],
via_device=(DOMAIN, self.device["parentDevice"]),
)

View file

@ -4,7 +4,7 @@ import logging
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity import DeviceInfo, Entity
from .api import HomeConnectDevice
from .const import DOMAIN, SIGNAL_UPDATE_ENTITIES
@ -51,14 +51,14 @@ class HomeConnectEntity(Entity):
return f"{self.device.appliance.haId}-{self.desc}"
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return info about the device."""
return {
"identifiers": {(DOMAIN, self.device.appliance.haId)},
"name": self.device.appliance.name,
"manufacturer": self.device.appliance.brand,
"model": self.device.appliance.vib,
}
return DeviceInfo(
identifiers={(DOMAIN, self.device.appliance.haId)},
manufacturer=self.device.appliance.brand,
model=self.device.appliance.vib,
name=self.device.appliance.name,
)
@callback
def async_entity_update(self):

View file

@ -8,6 +8,7 @@ from homeassistant.components.switch import (
)
from homeassistant.core import callback
from homeassistant.helpers import dispatcher
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DISPATCHER_REMOVERS, DOMAIN, HW_TYPE, SIGNAL_ADD_ENTITIES
@ -79,18 +80,18 @@ class HomeControlSwitchEntity(CoordinatorEntity, SwitchEntity):
return self.idx
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Device information."""
return {
"identifiers": {
return DeviceInfo(
identifiers={
# Unique identifiers within the domain
(DOMAIN, self.unique_id)
},
"name": self.name,
"manufacturer": "Legrand",
"model": HW_TYPE.get(self.module.hw_type),
"sw_version": self.module.fw,
}
manufacturer="Legrand",
model=HW_TYPE.get(self.module.hw_type),
name=self.name,
sw_version=self.module.fw,
)
@property
def device_class(self):

View file

@ -152,9 +152,9 @@ class HomeKitEntity(Entity):
device_info = DeviceInfo(
identifiers={(DOMAIN, "serial-number", accessory_serial)},
name=info.value(CharacteristicsTypes.NAME),
manufacturer=info.value(CharacteristicsTypes.MANUFACTURER, ""),
model=info.value(CharacteristicsTypes.MODEL, ""),
name=info.value(CharacteristicsTypes.NAME),
sw_version=info.value(CharacteristicsTypes.FIRMWARE_REVISION, ""),
)

View file

@ -49,9 +49,9 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
"""Return device specific attributes."""
return DeviceInfo(
identifiers={(HMIPC_DOMAIN, f"ACP {self._home.id}")},
name=self.name,
manufacturer="eQ-3",
model=CONST_ALARM_CONTROL_PANEL_NAME,
name=self.name,
via_device=(HMIPC_DOMAIN, self._home.id),
)

View file

@ -172,12 +172,12 @@ class HomematicipCloudConnectionSensor(HomematicipGenericEntity, BinarySensorEnt
def device_info(self) -> DeviceInfo:
"""Return device specific attributes."""
# Adds a sensor to the existing HAP device
return {
"identifiers": {
return DeviceInfo(
identifiers={
# Serial numbers of Homematic IP device
(HMIPC_DOMAIN, self._home.id)
}
}
)
@property
def icon(self) -> str:

View file

@ -78,9 +78,9 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
"""Return device specific attributes."""
return DeviceInfo(
identifiers={(HMIPC_DOMAIN, self._device.id)},
name=self._device.label,
manufacturer="eQ-3",
model=self._device.modelType,
name=self._device.label,
via_device=(HMIPC_DOMAIN, self._device.homeId),
)

View file

@ -101,9 +101,9 @@ class HomematicipGenericEntity(Entity):
# Serial numbers of Homematic IP device
(HMIPC_DOMAIN, self._device.id)
},
name=self._device.label,
manufacturer=self._device.oem,
model=self._device.modelType,
name=self._device.label,
sw_version=self._device.firmwareVersion,
# Link to the homematic ip access point.
via_device=(HMIPC_DOMAIN, self._device.homeId),

View file

@ -651,10 +651,10 @@ class HuaweiLteBaseEntity(Entity):
@property
def device_info(self) -> DeviceInfo:
"""Get info for matching with parent router."""
return {
"identifiers": self.router.device_identifiers,
"connections": self.router.device_connections,
}
return DeviceInfo(
connections=self.router.device_connections,
identifiers=self.router.device_identifiers,
)
async def async_update(self) -> None:
"""Update state."""

View file

@ -1,4 +1,6 @@
"""Support for the Philips Hue lights."""
from __future__ import annotations
from datetime import timedelta
from functools import partial
import logging
@ -29,6 +31,7 @@ from homeassistant.components.light import (
from homeassistant.core import callback
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.debounce import Debouncer
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -431,7 +434,7 @@ class HueLight(CoordinatorEntity, LightEntity):
return [EFFECT_COLORLOOP, EFFECT_RANDOM]
@property
def device_info(self):
def device_info(self) -> DeviceInfo | None:
"""Return the device info."""
if self.light.type in (
GROUP_TYPE_LIGHT_GROUP,
@ -441,22 +444,22 @@ class HueLight(CoordinatorEntity, LightEntity):
):
return None
info = {
"identifiers": {(HUE_DOMAIN, self.device_id)},
"name": self.name,
"manufacturer": self.light.manufacturername,
suggested_area = None
if self.light.id in self._rooms:
suggested_area = self._rooms[self.light.id]
return DeviceInfo(
identifiers={(HUE_DOMAIN, self.device_id)},
manufacturer=self.light.manufacturername,
# productname added in Hue Bridge API 1.24
# (published 03/05/2018)
"model": self.light.productname or self.light.modelid,
model=self.light.productname or self.light.modelid,
name=self.name,
# Not yet exposed as properties in aiohue
"sw_version": self.light.raw["swversion"],
"via_device": (HUE_DOMAIN, self.bridge.api.config.bridgeid),
}
if self.light.id in self._rooms:
info["suggested_area"] = self._rooms[self.light.id]
return info
suggested_area=suggested_area,
sw_version=self.light.raw["swversion"],
via_device=(HUE_DOMAIN, self.bridge.api.config.bridgeid),
)
async def async_added_to_hass(self) -> None:
"""Handle entity being added to Home Assistant."""

View file

@ -47,9 +47,9 @@ class GenericHueDevice(entity.Entity):
"""
return entity.DeviceInfo(
identifiers={(HUE_DOMAIN, self.device_id)},
name=self.primary_sensor.name,
manufacturer=self.primary_sensor.manufacturername,
model=(self.primary_sensor.productname or self.primary_sensor.modelid),
name=self.primary_sensor.name,
sw_version=self.primary_sensor.swversion,
via_device=(HUE_DOMAIN, self.bridge.api.config.bridgeid),
)

View file

@ -43,15 +43,15 @@ class HDEntity(CoordinatorEntity):
firmware = self._device_info[DEVICE_FIRMWARE]
sw_version = f"{firmware[FIRMWARE_REVISION]}.{firmware[FIRMWARE_SUB_REVISION]}.{firmware[FIRMWARE_BUILD]}"
return DeviceInfo(
identifiers={(DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER])},
connections={
(dr.CONNECTION_NETWORK_MAC, self._device_info[DEVICE_MAC_ADDRESS])
},
identifiers={(DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER])},
manufacturer=MANUFACTURER,
model=self._device_info[DEVICE_MODEL],
name=self._device_info[DEVICE_NAME],
suggested_area=self._room_name,
model=self._device_info[DEVICE_MODEL],
sw_version=sw_version,
manufacturer=MANUFACTURER,
)

View file

@ -11,6 +11,7 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity,
)
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -145,8 +146,8 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
@property
def device_info(self):
"""Return the device info for this sensor."""
return {
"identifiers": {
return DeviceInfo(
identifiers={
(
DOMAIN,
self.config_entry.entry_id,
@ -154,9 +155,9 @@ class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity):
self.config_entry.data[CONF_STATION]["type"],
)
},
"name": f"Departures at {self.config_entry.data[CONF_STATION]['name']}",
"manufacturer": MANUFACTURER,
}
manufacturer=MANUFACTURER,
name=f"Departures at {self.config_entry.data[CONF_STATION]['name']}",
)
@property
def name(self):

View file

@ -8,6 +8,7 @@ from pygti.exceptions import InvalidAuth
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_ID, DEVICE_CLASS_TIMESTAMP
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util import Throttle
from homeassistant.util.dt import get_time_zone, utcnow
@ -158,8 +159,8 @@ class HVVDepartureSensor(SensorEntity):
@property
def device_info(self):
"""Return the device info for this sensor."""
return {
"identifiers": {
return DeviceInfo(
identifiers={
(
DOMAIN,
self.config_entry.entry_id,
@ -167,9 +168,9 @@ class HVVDepartureSensor(SensorEntity):
self.config_entry.data[CONF_STATION]["type"],
)
},
"name": self._name,
"manufacturer": MANUFACTURER,
}
manufacturer=MANUFACTURER,
name=self._name,
)
@property
def name(self):

View file

@ -249,12 +249,12 @@ class HyperionCamera(Camera):
@property
def device_info(self) -> DeviceInfo:
"""Return device information."""
return {
"identifiers": {(DOMAIN, self._device_id)},
"name": self._instance_name,
"manufacturer": HYPERION_MANUFACTURER_NAME,
"model": HYPERION_MODEL_NAME,
}
return DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer=HYPERION_MANUFACTURER_NAME,
model=HYPERION_MODEL_NAME,
name=self._instance_name,
)
CAMERA_TYPES = {

View file

@ -240,12 +240,12 @@ class HyperionBaseLight(LightEntity):
@property
def device_info(self) -> DeviceInfo:
"""Return device information."""
return {
"identifiers": {(DOMAIN, self._device_id)},
"name": self._instance_name,
"manufacturer": HYPERION_MANUFACTURER_NAME,
"model": HYPERION_MODEL_NAME,
}
return DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer=HYPERION_MANUFACTURER_NAME,
model=HYPERION_MODEL_NAME,
name=self._instance_name,
)
def _get_option(self, key: str) -> Any:
"""Get a value from the provided options."""

View file

@ -185,12 +185,12 @@ class HyperionComponentSwitch(SwitchEntity):
@property
def device_info(self) -> DeviceInfo:
"""Return device information."""
return {
"identifiers": {(DOMAIN, self._device_id)},
"name": self._instance_name,
"manufacturer": HYPERION_MANUFACTURER_NAME,
"model": HYPERION_MODEL_NAME,
}
return DeviceInfo(
identifiers={(DOMAIN, self._device_id)},
manufacturer=HYPERION_MANUFACTURER_NAME,
model=HYPERION_MODEL_NAME,
name=self._instance_name,
)
async def _async_send_set_component(self, value: bool) -> None:
"""Send a component control request."""