Use DeviceInfo Class D (#58218)
parent
59fe30e589
commit
fc3e7f5b7e
|
@ -13,6 +13,7 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
from .const import CONF_UUID, DOMAIN, KEY_MAC, TIMEOUT
|
||||
|
@ -109,13 +110,13 @@ class DaikinApi:
|
|||
return self._available
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return a device description for device registry."""
|
||||
info = self.device.values
|
||||
return {
|
||||
"connections": {(CONNECTION_NETWORK_MAC, self.device.mac)},
|
||||
"manufacturer": "Daikin",
|
||||
"model": info.get("model"),
|
||||
"name": info.get("name"),
|
||||
"sw_version": info.get("ver", "").replace("_", "."),
|
||||
}
|
||||
return DeviceInfo(
|
||||
connections={(CONNECTION_NETWORK_MAC, self.device.mac)},
|
||||
manufacturer="Daikin",
|
||||
model=info.get("model"),
|
||||
name=info.get("name"),
|
||||
sw_version=info.get("ver", "").replace("_", "."),
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@ from homeassistant.components.binary_sensor import (
|
|||
DEVICE_CLASS_MOTION,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
@ -38,15 +39,15 @@ class DemoBinarySensor(BinarySensorEntity):
|
|||
self._sensor_type = device_class
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
"name": self.name,
|
||||
}
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.components.climate.const import (
|
|||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
@ -154,15 +155,15 @@ class DemoClimate(ClimateEntity):
|
|||
self._target_temperature_low = target_temp_low
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
"name": self.name,
|
||||
}
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -11,6 +11,7 @@ from homeassistant.components.cover import (
|
|||
CoverEntity,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.event import async_track_utc_time_change
|
||||
|
||||
from . import DOMAIN
|
||||
|
@ -86,15 +87,15 @@ class DemoCover(CoverEntity):
|
|||
self._closed = self.current_cover_position <= 0
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
"name": self.name,
|
||||
}
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.components.light import (
|
|||
SUPPORT_EFFECT,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
@ -138,15 +139,15 @@ class DemoLight(LightEntity):
|
|||
self._features |= SUPPORT_EFFECT
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
"name": self.name,
|
||||
}
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
|
|
|
@ -6,6 +6,7 @@ from typing import Literal
|
|||
from homeassistant.components.number import NumberEntity
|
||||
from homeassistant.components.number.const import MODE_AUTO, MODE_BOX, MODE_SLIDER
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
@ -95,15 +96,15 @@ class DemoNumber(NumberEntity):
|
|||
self._attr_step = step
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers are unique identifiers within a specific domain
|
||||
(DOMAIN, self.unique_id)
|
||||
},
|
||||
"name": self.name,
|
||||
}
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
async def async_set_value(self, value):
|
||||
"""Update the current value."""
|
||||
|
|
|
@ -5,6 +5,7 @@ from homeassistant.components.select import SelectEntity
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
|
@ -66,10 +67,10 @@ class DemoSelect(SelectEntity):
|
|||
self._attr_icon = icon
|
||||
self._attr_device_class = device_class
|
||||
self._attr_options = options
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, unique_id)},
|
||||
"name": name,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
name=name,
|
||||
)
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Update the current selected option."""
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, StateType
|
||||
|
||||
|
@ -125,10 +126,10 @@ class DemoSensor(SensorEntity):
|
|||
self._attr_state_class = state_class
|
||||
self._attr_unique_id = unique_id
|
||||
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, unique_id)},
|
||||
"name": name,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
name=name,
|
||||
)
|
||||
|
||||
if battery:
|
||||
self._attr_extra_state_attributes = {ATTR_BATTERY_LEVEL: battery}
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.const import DEVICE_DEFAULT_NAME
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import DOMAIN
|
||||
|
||||
|
@ -52,12 +53,12 @@ class DemoSwitch(SwitchEntity):
|
|||
self._attr_unique_id = unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.unique_id)},
|
||||
"name": self.name,
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the switch on."""
|
||||
|
|
|
@ -148,11 +148,11 @@ class DenonDevice(MediaPlayerEntity):
|
|||
self._attr_name = receiver.name
|
||||
self._attr_unique_id = unique_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
configuration_url=f"http://{config_entry.data[CONF_HOST]}/",
|
||||
identifiers={(DOMAIN, config_entry.unique_id)},
|
||||
manufacturer=config_entry.data[CONF_MANUFACTURER],
|
||||
name=config_entry.title,
|
||||
model=f"{config_entry.data[CONF_MODEL]}-{config_entry.data[CONF_TYPE]}",
|
||||
configuration_url=f"http://{config_entry.data[CONF_HOST]}/",
|
||||
name=config_entry.title,
|
||||
)
|
||||
self._attr_sound_mode_list = receiver.sound_mode_list
|
||||
self._attr_source_list = receiver.input_func_list
|
||||
|
|
|
@ -6,7 +6,7 @@ import logging
|
|||
from devolo_home_control_api.devices.zwave import Zwave
|
||||
from devolo_home_control_api.homecontrol import HomeControl
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .subscriber import Subscriber
|
||||
|
@ -32,15 +32,15 @@ class DevoloDeviceEntity(Entity):
|
|||
].name
|
||||
self._attr_should_poll = False
|
||||
self._attr_unique_id = element_uid
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, self._device_instance.uid)},
|
||||
"name": self._attr_name,
|
||||
"manufacturer": device_instance.brand,
|
||||
"model": device_instance.name,
|
||||
"suggested_area": device_instance.settings_property[
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_instance.uid)},
|
||||
manufacturer=device_instance.brand,
|
||||
model=device_instance.name,
|
||||
name=self._attr_name,
|
||||
suggested_area=device_instance.settings_property[
|
||||
"general_device_settings"
|
||||
].zone,
|
||||
}
|
||||
)
|
||||
|
||||
self.subscriber: Subscriber | None = None
|
||||
self.sync_callback = self._sync
|
||||
|
|
|
@ -23,9 +23,8 @@ class DIRECTVEntity(Entity):
|
|||
"""Return device information about this DirecTV receiver."""
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
name=self.name,
|
||||
manufacturer=self.dtv.device.info.brand,
|
||||
model=None,
|
||||
name=self.name,
|
||||
sw_version=self.dtv.device.info.version,
|
||||
via_device=(DOMAIN, self.dtv.device.info.receiver_id),
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""The DoorBird integration base entity."""
|
||||
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import (
|
||||
DOORBIRD_INFO_KEY_BUILD_NUMBER,
|
||||
|
@ -23,14 +23,14 @@ class DoorBirdEntity(Entity):
|
|||
self._mac_addr = get_mac_address_from_doorstation_info(doorstation_info)
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Doorbird device info."""
|
||||
firmware = self._doorstation_info[DOORBIRD_INFO_KEY_FIRMWARE]
|
||||
firmware_build = self._doorstation_info[DOORBIRD_INFO_KEY_BUILD_NUMBER]
|
||||
return {
|
||||
"connections": {(dr.CONNECTION_NETWORK_MAC, self._mac_addr)},
|
||||
"name": self._doorstation.name,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"sw_version": f"{firmware} {firmware_build}",
|
||||
"model": self._doorstation_info[DOORBIRD_INFO_KEY_DEVICE_TYPE],
|
||||
}
|
||||
return DeviceInfo(
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, self._mac_addr)},
|
||||
manufacturer=MANUFACTURER,
|
||||
model=self._doorstation_info[DOORBIRD_INFO_KEY_DEVICE_TYPE],
|
||||
name=self._doorstation.name,
|
||||
sw_version=f"{firmware} {firmware_build}",
|
||||
)
|
||||
|
|
|
@ -24,6 +24,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import CoreState, HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, EventType, StateType
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -230,10 +231,10 @@ class DSMREntity(SensorEntity):
|
|||
if device_serial is None:
|
||||
device_serial = entry.entry_id
|
||||
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, device_serial)},
|
||||
"name": device_name,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device_serial)},
|
||||
name=device_name,
|
||||
)
|
||||
self._attr_unique_id = f"{device_serial}_{entity_description.name}".replace(
|
||||
" ", "_"
|
||||
)
|
||||
|
|
|
@ -131,11 +131,11 @@ class DuneHDPlayerEntity(MediaPlayerEntity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._unique_id)},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": ATTR_MANUFACTURER,
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._unique_id)},
|
||||
manufacturer=ATTR_MANUFACTURER,
|
||||
name=DEFAULT_NAME,
|
||||
)
|
||||
|
||||
@property
|
||||
def volume_level(self) -> float:
|
||||
|
|
|
@ -64,11 +64,11 @@ class DynaliteBase(Entity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Device info for this entity."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._device.unique_id)},
|
||||
"name": self.name,
|
||||
"manufacturer": "Dynalite",
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device.unique_id)},
|
||||
manufacturer="Dynalite",
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Added to hass so need to register to dispatch."""
|
||||
|
|
Loading…
Reference in New Issue