Use DeviceInfo object s-x (#96281)
* Use DeviceInfo object o-x * Use DeviceInfo object
This commit is contained in:
parent
f25d5a157a
commit
2f6826dbe3
8 changed files with 43 additions and 24 deletions
|
@ -15,6 +15,7 @@ from homeassistant.components.binary_sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
|
@ -112,7 +113,9 @@ class SFRBoxBinarySensor(
|
|||
self._attr_unique_id = (
|
||||
f"{system_info.mac_addr}_{coordinator.name}_{description.key}"
|
||||
)
|
||||
self._attr_device_info = {"identifiers": {(DOMAIN, system_info.mac_addr)}}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -100,7 +101,9 @@ class SFRBoxButton(ButtonEntity):
|
|||
self.entity_description = description
|
||||
self._box = box
|
||||
self._attr_unique_id = f"{system_info.mac_addr}_{description.key}"
|
||||
self._attr_device_info = {"identifiers": {(DOMAIN, system_info.mac_addr)}}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
|
||||
@with_error_wrapping
|
||||
async def async_press(self) -> None:
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
@ -252,7 +253,9 @@ class SFRBoxSensor(CoordinatorEntity[SFRDataUpdateCoordinator[_T]], SensorEntity
|
|||
self._attr_unique_id = (
|
||||
f"{system_info.mac_addr}_{coordinator.name}_{description.key}"
|
||||
)
|
||||
self._attr_device_info = {"identifiers": {(DOMAIN, system_info.mac_addr)}}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
|
|
|
@ -254,7 +254,9 @@ class BlockSleepingClimate(
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Device info."""
|
||||
return {"connections": {(CONNECTION_NETWORK_MAC, self.coordinator.mac)}}
|
||||
return DeviceInfo(
|
||||
connections={(CONNECTION_NETWORK_MAC, self.coordinator.mac)},
|
||||
)
|
||||
|
||||
def _check_is_off(self) -> bool:
|
||||
"""Return if valve is off or on."""
|
||||
|
|
|
@ -39,6 +39,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
@ -411,9 +412,12 @@ class TraccarEntity(TrackerEntity, RestoreEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info."""
|
||||
return {"name": self._name, "identifiers": {(DOMAIN, self._unique_id)}}
|
||||
return DeviceInfo(
|
||||
name=self._name,
|
||||
identifiers={(DOMAIN, self._unique_id)},
|
||||
)
|
||||
|
||||
@property
|
||||
def source_type(self) -> SourceType:
|
||||
|
|
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import update_coordinator
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import _LOGGER, DOMAIN, VENSTAR_SLEEP, VENSTAR_TIMEOUT
|
||||
|
@ -143,12 +144,12 @@ class VenstarEntity(CoordinatorEntity[VenstarDataUpdateCoordinator]):
|
|||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information for this entity."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._config.entry_id)},
|
||||
"name": self._client.name,
|
||||
"manufacturer": "Venstar",
|
||||
"model": f"{self._client.model}-{self._client.get_type()}",
|
||||
"sw_version": self._client.get_api_ver(),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._config.entry_id)},
|
||||
name=self._client.name,
|
||||
manufacturer="Venstar",
|
||||
model=f"{self._client.model}-{self._client.get_type()}",
|
||||
sw_version=self._client.get_api_ver(),
|
||||
)
|
||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
from homeassistant.helpers.entity import generate_entity_id
|
||||
from homeassistant.helpers.entity import DeviceInfo, generate_entity_id
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import DOMAIN
|
||||
|
@ -64,19 +64,19 @@ class VulcanCalendarEntity(CalendarEntity):
|
|||
self._unique_id = f"vulcan_calendar_{self.student_info['id']}"
|
||||
self._attr_name = f"Vulcan calendar - {self.student_info['full_name']}"
|
||||
self._attr_unique_id = f"vulcan_calendar_{self.student_info['id']}"
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, f"calendar_{self.student_info['id']}")},
|
||||
"entry_type": DeviceEntryType.SERVICE,
|
||||
"name": f"{self.student_info['full_name']}: Calendar",
|
||||
"model": (
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, f"calendar_{self.student_info['id']}")},
|
||||
entry_type=DeviceEntryType.SERVICE,
|
||||
name=f"{self.student_info['full_name']}: Calendar",
|
||||
model=(
|
||||
f"{self.student_info['full_name']} -"
|
||||
f" {self.student_info['class']} {self.student_info['school']}"
|
||||
),
|
||||
"manufacturer": "Uonet +",
|
||||
"configuration_url": (
|
||||
manufacturer="Uonet +",
|
||||
configuration_url=(
|
||||
f"https://uonetplus.vulcan.net.pl/{self.student_info['symbol']}"
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def event(self) -> CalendarEvent | None:
|
||||
|
|
|
@ -42,6 +42,7 @@ from homeassistant.const import (
|
|||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
|
@ -997,7 +998,9 @@ class XiaomiGatewayIlluminanceSensor(SensorEntity):
|
|||
"""Initialize the entity."""
|
||||
self._attr_name = f"{gateway_name} {description.name}"
|
||||
self._attr_unique_id = f"{gateway_device_id}-{description.key}"
|
||||
self._attr_device_info = {"identifiers": {(DOMAIN, gateway_device_id)}}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, gateway_device_id)},
|
||||
)
|
||||
self._gateway = gateway_device
|
||||
self.entity_description = description
|
||||
self._available = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue