1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Use DeviceInfo Class I-K (#58300)

This commit is contained in:
Robert Hillis 2021-10-23 14:42:50 -04:00 committed by GitHub
parent b52c5c82b1
commit 05671557f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 114 additions and 129 deletions

View File

@ -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):

View File

@ -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),
)

View File

@ -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."""

View File

@ -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:

View File

@ -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)),
)

View File

@ -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):

View File

@ -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:

View File

@ -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,
)

View File

@ -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."""

View File

@ -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,
)

View File

@ -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."""

View File

@ -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):

View File

@ -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):

View File

@ -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."""

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -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."""

View File

@ -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):