Use DeviceInfo Class E (#58230)

pull/58280/head
Robert Hillis 2021-10-23 05:44:51 -04:00 committed by GitHub
parent 137d41d8b4
commit 12c067970a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 111 additions and 99 deletions

View File

@ -8,6 +8,7 @@ import async_timeout
from homeassistant.components.sensor import SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_METERS
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -121,13 +122,13 @@ class Measurement(CoordinatorEntity, SensorEntity):
@property
def device_info(self):
"""Return the device info."""
return {
"identifiers": {(DOMAIN, "measure-id", self.station_id)},
"name": self.name,
"manufacturer": "https://environment.data.gov.uk/",
"model": self.parameter_name,
"entry_type": "service",
}
return DeviceInfo(
entry_type="service",
identifiers={(DOMAIN, "measure-id", self.station_id)},
manufacturer="https://environment.data.gov.uk/",
model=self.parameter_name,
name=self.name,
)
@property
def available(self) -> bool:

View File

@ -1,8 +1,11 @@
"""Support for Ecobee binary sensors."""
from __future__ import annotations
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_OCCUPANCY,
BinarySensorEntity,
)
from homeassistant.helpers.entity import DeviceInfo
from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
@ -49,7 +52,7 @@ class EcobeeBinarySensor(BinarySensorEntity):
return f"{thermostat['identifier']}-{sensor['id']}-{self.device_class}"
@property
def device_info(self):
def device_info(self) -> DeviceInfo | None:
"""Return device information for this sensor."""
identifier = None
model = None
@ -72,12 +75,12 @@ class EcobeeBinarySensor(BinarySensorEntity):
break
if identifier is not None:
return {
"identifiers": {(DOMAIN, identifier)},
"name": self.sensor_name,
"manufacturer": MANUFACTURER,
"model": model,
}
return DeviceInfo(
identifiers={(DOMAIN, identifier)},
manufacturer=MANUFACTURER,
model=model,
name=self.sensor_name,
)
return None
@property

View File

@ -38,6 +38,7 @@ from homeassistant.const import (
)
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util.temperature import convert
from .const import _LOGGER, DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
@ -366,20 +367,21 @@ class Thermostat(ClimateEntity):
return self.thermostat["identifier"]
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return device information for this ecobee thermostat."""
model: str | None
try:
model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat"
except KeyError:
# Ecobee model is not in our list
model = None
return {
"identifiers": {(DOMAIN, self.thermostat["identifier"])},
"name": self.name,
"manufacturer": MANUFACTURER,
"model": model,
}
return DeviceInfo(
identifiers={(DOMAIN, self.thermostat["identifier"])},
manufacturer=MANUFACTURER,
model=model,
name=self.name,
)
@property
def temperature_unit(self):

View File

@ -1,4 +1,6 @@
"""Support for using humidifier with ecobee thermostats."""
from __future__ import annotations
from datetime import timedelta
from homeassistant.components.humidifier import HumidifierEntity
@ -9,6 +11,7 @@ from homeassistant.components.humidifier.const import (
MODE_AUTO,
SUPPORT_MODES,
)
from homeassistant.helpers.entity import DeviceInfo
from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
@ -54,20 +57,21 @@ class EcobeeHumidifier(HumidifierEntity):
return f"{self.thermostat['identifier']}"
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return device information for the ecobee humidifier."""
model: str | None
try:
model = f"{ECOBEE_MODEL_TO_NAME[self.thermostat['modelNumber']]} Thermostat"
except KeyError:
# Ecobee model is not in our list
model = None
return {
"identifiers": {(DOMAIN, self.thermostat["identifier"])},
"name": self.name,
"manufacturer": MANUFACTURER,
"model": model,
}
return DeviceInfo(
identifiers={(DOMAIN, self.thermostat["identifier"])},
manufacturer=MANUFACTURER,
model=model,
name=self.name,
)
@property
def available(self):

View File

@ -14,6 +14,7 @@ from homeassistant.const import (
PERCENTAGE,
TEMP_FAHRENHEIT,
)
from homeassistant.helpers.entity import DeviceInfo
from .const import DOMAIN, ECOBEE_MODEL_TO_NAME, MANUFACTURER
@ -76,7 +77,7 @@ class EcobeeSensor(SensorEntity):
return f"{thermostat['identifier']}-{sensor['id']}-{self.device_class}"
@property
def device_info(self):
def device_info(self) -> DeviceInfo | None:
"""Return device information for this sensor."""
identifier = None
model = None
@ -99,12 +100,12 @@ class EcobeeSensor(SensorEntity):
break
if identifier is not None and model is not None:
return {
"identifiers": {(DOMAIN, identifier)},
"name": self.sensor_name,
"manufacturer": MANUFACTURER,
"model": model,
}
return DeviceInfo(
identifiers={(DOMAIN, identifier)},
manufacturer=MANUFACTURER,
model=model,
name=self.sensor_name,
)
return None
@property

View File

@ -1,4 +1,6 @@
"""Support for displaying weather info from Ecobee API."""
from __future__ import annotations
from datetime import timedelta
from pyecobee.const import ECOBEE_STATE_UNKNOWN
@ -13,6 +15,7 @@ from homeassistant.components.weather import (
WeatherEntity,
)
from homeassistant.const import PRESSURE_HPA, PRESSURE_INHG, TEMP_FAHRENHEIT
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.util import dt as dt_util
from homeassistant.util.pressure import convert as pressure_convert
@ -65,21 +68,22 @@ class EcobeeWeather(WeatherEntity):
return self.data.ecobee.get_thermostat(self._index)["identifier"]
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return device information for the ecobee weather platform."""
thermostat = self.data.ecobee.get_thermostat(self._index)
model: str | None
try:
model = f"{ECOBEE_MODEL_TO_NAME[thermostat['modelNumber']]} Thermostat"
except KeyError:
# Ecobee model is not in our list
model = None
return {
"identifiers": {(DOMAIN, thermostat["identifier"])},
"name": self.name,
"manufacturer": MANUFACTURER,
"model": model,
}
return DeviceInfo(
identifiers={(DOMAIN, thermostat["identifier"])},
manufacturer=MANUFACTURER,
model=model,
name=self.name,
)
@property
def condition(self):

View File

@ -16,7 +16,7 @@ from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, TEMP_FAHRENHEIT
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.dispatcher import dispatcher_send
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.event import async_track_time_interval
from .const import API_CLIENT, DOMAIN, EQUIPMENT
@ -128,13 +128,13 @@ class EcoNetEntity(Entity):
return self._econet.connected
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return device registry information for this entity."""
return {
"identifiers": {(DOMAIN, self._econet.device_id)},
"manufacturer": "Rheem",
"name": self._econet.device_name,
}
return DeviceInfo(
identifiers={(DOMAIN, self._econet.device_id)},
manufacturer="Rheem",
name=self._econet.device_name,
)
@property
def name(self):

View File

@ -16,13 +16,6 @@ from homeassistant.components.light import (
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_MODEL,
ATTR_NAME,
ATTR_SW_VERSION,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import (
@ -187,13 +180,13 @@ class ElgatoLight(LightEntity):
@property
def device_info(self) -> DeviceInfo:
"""Return device information about this Elgato Light."""
return {
ATTR_IDENTIFIERS: {(DOMAIN, self._info.serial_number)},
ATTR_NAME: self._info.product_name,
ATTR_MANUFACTURER: "Elgato",
ATTR_MODEL: self._info.product_name,
ATTR_SW_VERSION: f"{self._info.firmware_version} ({self._info.firmware_build_number})",
}
return DeviceInfo(
identifiers={(DOMAIN, self._info.serial_number)},
manufacturer="Elgato",
model=self._info.product_name,
name=self._info.product_name,
sw_version=f"{self._info.firmware_version} ({self._info.firmware_build_number})",
)
async def async_identify(self) -> None:
"""Identify the light, will make it blink."""

View File

@ -463,15 +463,15 @@ class ElkAttachedEntity(ElkEntity):
"""An elk entity that is attached to the elk system."""
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Device info for the underlying ElkM1 system."""
device_name = "ElkM1"
if self._prefix:
device_name += f" {self._prefix}"
return {
"name": device_name,
"identifiers": {(DOMAIN, f"{self._prefix}_system")},
"sw_version": self._elk.panel.elkm1_version,
"manufacturer": "ELK Products, Inc.",
"model": "M1",
}
return DeviceInfo(
identifiers={(DOMAIN, f"{self._prefix}_system")},
manufacturer="ELK Products, Inc.",
model="M1",
name=device_name,
sw_version=self._elk.panel.elkm1_version,
)

View File

@ -94,9 +94,9 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
@property
def device_info(self) -> DeviceInfo:
"""Return info about the emonitor device."""
return {
"name": name_short_mac(self.mac_address[-6:]),
"connections": {(dr.CONNECTION_NETWORK_MAC, self.mac_address)},
"manufacturer": "Powerhouse Dynamics, Inc.",
"sw_version": self.coordinator.data.hardware.firmware_version,
}
return DeviceInfo(
connections={(dr.CONNECTION_NETWORK_MAC, self.mac_address)},
manufacturer="Powerhouse Dynamics, Inc.",
name=name_short_mac(self.mac_address[-6:]),
sw_version=self.coordinator.data.hardware.firmware_version,
)

View File

@ -15,6 +15,7 @@ from homeassistant.const import (
CONF_USERNAME,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import COORDINATOR, DOMAIN, NAME, SENSORS
@ -169,13 +170,13 @@ class Envoy(CoordinatorEntity, SensorEntity):
return None
@property
def device_info(self):
def device_info(self) -> DeviceInfo:
"""Return the device_info of the device."""
if not self._device_serial_number:
return None
return {
"identifiers": {(DOMAIN, str(self._device_serial_number))},
"name": self._device_name,
"model": "Envoy",
"manufacturer": "Enphase",
}
return DeviceInfo(
identifiers={(DOMAIN, str(self._device_serial_number))},
manufacturer="Enphase",
model="Envoy",
name=self._device_name,
)

View File

@ -1,4 +1,6 @@
"""Support for Epson projector."""
from __future__ import annotations
import logging
from epson_projector.const import (
@ -39,6 +41,7 @@ from homeassistant.components.media_player.const import (
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_registry import async_get as async_get_entity_registry
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
@ -137,17 +140,17 @@ class EpsonProjectorMediaPlayer(MediaPlayerEntity):
self._state = STATE_OFF
@property
def device_info(self):
def device_info(self) -> DeviceInfo | None:
"""Get attributes about the device."""
if not self._unique_id:
return None
return {
"identifiers": {(DOMAIN, self._unique_id)},
"manufacturer": "Epson",
"name": "Epson projector",
"model": "Epson",
"via_hub": (DOMAIN, self._unique_id),
}
return DeviceInfo(
identifiers={(DOMAIN, self._unique_id)},
manufacturer="Epson",
model="Epson",
name="Epson projector",
via_device=(DOMAIN, self._unique_id),
)
@property
def name(self):

View File

@ -22,13 +22,13 @@ class EzvizEntity(CoordinatorEntity, Entity):
super().__init__(coordinator)
self._serial = serial
self._camera_name = self.data["name"]
self._attr_device_info: DeviceInfo = {
"identifiers": {(DOMAIN, serial)},
"name": self.data["name"],
"model": self.data["device_sub_category"],
"manufacturer": MANUFACTURER,
"sw_version": self.data["version"],
}
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, serial)},
manufacturer=MANUFACTURER,
model=self.data["device_sub_category"],
name=self.data["name"],
sw_version=self.data["version"],
)
@property
def data(self) -> dict[str, Any]: