Use DeviceInfo on components with via_device (H) (#58211)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-10-22 11:52:48 +02:00 committed by GitHub
parent c00a5fad8f
commit 58c5b5058c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 108 additions and 97 deletions

View file

@ -9,6 +9,7 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_SOUND, DEVICE_CLASS_SOUND,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.helpers.entity import DeviceInfo
from . import HiveEntity from . import HiveEntity
from .const import ATTR_MODE, DOMAIN from .const import ATTR_MODE, DOMAIN
@ -46,16 +47,16 @@ class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device information.""" """Return device information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device["device_id"])}, identifiers={(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"], name=self.device["device_name"],
"model": self.device["deviceData"]["model"], model=self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"], manufacturer=self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"], sw_version=self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]), via_device=(DOMAIN, self.device["parentDevice"]),
} )
@property @property
def device_class(self): def device_class(self):

View file

@ -19,6 +19,7 @@ from homeassistant.components.climate.const import (
) )
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity import DeviceInfo
from . import HiveEntity, refresh_system from . import HiveEntity, refresh_system
from .const import ( from .const import (
@ -117,16 +118,16 @@ class HiveClimateEntity(HiveEntity, ClimateEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device information.""" """Return device information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device["device_id"])}, identifiers={(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"], name=self.device["device_name"],
"model": self.device["deviceData"]["model"], model=self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"], manufacturer=self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"], sw_version=self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]), via_device=(DOMAIN, self.device["parentDevice"]),
} )
@property @property
def supported_features(self): def supported_features(self):

View file

@ -10,6 +10,7 @@ from homeassistant.components.light import (
SUPPORT_COLOR_TEMP, SUPPORT_COLOR_TEMP,
LightEntity, LightEntity,
) )
from homeassistant.helpers.entity import DeviceInfo
import homeassistant.util.color as color_util import homeassistant.util.color as color_util
from . import HiveEntity, refresh_system from . import HiveEntity, refresh_system
@ -40,16 +41,16 @@ class HiveDeviceLight(HiveEntity, LightEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device information.""" """Return device information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device["device_id"])}, identifiers={(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"], name=self.device["device_name"],
"model": self.device["deviceData"]["model"], model=self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"], manufacturer=self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"], sw_version=self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]), via_device=(DOMAIN, self.device["parentDevice"]),
} )
@property @property
def name(self): def name(self):

View file

@ -3,6 +3,7 @@
from datetime import timedelta from datetime import timedelta
from homeassistant.components.sensor import DEVICE_CLASS_BATTERY, SensorEntity from homeassistant.components.sensor import DEVICE_CLASS_BATTERY, SensorEntity
from homeassistant.helpers.entity import DeviceInfo
from . import HiveEntity from . import HiveEntity
from .const import DOMAIN from .const import DOMAIN
@ -35,16 +36,16 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device information.""" """Return device information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device["device_id"])}, identifiers={(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"], name=self.device["device_name"],
"model": self.device["deviceData"]["model"], model=self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"], manufacturer=self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"], sw_version=self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]), via_device=(DOMAIN, self.device["parentDevice"]),
} )
@property @property
def available(self): def available(self):

View file

@ -1,7 +1,10 @@
"""Support for the Hive switches.""" """Support for the Hive switches."""
from __future__ import annotations
from datetime import timedelta from datetime import timedelta
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
from homeassistant.helpers.entity import DeviceInfo
from . import HiveEntity, refresh_system from . import HiveEntity, refresh_system
from .const import ATTR_MODE, DOMAIN from .const import ATTR_MODE, DOMAIN
@ -31,17 +34,18 @@ class HiveDevicePlug(HiveEntity, SwitchEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo | None:
"""Return device information.""" """Return device information."""
if self.device["hiveType"] == "activeplug": if self.device["hiveType"] == "activeplug":
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device["device_id"])}, identifiers={(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"], name=self.device["device_name"],
"model": self.device["deviceData"]["model"], model=self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"], manufacturer=self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"], sw_version=self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]), via_device=(DOMAIN, self.device["parentDevice"]),
} )
return None
@property @property
def name(self): def name(self):

View file

@ -13,6 +13,7 @@ from homeassistant.components.water_heater import (
) )
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers import config_validation as cv, entity_platform from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.entity import DeviceInfo
from . import HiveEntity, refresh_system from . import HiveEntity, refresh_system
from .const import ( from .const import (
@ -78,16 +79,16 @@ class HiveWaterHeater(HiveEntity, WaterHeaterEntity):
return self._unique_id return self._unique_id
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device information.""" """Return device information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.device["device_id"])}, identifiers={(DOMAIN, self.device["device_id"])},
"name": self.device["device_name"], name=self.device["device_name"],
"model": self.device["deviceData"]["model"], model=self.device["deviceData"]["model"],
"manufacturer": self.device["deviceData"]["manufacturer"], manufacturer=self.device["deviceData"]["manufacturer"],
"sw_version": self.device["deviceData"]["version"], sw_version=self.device["deviceData"]["version"],
"via_device": (DOMAIN, self.device["parentDevice"]), via_device=(DOMAIN, self.device["parentDevice"]),
} )
@property @property
def supported_features(self): def supported_features(self):

View file

@ -47,13 +47,13 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return device specific attributes.""" """Return device specific attributes."""
return { return DeviceInfo(
"identifiers": {(HMIPC_DOMAIN, f"ACP {self._home.id}")}, identifiers={(HMIPC_DOMAIN, f"ACP {self._home.id}")},
"name": self.name, name=self.name,
"manufacturer": "eQ-3", manufacturer="eQ-3",
"model": CONST_ALARM_CONTROL_PANEL_NAME, model=CONST_ALARM_CONTROL_PANEL_NAME,
"via_device": (HMIPC_DOMAIN, self._home.id), via_device=(HMIPC_DOMAIN, self._home.id),
} )
@property @property
def state(self) -> str: def state(self) -> str:

View file

@ -76,13 +76,13 @@ class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
@property @property
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return device specific attributes.""" """Return device specific attributes."""
return { return DeviceInfo(
"identifiers": {(HMIPC_DOMAIN, self._device.id)}, identifiers={(HMIPC_DOMAIN, self._device.id)},
"name": self._device.label, name=self._device.label,
"manufacturer": "eQ-3", manufacturer="eQ-3",
"model": self._device.modelType, model=self._device.modelType,
"via_device": (HMIPC_DOMAIN, self._device.homeId), via_device=(HMIPC_DOMAIN, self._device.homeId),
} )
@property @property
def temperature_unit(self) -> str: def temperature_unit(self) -> str:

View file

@ -96,18 +96,18 @@ class HomematicipGenericEntity(Entity):
"""Return device specific attributes.""" """Return device specific attributes."""
# Only physical devices should be HA devices. # Only physical devices should be HA devices.
if isinstance(self._device, AsyncDevice): if isinstance(self._device, AsyncDevice):
return { return DeviceInfo(
"identifiers": { identifiers={
# Serial numbers of Homematic IP device # Serial numbers of Homematic IP device
(HMIPC_DOMAIN, self._device.id) (HMIPC_DOMAIN, self._device.id)
}, },
"name": self._device.label, name=self._device.label,
"manufacturer": self._device.oem, manufacturer=self._device.oem,
"model": self._device.modelType, model=self._device.modelType,
"sw_version": self._device.firmwareVersion, sw_version=self._device.firmwareVersion,
# Link to the homematic ip access point. # Link to the homematic ip access point.
"via_device": (HMIPC_DOMAIN, self._device.homeId), via_device=(HMIPC_DOMAIN, self._device.homeId),
} )
return None return None
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:

View file

@ -40,19 +40,19 @@ class GenericHueDevice(entity.Entity):
return self.primary_sensor.raw.get("swupdate", {}).get("state") return self.primary_sensor.raw.get("swupdate", {}).get("state")
@property @property
def device_info(self): def device_info(self) -> entity.DeviceInfo:
"""Return the device info. """Return the device info.
Links individual entities together in the hass device registry. Links individual entities together in the hass device registry.
""" """
return { return entity.DeviceInfo(
"identifiers": {(HUE_DOMAIN, self.device_id)}, identifiers={(HUE_DOMAIN, self.device_id)},
"name": self.primary_sensor.name, name=self.primary_sensor.name,
"manufacturer": self.primary_sensor.manufacturername, manufacturer=self.primary_sensor.manufacturername,
"model": (self.primary_sensor.productname or self.primary_sensor.modelid), model=(self.primary_sensor.productname or self.primary_sensor.modelid),
"sw_version": self.primary_sensor.swversion, sw_version=self.primary_sensor.swversion,
"via_device": (HUE_DOMAIN, self.bridge.api.config.bridgeid), via_device=(HUE_DOMAIN, self.bridge.api.config.bridgeid),
} )
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Handle entity being added to Home Assistant.""" """Handle entity being added to Home Assistant."""

View file

@ -2,7 +2,9 @@
from aiopvapi.resources.shade import ATTR_TYPE from aiopvapi.resources.shade import ATTR_TYPE
from homeassistant.const import ATTR_MODEL, ATTR_SW_VERSION
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ( from .const import (
@ -63,21 +65,21 @@ class ShadeEntity(HDEntity):
self._shade = shade self._shade = shade
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device_info of the device.""" """Return the device_info of the device."""
device_info = { device_info = DeviceInfo(
"identifiers": {(DOMAIN, self._shade.id)}, identifiers={(DOMAIN, self._shade.id)},
"name": self._shade_name, name=self._shade_name,
"suggested_area": self._room_name, suggested_area=self._room_name,
"manufacturer": MANUFACTURER, manufacturer=MANUFACTURER,
"model": str(self._shade.raw_data[ATTR_TYPE]), model=str(self._shade.raw_data[ATTR_TYPE]),
"via_device": (DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]), via_device=(DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]),
} )
for shade in self._shade.shade_types: for shade in self._shade.shade_types:
if shade.shade_type == device_info["model"]: if shade.shade_type == device_info[ATTR_MODEL]:
device_info["model"] = shade.description device_info[ATTR_MODEL] = shade.description
break break
if FIRMWARE not in self._shade.raw_data: if FIRMWARE not in self._shade.raw_data:
@ -86,6 +88,6 @@ class ShadeEntity(HDEntity):
firmware = self._shade.raw_data[FIRMWARE] firmware = self._shade.raw_data[FIRMWARE]
sw_version = f"{firmware[FIRMWARE_REVISION]}.{firmware[FIRMWARE_SUB_REVISION]}.{firmware[FIRMWARE_BUILD]}" 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 return device_info