Use DeviceInfo Class B-C (#58217)
This commit is contained in:
parent
059880ebdc
commit
137d41d8b4
13 changed files with 90 additions and 100 deletions
|
@ -10,7 +10,7 @@ from homeassistant.const import CONF_HOST, CONF_PORT
|
|||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DEFAULT_SETUP_TIMEOUT, DOMAIN, PRODUCT
|
||||
|
||||
|
@ -82,13 +82,13 @@ class BleBoxEntity(Entity):
|
|||
self._attr_name = feature.full_name
|
||||
self._attr_unique_id = feature.unique_id
|
||||
product = feature.product
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, product.unique_id)},
|
||||
"name": product.name,
|
||||
"manufacturer": product.brand,
|
||||
"model": product.model,
|
||||
"sw_version": product.firmware_version,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, product.unique_id)},
|
||||
manufacturer=product.brand,
|
||||
model=product.model,
|
||||
name=product.name,
|
||||
sw_version=product.firmware_version,
|
||||
)
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the entity state."""
|
||||
|
|
|
@ -21,7 +21,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry, discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
from homeassistant.helpers.event import track_utc_time_change
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import slugify
|
||||
|
@ -330,12 +330,12 @@ class BMWConnectedDriveBaseEntity(Entity):
|
|||
"vin": self._vehicle.vin,
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, vehicle.vin)},
|
||||
"name": f'{vehicle.attributes.get("brand")} {vehicle.name}',
|
||||
"model": vehicle.name,
|
||||
"manufacturer": vehicle.attributes.get("brand"),
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, vehicle.vin)},
|
||||
manufacturer=vehicle.attributes.get("brand"),
|
||||
model=vehicle.name,
|
||||
name=f'{vehicle.attributes.get("brand")} {vehicle.name}',
|
||||
)
|
||||
|
||||
def update_callback(self):
|
||||
"""Schedule a state update."""
|
||||
|
|
|
@ -30,9 +30,9 @@ class SHCEntity(Entity):
|
|||
self._attr_unique_id = device.serial
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, device.id)},
|
||||
name=device.name,
|
||||
manufacturer=device.manufacturer,
|
||||
model=device.device_model,
|
||||
name=device.name,
|
||||
via_device=(
|
||||
DOMAIN,
|
||||
device.parent_device_id
|
||||
|
|
|
@ -52,12 +52,12 @@ async def async_setup_entry(
|
|||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
unique_id = config_entry.unique_id
|
||||
assert unique_id is not None
|
||||
device_info: DeviceInfo = {
|
||||
"identifiers": {(DOMAIN, unique_id)},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": ATTR_MANUFACTURER,
|
||||
"model": config_entry.title,
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
manufacturer=ATTR_MANUFACTURER,
|
||||
model=config_entry.title,
|
||||
name=DEFAULT_NAME,
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
[BraviaTVMediaPlayer(coordinator, DEFAULT_NAME, unique_id, device_info)]
|
||||
|
|
|
@ -25,12 +25,12 @@ async def async_setup_entry(
|
|||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
unique_id = config_entry.unique_id
|
||||
assert unique_id is not None
|
||||
device_info: DeviceInfo = {
|
||||
"identifiers": {(DOMAIN, unique_id)},
|
||||
"name": DEFAULT_NAME,
|
||||
"manufacturer": ATTR_MANUFACTURER,
|
||||
"model": config_entry.title,
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
manufacturer=ATTR_MANUFACTURER,
|
||||
model=config_entry.title,
|
||||
name=DEFAULT_NAME,
|
||||
)
|
||||
|
||||
async_add_entities(
|
||||
[BraviaTVRemote(coordinator, DEFAULT_NAME, unique_id, device_info)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Broadlink entities."""
|
||||
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
@ -51,13 +51,13 @@ class BroadlinkEntity(Entity):
|
|||
return self._device.update_manager.available
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._device.unique_id)},
|
||||
"connections": {(dr.CONNECTION_NETWORK_MAC, self._device.mac_address)},
|
||||
"manufacturer": self._device.api.manufacturer,
|
||||
"model": self._device.api.model,
|
||||
"name": self._device.name,
|
||||
"sw_version": self._device.fw_version,
|
||||
}
|
||||
return DeviceInfo(
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, self._device.mac_address)},
|
||||
identifiers={(DOMAIN, self._device.unique_id)},
|
||||
manufacturer=self._device.api.manufacturer,
|
||||
model=self._device.api.model,
|
||||
name=self._device.name,
|
||||
sw_version=self._device.fw_version,
|
||||
)
|
||||
|
|
|
@ -20,16 +20,9 @@ from homeassistant.components.climate.const import (
|
|||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_TEMPERATURE,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import ATTR_TARGET_TEMPERATURE, DATA_BSBLAN_CLIENT, DOMAIN
|
||||
|
@ -98,12 +91,12 @@ class BSBLanClimate(ClimateEntity):
|
|||
self._store_hvac_mode = None
|
||||
self.bsblan = bsblan
|
||||
self._attr_name = self._attr_unique_id = info.device_identification
|
||||
self._attr_device_info = {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, info.device_identification)},
|
||||
ATTR_NAME: "BSBLan Device",
|
||||
ATTR_MANUFACTURER: "BSBLan",
|
||||
ATTR_MODEL: info.controller_variant,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, info.device_identification)},
|
||||
manufacturer="BSBLan",
|
||||
model=info.controller_variant,
|
||||
name="BSBLan Device",
|
||||
)
|
||||
|
||||
async def async_set_preset_mode(self, preset_mode):
|
||||
"""Set preset mode."""
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -100,12 +101,12 @@ class CanaryCamera(CoordinatorEntity, Camera):
|
|||
self._live_stream_session: LiveStreamSession | None = None
|
||||
self._attr_name = device.name
|
||||
self._attr_unique_id = str(device.device_id)
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, str(device.device_id))},
|
||||
"name": device.name,
|
||||
"model": device.device_type["name"],
|
||||
"manufacturer": MANUFACTURER,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, str(device.device_id))},
|
||||
manufacturer=MANUFACTURER,
|
||||
model=device.device_type["name"],
|
||||
name=device.name,
|
||||
)
|
||||
|
||||
@property
|
||||
def location(self) -> Location:
|
||||
|
|
|
@ -17,6 +17,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.update_coordinator import CoordinatorEntity
|
||||
|
||||
|
@ -114,12 +115,12 @@ class CanarySensor(CoordinatorEntity, SensorEntity):
|
|||
|
||||
self._canary_type = canary_sensor_type
|
||||
self._attr_unique_id = f"{device.device_id}_{sensor_type[0]}"
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, str(device.device_id))},
|
||||
"name": device.name,
|
||||
"model": device.device_type["name"],
|
||||
"manufacturer": MANUFACTURER,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, str(device.device_id))},
|
||||
model=device.device_type["name"],
|
||||
manufacturer=MANUFACTURER,
|
||||
name=device.name,
|
||||
)
|
||||
self._attr_native_unit_of_measurement = sensor_type[1]
|
||||
self._attr_device_class = sensor_type[3]
|
||||
self._attr_icon = sensor_type[2]
|
||||
|
|
|
@ -55,6 +55,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.logging import async_create_catching_coro
|
||||
|
@ -184,12 +185,12 @@ class CastDevice(MediaPlayerEntity):
|
|||
self._attr_unique_id = cast_info.uuid
|
||||
self._attr_name = cast_info.friendly_name
|
||||
if cast_info.model_name != "Google Cast Group":
|
||||
self._attr_device_info = {
|
||||
"name": str(cast_info.friendly_name),
|
||||
"identifiers": {(CAST_DOMAIN, str(cast_info.uuid).replace("-", ""))},
|
||||
"model": cast_info.model_name,
|
||||
"manufacturer": str(cast_info.manufacturer),
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(CAST_DOMAIN, str(cast_info.uuid).replace("-", ""))},
|
||||
manufacturer=str(cast_info.manufacturer),
|
||||
model=cast_info.model_name,
|
||||
name=str(cast_info.friendly_name),
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Create chromecast object when added to hass."""
|
||||
|
|
|
@ -357,10 +357,10 @@ class ClimaCellEntity(CoordinatorEntity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device registry information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._config_entry.data[CONF_API_KEY])},
|
||||
"name": "ClimaCell",
|
||||
"manufacturer": "ClimaCell",
|
||||
"sw_version": f"v{self.api_version}",
|
||||
"entry_type": "service",
|
||||
}
|
||||
return DeviceInfo(
|
||||
entry_type="service",
|
||||
identifiers={(DOMAIN, self._config_entry.data[CONF_API_KEY])},
|
||||
manufacturer="ClimaCell",
|
||||
name="ClimaCell",
|
||||
sw_version=f"v{self.api_version}",
|
||||
)
|
||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.components.climate.const import (
|
|||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import CONF_SUPPORTED_MODES, DATA_COORDINATOR, DATA_INFO, DOMAIN
|
||||
|
@ -73,15 +74,15 @@ class CoolmasterClimate(CoordinatorEntity, ClimateEntity):
|
|||
super()._handle_coordinator_update()
|
||||
|
||||
@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": "CoolAutomation",
|
||||
"model": "CoolMasterNet",
|
||||
"sw_version": self._info["version"],
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.unique_id)},
|
||||
manufacturer="CoolAutomation",
|
||||
model="CoolMasterNet",
|
||||
name=self.name,
|
||||
sw_version=self._info["version"],
|
||||
)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -3,13 +3,6 @@ from __future__ import annotations
|
|||
|
||||
from crownstone_cloud.cloud_models.crownstones import Crownstone
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_NAME,
|
||||
ATTR_SW_VERSION,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import CROWNSTONE_INCLUDE_TYPES, DOMAIN
|
||||
|
@ -36,10 +29,10 @@ class CrownstoneBaseEntity(Entity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device info."""
|
||||
return {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, self.cloud_id)},
|
||||
ATTR_NAME: self.device.name,
|
||||
ATTR_MANUFACTURER: "Crownstone",
|
||||
ATTR_MODEL: CROWNSTONE_INCLUDE_TYPES[self.device.type],
|
||||
ATTR_SW_VERSION: self.device.sw_version,
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.cloud_id)},
|
||||
manufacturer="Crownstone",
|
||||
model=CROWNSTONE_INCLUDE_TYPES[self.device.type],
|
||||
name=self.device.name,
|
||||
sw_version=self.device.sw_version,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue