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