Use DeviceInfo on components with via_device (I-T) (#58212)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-10-22 12:31:12 +02:00 committed by GitHub
parent 6dd72869a6
commit 176ed4f7ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 96 additions and 93 deletions

View File

@ -238,10 +238,10 @@ class AqualinkEntity(Entity):
@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": self.name, name=self.name,
"model": self.dev.__class__.__name__.replace("Aqualink", ""), model=self.dev.__class__.__name__.replace("Aqualink", ""),
"manufacturer": "Jandy", manufacturer="Jandy",
"via_device": (DOMAIN, self.dev.system.serial), via_device=(DOMAIN, self.dev.system.serial),
} )

View File

@ -9,7 +9,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from .const import ( from .const import (
DOMAIN, DOMAIN,
@ -79,16 +79,16 @@ class InsteonEntity(Entity):
return {"insteon_address": self.address, "insteon_group": self.group} return {"insteon_address": self.address, "insteon_group": self.group}
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return device information.""" """Return device information."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, str(self._insteon_device.address))}, identifiers={(DOMAIN, str(self._insteon_device.address))},
"name": f"{self._insteon_device.description} {self._insteon_device.address}", name=f"{self._insteon_device.description} {self._insteon_device.address}",
"model": f"{self._insteon_device.model} ({self._insteon_device.cat!r}, 0x{self._insteon_device.subcat:02x})", model=f"{self._insteon_device.model} ({self._insteon_device.cat!r}, 0x{self._insteon_device.subcat:02x})",
"sw_version": f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}", sw_version=f"{self._insteon_device.firmware:02x} Engine Version: {self._insteon_device.engine_version}",
"manufacturer": "Smart Home", manufacturer="Smart Home",
"via_device": (DOMAIN, str(devices.modem.address)), via_device=(DOMAIN, str(devices.modem.address)),
} )
@callback @callback
def async_entity_update(self, name, address, value, group): def async_entity_update(self, name, address, value, group):

View File

@ -35,6 +35,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_platform from homeassistant.helpers import entity_platform
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.temperature import display_temp as show_temp from homeassistant.helpers.temperature import display_temp as show_temp
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
@ -483,13 +484,13 @@ class ZoneDevice(ClimateEntity):
} }
self._supported_features |= SUPPORT_TARGET_TEMPERATURE self._supported_features |= SUPPORT_TARGET_TEMPERATURE
self._device_info = { self._device_info = DeviceInfo(
"identifiers": {(IZONE, controller.unique_id, zone.index)}, identifiers={(IZONE, controller.unique_id, zone.index)},
"name": self.name, name=self.name,
"manufacturer": "IZone", manufacturer="IZone",
"via_device": (IZONE, controller.unique_id), via_device=(IZONE, controller.unique_id),
"model": zone.type.name.title(), model=zone.type.name.title(),
} )
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Call on adding to hass.""" """Call on adding to hass."""

View File

@ -17,7 +17,7 @@ from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from .const import ( from .const import (
ACTION_PRESS, ACTION_PRESS,
@ -329,16 +329,16 @@ class LutronCasetaDevice(Entity):
return str(self.serial) return str(self.serial)
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device info.""" """Return the device info."""
return { return DeviceInfo(
"identifiers": {(DOMAIN, self.serial)}, identifiers={(DOMAIN, self.serial)},
"name": self.name, name=self.name,
"suggested_area": self._device["name"].split("_")[0], suggested_area=self._device["name"].split("_")[0],
"manufacturer": MANUFACTURER, manufacturer=MANUFACTURER,
"model": f"{self._device['model']} ({self._device['type']})", model=f"{self._device['model']} ({self._device['type']})",
"via_device": (DOMAIN, self._bridge_device["serial"]), via_device=(DOMAIN, self._bridge_device["serial"]),
} )
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):

View File

@ -17,6 +17,7 @@ from homeassistant.components.cover import (
CoverEntity, CoverEntity,
) )
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 homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ( from .const import (
@ -138,13 +139,13 @@ class MotionPositionDevice(CoordinatorEntity, CoverEntity):
self._attr_device_class = device_class self._attr_device_class = device_class
self._attr_name = f"{blind.blind_type}-{blind.mac[12:]}" self._attr_name = f"{blind.blind_type}-{blind.mac[12:]}"
self._attr_unique_id = blind.mac self._attr_unique_id = blind.mac
self._attr_device_info = { self._attr_device_info = DeviceInfo(
"identifiers": {(DOMAIN, blind.mac)}, identifiers={(DOMAIN, blind.mac)},
"manufacturer": MANUFACTURER, manufacturer=MANUFACTURER,
"name": f"{blind.blind_type}-{blind.mac[12:]}", name=f"{blind.blind_type}-{blind.mac[12:]}",
"model": blind.blind_type, model=blind.blind_type,
"via_device": (DOMAIN, config_entry.unique_id), via_device=(DOMAIN, config_entry.unique_id),
} )
@property @property
def available(self): def available(self):

View File

@ -23,7 +23,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
@ -273,14 +273,14 @@ class NetgearDeviceEntity(Entity):
return self._name return self._name
@property @property
def device_info(self): def device_info(self) -> DeviceInfo:
"""Return the device information.""" """Return the device information."""
return { return DeviceInfo(
"connections": {(CONNECTION_NETWORK_MAC, self._mac)}, connections={(CONNECTION_NETWORK_MAC, self._mac)},
"default_name": self._device_name, default_name=self._device_name,
"default_model": self._device["device_model"], default_model=self._device["device_model"],
"via_device": (DOMAIN, self._router.unique_id), via_device=(DOMAIN, self._router.unique_id),
} )
@property @property
def should_poll(self) -> bool: def should_poll(self) -> bool:

View File

@ -17,7 +17,7 @@ from homeassistant.helpers import (
config_validation as cv, config_validation as cv,
device_registry as dr, device_registry as dr,
) )
from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.entity import DeviceInfo, EntityDescription
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
@ -147,14 +147,14 @@ class NotionEntity(CoordinatorEntity):
bridge = self.coordinator.data["bridges"].get(bridge_id, {}) bridge = self.coordinator.data["bridges"].get(bridge_id, {})
sensor = self.coordinator.data["sensors"][sensor_id] sensor = self.coordinator.data["sensors"][sensor_id]
self._attr_device_info = { self._attr_device_info = DeviceInfo(
"identifiers": {(DOMAIN, sensor["hardware_id"])}, identifiers={(DOMAIN, sensor["hardware_id"])},
"manufacturer": "Silicon Labs", manufacturer="Silicon Labs",
"model": sensor["hardware_revision"], model=sensor["hardware_revision"],
"name": str(sensor["name"]), name=str(sensor["name"]),
"sw_version": sensor["firmware_version"], sw_version=sensor["firmware_version"],
"via_device": (DOMAIN, bridge.get("hardware_id")), via_device=(DOMAIN, bridge.get("hardware_id")),
} )
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION} self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._attr_name = f'{sensor["name"]}: {description.name}' self._attr_name = f'{sensor["name"]}: {description.name}'

View File

@ -27,6 +27,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.helpers.entity_registry import async_get_registry
from homeassistant.helpers.network import is_internal_request from homeassistant.helpers.network import is_internal_request
@ -523,28 +524,28 @@ class PlexMediaPlayer(MediaPlayerEntity):
return attributes return attributes
@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."""
if self.machine_identifier is None: if self.machine_identifier is None:
return None return None
if self.device_product in TRANSIENT_DEVICE_MODELS: if self.device_product in TRANSIENT_DEVICE_MODELS:
return { return DeviceInfo(
"identifiers": {(PLEX_DOMAIN, "plex.tv-clients")}, identifiers={(PLEX_DOMAIN, "plex.tv-clients")},
"name": "Plex Client Service", name="Plex Client Service",
"manufacturer": "Plex", manufacturer="Plex",
"model": "Plex Clients", model="Plex Clients",
"entry_type": "service", entry_type="service",
} )
return { return DeviceInfo(
"identifiers": {(PLEX_DOMAIN, self.machine_identifier)}, identifiers={(PLEX_DOMAIN, self.machine_identifier)},
"manufacturer": self.device_platform or "Plex", manufacturer=self.device_platform or "Plex",
"model": self.device_product or self.device_make, model=self.device_product or self.device_make,
"name": self.name, name=self.name,
"sw_version": self.device_version, sw_version=self.device_version,
"via_device": (PLEX_DOMAIN, self.plex_server.machine_identifier), via_device=(PLEX_DOMAIN, self.plex_server.machine_identifier),
} )
async def async_browse_media(self, media_content_type=None, media_content_id=None): async def async_browse_media(self, media_content_type=None, media_content_id=None):
"""Implement the websocket media browsing helper.""" """Implement the websocket media browsing helper."""

View File

@ -21,7 +21,7 @@ from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from homeassistant.util.dt import as_local, parse_datetime, utc_from_timestamp from homeassistant.util.dt import as_local, parse_datetime, utc_from_timestamp
@ -308,20 +308,20 @@ class MinutPointEntity(Entity):
return attrs return attrs
@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."""
device = self.device.device device = self.device.device
return { return DeviceInfo(
"connections": { connections={
(device_registry.CONNECTION_NETWORK_MAC, device["device_mac"]) (device_registry.CONNECTION_NETWORK_MAC, device["device_mac"])
}, },
"identifieres": device["device_id"], identifieres=device["device_id"],
"manufacturer": "Minut", manufacturer="Minut",
"model": f"Point v{device['hardware_version']}", model=f"Point v{device['hardware_version']}",
"name": device["description"], name=device["description"],
"sw_version": device["firmware"]["installed"], sw_version=device["firmware"]["installed"],
"via_device": (DOMAIN, device["home"]), via_device=(DOMAIN, device["home"]),
} )
@property @property
def name(self): def name(self):

View File

@ -109,14 +109,14 @@ class TradfriBaseDevice(TradfriBaseClass):
def device_info(self) -> DeviceInfo: def device_info(self) -> DeviceInfo:
"""Return the device info.""" """Return the device info."""
info = self._device.device_info info = self._device.device_info
return { return DeviceInfo(
"identifiers": {(DOMAIN, self._device.id)}, identifiers={(DOMAIN, self._device.id)},
"manufacturer": info.manufacturer, manufacturer=info.manufacturer,
"model": info.model_number, model=info.model_number,
"name": self._attr_name, name=self._attr_name,
"sw_version": info.firmware_version, sw_version=info.firmware_version,
"via_device": (DOMAIN, self._gateway_id), via_device=(DOMAIN, self._gateway_id),
} )
def _refresh(self, device: Device) -> None: def _refresh(self, device: Device) -> None:
"""Refresh the device data.""" """Refresh the device data."""