Use DeviceInfo on components with via_device (H) (#58211)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
c00a5fad8f
commit
58c5b5058c
11 changed files with 108 additions and 97 deletions
|
@ -9,6 +9,7 @@ from homeassistant.components.binary_sensor import (
|
|||
DEVICE_CLASS_SOUND,
|
||||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import HiveEntity
|
||||
from .const import ATTR_MODE, DOMAIN
|
||||
|
@ -46,16 +47,16 @@ class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device["device_id"])},
|
||||
"name": self.device["device_name"],
|
||||
"model": self.device["deviceData"]["model"],
|
||||
"manufacturer": self.device["deviceData"]["manufacturer"],
|
||||
"sw_version": self.device["deviceData"]["version"],
|
||||
"via_device": (DOMAIN, self.device["parentDevice"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
name=self.device["device_name"],
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
|
|
|
@ -19,6 +19,7 @@ from homeassistant.components.climate.const import (
|
|||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import HiveEntity, refresh_system
|
||||
from .const import (
|
||||
|
@ -117,16 +118,16 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device["device_id"])},
|
||||
"name": self.device["device_name"],
|
||||
"model": self.device["deviceData"]["model"],
|
||||
"manufacturer": self.device["deviceData"]["manufacturer"],
|
||||
"sw_version": self.device["deviceData"]["version"],
|
||||
"via_device": (DOMAIN, self.device["parentDevice"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
name=self.device["device_name"],
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
|
|
@ -10,6 +10,7 @@ from homeassistant.components.light import (
|
|||
SUPPORT_COLOR_TEMP,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
from . import HiveEntity, refresh_system
|
||||
|
@ -40,16 +41,16 @@ class HiveDeviceLight(HiveEntity, LightEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device["device_id"])},
|
||||
"name": self.device["device_name"],
|
||||
"model": self.device["deviceData"]["model"],
|
||||
"manufacturer": self.device["deviceData"]["manufacturer"],
|
||||
"sw_version": self.device["deviceData"]["version"],
|
||||
"via_device": (DOMAIN, self.device["parentDevice"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
name=self.device["device_name"],
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.sensor import DEVICE_CLASS_BATTERY, SensorEntity
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import HiveEntity
|
||||
from .const import DOMAIN
|
||||
|
@ -35,16 +36,16 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device["device_id"])},
|
||||
"name": self.device["device_name"],
|
||||
"model": self.device["deviceData"]["model"],
|
||||
"manufacturer": self.device["deviceData"]["manufacturer"],
|
||||
"sw_version": self.device["deviceData"]["version"],
|
||||
"via_device": (DOMAIN, self.device["parentDevice"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
name=self.device["device_name"],
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
"""Support for the Hive switches."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import HiveEntity, refresh_system
|
||||
from .const import ATTR_MODE, DOMAIN
|
||||
|
@ -31,17 +34,18 @@ class HiveDevicePlug(HiveEntity, SwitchEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return device information."""
|
||||
if self.device["hiveType"] == "activeplug":
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device["device_id"])},
|
||||
"name": self.device["device_name"],
|
||||
"model": self.device["deviceData"]["model"],
|
||||
"manufacturer": self.device["deviceData"]["manufacturer"],
|
||||
"sw_version": self.device["deviceData"]["version"],
|
||||
"via_device": (DOMAIN, self.device["parentDevice"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
name=self.device["device_name"],
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
return None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -13,6 +13,7 @@ from homeassistant.components.water_heater import (
|
|||
)
|
||||
from homeassistant.const import TEMP_CELSIUS
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from . import HiveEntity, refresh_system
|
||||
from .const import (
|
||||
|
@ -78,16 +79,16 @@ class HiveWaterHeater(HiveEntity, WaterHeaterEntity):
|
|||
return self._unique_id
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device["device_id"])},
|
||||
"name": self.device["device_name"],
|
||||
"model": self.device["deviceData"]["model"],
|
||||
"manufacturer": self.device["deviceData"]["manufacturer"],
|
||||
"sw_version": self.device["deviceData"]["version"],
|
||||
"via_device": (DOMAIN, self.device["parentDevice"]),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device["device_id"])},
|
||||
name=self.device["device_name"],
|
||||
model=self.device["deviceData"]["model"],
|
||||
manufacturer=self.device["deviceData"]["manufacturer"],
|
||||
sw_version=self.device["deviceData"]["version"],
|
||||
via_device=(DOMAIN, self.device["parentDevice"]),
|
||||
)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
|
|
@ -47,13 +47,13 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device specific attributes."""
|
||||
return {
|
||||
"identifiers": {(HMIPC_DOMAIN, f"ACP {self._home.id}")},
|
||||
"name": self.name,
|
||||
"manufacturer": "eQ-3",
|
||||
"model": CONST_ALARM_CONTROL_PANEL_NAME,
|
||||
"via_device": (HMIPC_DOMAIN, self._home.id),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(HMIPC_DOMAIN, f"ACP {self._home.id}")},
|
||||
name=self.name,
|
||||
manufacturer="eQ-3",
|
||||
model=CONST_ALARM_CONTROL_PANEL_NAME,
|
||||
via_device=(HMIPC_DOMAIN, self._home.id),
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
|
|
|
@ -76,13 +76,13 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device specific attributes."""
|
||||
return {
|
||||
"identifiers": {(HMIPC_DOMAIN, self._device.id)},
|
||||
"name": self._device.label,
|
||||
"manufacturer": "eQ-3",
|
||||
"model": self._device.modelType,
|
||||
"via_device": (HMIPC_DOMAIN, self._device.homeId),
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(HMIPC_DOMAIN, self._device.id)},
|
||||
name=self._device.label,
|
||||
manufacturer="eQ-3",
|
||||
model=self._device.modelType,
|
||||
via_device=(HMIPC_DOMAIN, self._device.homeId),
|
||||
)
|
||||
|
||||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
|
|
|
@ -96,18 +96,18 @@ class HomematicipGenericEntity(Entity):
|
|||
"""Return device specific attributes."""
|
||||
# Only physical devices should be HA devices.
|
||||
if isinstance(self._device, AsyncDevice):
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# Serial numbers of Homematic IP device
|
||||
(HMIPC_DOMAIN, self._device.id)
|
||||
},
|
||||
"name": self._device.label,
|
||||
"manufacturer": self._device.oem,
|
||||
"model": self._device.modelType,
|
||||
"sw_version": self._device.firmwareVersion,
|
||||
name=self._device.label,
|
||||
manufacturer=self._device.oem,
|
||||
model=self._device.modelType,
|
||||
sw_version=self._device.firmwareVersion,
|
||||
# Link to the homematic ip access point.
|
||||
"via_device": (HMIPC_DOMAIN, self._device.homeId),
|
||||
}
|
||||
via_device=(HMIPC_DOMAIN, self._device.homeId),
|
||||
)
|
||||
return None
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
|
|
|
@ -40,19 +40,19 @@ class GenericHueDevice(entity.Entity):
|
|||
return self.primary_sensor.raw.get("swupdate", {}).get("state")
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> entity.DeviceInfo:
|
||||
"""Return the device info.
|
||||
|
||||
Links individual entities together in the hass device registry.
|
||||
"""
|
||||
return {
|
||||
"identifiers": {(HUE_DOMAIN, self.device_id)},
|
||||
"name": self.primary_sensor.name,
|
||||
"manufacturer": self.primary_sensor.manufacturername,
|
||||
"model": (self.primary_sensor.productname or self.primary_sensor.modelid),
|
||||
"sw_version": self.primary_sensor.swversion,
|
||||
"via_device": (HUE_DOMAIN, self.bridge.api.config.bridgeid),
|
||||
}
|
||||
return entity.DeviceInfo(
|
||||
identifiers={(HUE_DOMAIN, self.device_id)},
|
||||
name=self.primary_sensor.name,
|
||||
manufacturer=self.primary_sensor.manufacturername,
|
||||
model=(self.primary_sensor.productname or self.primary_sensor.modelid),
|
||||
sw_version=self.primary_sensor.swversion,
|
||||
via_device=(HUE_DOMAIN, self.bridge.api.config.bridgeid),
|
||||
)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle entity being added to Home Assistant."""
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
from aiopvapi.resources.shade import ATTR_TYPE
|
||||
|
||||
from homeassistant.const import ATTR_MODEL, ATTR_SW_VERSION
|
||||
import homeassistant.helpers.device_registry as dr
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
|
@ -63,21 +65,21 @@ class ShadeEntity(HDEntity):
|
|||
self._shade = shade
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device_info of the device."""
|
||||
|
||||
device_info = {
|
||||
"identifiers": {(DOMAIN, self._shade.id)},
|
||||
"name": self._shade_name,
|
||||
"suggested_area": self._room_name,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"model": str(self._shade.raw_data[ATTR_TYPE]),
|
||||
"via_device": (DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]),
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self._shade.id)},
|
||||
name=self._shade_name,
|
||||
suggested_area=self._room_name,
|
||||
manufacturer=MANUFACTURER,
|
||||
model=str(self._shade.raw_data[ATTR_TYPE]),
|
||||
via_device=(DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]),
|
||||
)
|
||||
|
||||
for shade in self._shade.shade_types:
|
||||
if shade.shade_type == device_info["model"]:
|
||||
device_info["model"] = shade.description
|
||||
if shade.shade_type == device_info[ATTR_MODEL]:
|
||||
device_info[ATTR_MODEL] = shade.description
|
||||
break
|
||||
|
||||
if FIRMWARE not in self._shade.raw_data:
|
||||
|
@ -86,6 +88,6 @@ class ShadeEntity(HDEntity):
|
|||
firmware = self._shade.raw_data[FIRMWARE]
|
||||
sw_version = f"{firmware[FIRMWARE_REVISION]}.{firmware[FIRMWARE_SUB_REVISION]}.{firmware[FIRMWARE_BUILD]}"
|
||||
|
||||
device_info["sw_version"] = sw_version
|
||||
device_info[ATTR_SW_VERSION] = sw_version
|
||||
|
||||
return device_info
|
||||
|
|
Loading…
Add table
Reference in a new issue