Use DeviceInfo on components with configuration_url (#58223)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
416d87c01c
commit
f6ffae9e10
12 changed files with 116 additions and 119 deletions
|
@ -33,14 +33,14 @@ async def async_setup_entry(
|
|||
|
||||
sensors = []
|
||||
|
||||
device_info: DeviceInfo = {
|
||||
"identifiers": {(DOMAIN, coordinator.data.serial)},
|
||||
"name": coordinator.data.model,
|
||||
"manufacturer": ATTR_MANUFACTURER,
|
||||
"model": coordinator.data.model,
|
||||
"sw_version": getattr(coordinator.data, "firmware", None),
|
||||
"configuration_url": f"http://{entry.data[CONF_HOST]}/",
|
||||
}
|
||||
device_info = DeviceInfo(
|
||||
configuration_url=f"http://{entry.data[CONF_HOST]}/",
|
||||
identifiers={(DOMAIN, coordinator.data.serial)},
|
||||
manufacturer=ATTR_MANUFACTURER,
|
||||
model=coordinator.data.model,
|
||||
name=coordinator.data.model,
|
||||
sw_version=getattr(coordinator.data, "firmware", None),
|
||||
)
|
||||
|
||||
for description in SENSOR_TYPES:
|
||||
if description.key in coordinator.data:
|
||||
|
|
|
@ -15,15 +15,13 @@ from homeassistant.components.sensor import (
|
|||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_NAME,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_TOKEN,
|
||||
PERCENTAGE,
|
||||
)
|
||||
from homeassistant.helpers import config_validation as cv, update_coordinator
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import CO2SignalCoordinator, CO2SignalResponse
|
||||
|
@ -104,13 +102,13 @@ class CO2Sensor(update_coordinator.CoordinatorEntity[CO2SignalResponse], SensorE
|
|||
"country_code": coordinator.data["countryCode"],
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
self._attr_device_info = {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, coordinator.entry_id)},
|
||||
ATTR_NAME: "CO2 signal",
|
||||
ATTR_MANUFACTURER: "Tmrow.com",
|
||||
"entry_type": "service",
|
||||
"configuration_url": "https://www.electricitymap.org/",
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
configuration_url="https://www.electricitymap.org/",
|
||||
entry_type="service",
|
||||
identifiers={(DOMAIN, coordinator.entry_id)},
|
||||
manufacturer="Tmrow.com",
|
||||
name="CO2 signal",
|
||||
)
|
||||
self._attr_unique_id = (
|
||||
f"{coordinator.entry_id}_{description.unique_id or description.key}"
|
||||
)
|
||||
|
|
|
@ -480,12 +480,12 @@ class FritzBoxBaseEntity:
|
|||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information."""
|
||||
|
||||
return {
|
||||
"connections": {(CONNECTION_NETWORK_MAC, self.mac_address)},
|
||||
"identifiers": {(DOMAIN, self._fritzbox_tools.unique_id)},
|
||||
"name": self._device_name,
|
||||
"manufacturer": "AVM",
|
||||
"model": self._fritzbox_tools.model,
|
||||
"sw_version": self._fritzbox_tools.current_firmware,
|
||||
"configuration_url": f"http://{self._fritzbox_tools.host}",
|
||||
}
|
||||
return DeviceInfo(
|
||||
connections={(CONNECTION_NETWORK_MAC, self.mac_address)},
|
||||
identifiers={(DOMAIN, self._fritzbox_tools.unique_id)},
|
||||
name=self._device_name,
|
||||
manufacturer="AVM",
|
||||
model=self._fritzbox_tools.model,
|
||||
sw_version=self._fritzbox_tools.current_firmware,
|
||||
configuration_url=f"http://{self._fritzbox_tools.host}",
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Adapter to wrap the pyjuicenet api for home assistant."""
|
||||
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -20,11 +21,11 @@ class JuiceNetDevice(CoordinatorEntity):
|
|||
return f"{self.device.id}-{self.type}"
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return device information about this JuiceNet Device."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.device.id)},
|
||||
"name": self.device.name,
|
||||
"manufacturer": "JuiceNet",
|
||||
"configuration_url": f"https://home.juice.net/Portal/Details?unitID={self.device.id}",
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device.id)},
|
||||
name=self.device.name,
|
||||
manufacturer="JuiceNet",
|
||||
configuration_url=f"https://home.juice.net/Portal/Details?unitID={self.device.id}",
|
||||
)
|
||||
|
|
|
@ -115,10 +115,10 @@ class NAMDataUpdateCoordinator(DataUpdateCoordinator):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device info."""
|
||||
return {
|
||||
"connections": {(CONNECTION_NETWORK_MAC, cast(str, self._unique_id))},
|
||||
"name": DEFAULT_NAME,
|
||||
"sw_version": self.nam.software_version,
|
||||
"manufacturer": MANUFACTURER,
|
||||
"configuration_url": f"http://{self.host}/",
|
||||
}
|
||||
return DeviceInfo(
|
||||
connections={(CONNECTION_NETWORK_MAC, cast(str, self._unique_id))},
|
||||
name=DEFAULT_NAME,
|
||||
sw_version=self.nam.software_version,
|
||||
manufacturer=MANUFACTURER,
|
||||
configuration_url=f"http://{self.host}/",
|
||||
)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Support for Plex media server monitoring."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from plexapi.exceptions import NotFound
|
||||
|
@ -7,6 +9,7 @@ import requests.exceptions
|
|||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.helpers.debounce import Debouncer
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
||||
from .const import (
|
||||
CONF_SERVER_IDENTIFIER,
|
||||
|
@ -102,19 +105,19 @@ class PlexSensor(SensorEntity):
|
|||
return self._server.sensor_attributes
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return a device description for device registry."""
|
||||
if self.unique_id is None:
|
||||
return None
|
||||
|
||||
return {
|
||||
"identifiers": {(PLEX_DOMAIN, self._server.machine_identifier)},
|
||||
"manufacturer": "Plex",
|
||||
"model": "Plex Media Server",
|
||||
"name": self._server.friendly_name,
|
||||
"sw_version": self._server.version,
|
||||
"configuration_url": f"{self._server.url_in_use}/web",
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(PLEX_DOMAIN, self._server.machine_identifier)},
|
||||
manufacturer="Plex",
|
||||
model="Plex Media Server",
|
||||
name=self._server.friendly_name,
|
||||
sw_version=self._server.version,
|
||||
configuration_url=f"{self._server.url_in_use}/web",
|
||||
)
|
||||
|
||||
|
||||
class PlexLibrarySectionSensor(SensorEntity):
|
||||
|
@ -193,16 +196,16 @@ class PlexLibrarySectionSensor(SensorEntity):
|
|||
self._attr_extra_state_attributes["last_added_timestamp"] = media.addedAt
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo | None:
|
||||
"""Return a device description for device registry."""
|
||||
if self.unique_id is None:
|
||||
return None
|
||||
|
||||
return {
|
||||
"identifiers": {(PLEX_DOMAIN, self.server_id)},
|
||||
"manufacturer": "Plex",
|
||||
"model": "Plex Media Server",
|
||||
"name": self.server_name,
|
||||
"sw_version": self._server.version,
|
||||
"configuration_url": f"{self._server.url_in_use}/web",
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(PLEX_DOMAIN, self.server_id)},
|
||||
manufacturer="Plex",
|
||||
model="Plex Media Server",
|
||||
name=self.server_name,
|
||||
sw_version=self._server.version,
|
||||
configuration_url=f"{self._server.url_in_use}/web",
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Adapter to wrap the rachiopy api for home assistant."""
|
||||
|
||||
from homeassistant.helpers import device_registry
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DEFAULT_NAME, DOMAIN
|
||||
|
||||
|
@ -20,23 +20,23 @@ class RachioDevice(Entity):
|
|||
return False
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device_info of the device."""
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
(
|
||||
DOMAIN,
|
||||
self._controller.serial_number,
|
||||
)
|
||||
},
|
||||
"connections": {
|
||||
connections={
|
||||
(
|
||||
device_registry.CONNECTION_NETWORK_MAC,
|
||||
self._controller.mac_address,
|
||||
)
|
||||
},
|
||||
"name": self._controller.name,
|
||||
"model": self._controller.model,
|
||||
"manufacturer": DEFAULT_NAME,
|
||||
"configuration_url": "https://app.rach.io",
|
||||
}
|
||||
name=self._controller.name,
|
||||
model=self._controller.model,
|
||||
manufacturer=DEFAULT_NAME,
|
||||
configuration_url="https://app.rach.io",
|
||||
)
|
||||
|
|
|
@ -24,7 +24,7 @@ from homeassistant.core import HomeAssistant, ServiceCall, callback
|
|||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||
import homeassistant.helpers.device_registry as dr
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
|
@ -332,18 +332,18 @@ class RainMachineEntity(CoordinatorEntity):
|
|||
"""Initialize."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, controller.mac)},
|
||||
"configuration_url": f"https://{entry.data[CONF_IP_ADDRESS]}:{entry.data[CONF_PORT]}",
|
||||
"connections": {(dr.CONNECTION_NETWORK_MAC, controller.mac)},
|
||||
"name": str(controller.name),
|
||||
"manufacturer": "RainMachine",
|
||||
"model": (
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, controller.mac)},
|
||||
configuration_url=f"https://{entry.data[CONF_IP_ADDRESS]}:{entry.data[CONF_PORT]}",
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, controller.mac)},
|
||||
name=str(controller.name),
|
||||
manufacturer="RainMachine",
|
||||
model=(
|
||||
f"Version {controller.hardware_version} "
|
||||
f"(API: {controller.api_version})"
|
||||
),
|
||||
"sw_version": controller.software_version,
|
||||
}
|
||||
sw_version=controller.software_version,
|
||||
)
|
||||
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||
self._attr_name = f"{controller.name} {description.name}"
|
||||
# The colons are removed from the device MAC simply because that value
|
||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
|
@ -280,13 +281,13 @@ class SenseTrendsSensor(CoordinatorEntity, SensorEntity):
|
|||
self._attr_entity_registry_enabled_default = False
|
||||
self._attr_state_class = None
|
||||
self._attr_device_class = None
|
||||
self._attr_device_info = {
|
||||
"name": f"Sense {sense_monitor_id}",
|
||||
"identifiers": {(DOMAIN, sense_monitor_id)},
|
||||
"model": "Sense",
|
||||
"manufacturer": "Sense Labs, Inc.",
|
||||
"configuration_url": "https://home.sense.com",
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
name=f"Sense {sense_monitor_id}",
|
||||
identifiers={(DOMAIN, sense_monitor_id)},
|
||||
model="Sense",
|
||||
manufacturer="Sense Labs, Inc.",
|
||||
configuration_url="https://home.sense.com",
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
|
|
|
@ -3,12 +3,6 @@ from __future__ import annotations
|
|||
|
||||
from sonarr import Sonarr
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_IDENTIFIERS,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_NAME,
|
||||
ATTR_SW_VERSION,
|
||||
)
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -39,11 +33,11 @@ class SonarrEntity(Entity):
|
|||
configuration_url += f"{self.sonarr.host}:{self.sonarr.port}"
|
||||
configuration_url += self.sonarr.base_path.replace("/api", "")
|
||||
|
||||
return {
|
||||
ATTR_IDENTIFIERS: {(DOMAIN, self._device_id)},
|
||||
ATTR_NAME: "Activity Sensor",
|
||||
ATTR_MANUFACTURER: "Sonarr",
|
||||
ATTR_SW_VERSION: self.sonarr.app.info.version,
|
||||
"entry_type": "service",
|
||||
"configuration_url": configuration_url,
|
||||
}
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device_id)},
|
||||
name="Activity Sensor",
|
||||
manufacturer="Sonarr",
|
||||
sw_version=self.sonarr.app.info.version,
|
||||
entry_type="service",
|
||||
configuration_url=configuration_url,
|
||||
)
|
||||
|
|
|
@ -90,19 +90,19 @@ class SonosEntity(Entity):
|
|||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return information about the device."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.soco.uid)},
|
||||
"name": self.speaker.zone_name,
|
||||
"model": self.speaker.model_name.replace("Sonos ", ""),
|
||||
"sw_version": self.speaker.version,
|
||||
"connections": {
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self.soco.uid)},
|
||||
name=self.speaker.zone_name,
|
||||
model=self.speaker.model_name.replace("Sonos ", ""),
|
||||
sw_version=self.speaker.version,
|
||||
connections={
|
||||
(dr.CONNECTION_NETWORK_MAC, self.speaker.mac_address),
|
||||
(dr.CONNECTION_UPNP, f"uuid:{self.speaker.uid}"),
|
||||
},
|
||||
"manufacturer": "Sonos",
|
||||
"suggested_area": self.speaker.zone_name,
|
||||
"configuration_url": f"http://{self.soco.ip_address}:1400/support/review",
|
||||
}
|
||||
manufacturer="Sonos",
|
||||
suggested_area=self.speaker.zone_name,
|
||||
configuration_url=f"http://{self.soco.ip_address}:1400/support/review",
|
||||
)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from pyuptimerobot import UptimeRobotMonitor
|
||||
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.entity import DeviceInfo, EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
|
@ -27,14 +27,14 @@ class UptimeRobotEntity(CoordinatorEntity):
|
|||
super().__init__(coordinator)
|
||||
self.entity_description = description
|
||||
self._monitor = monitor
|
||||
self._attr_device_info = {
|
||||
"identifiers": {(DOMAIN, str(self.monitor.id))},
|
||||
"name": self.monitor.friendly_name,
|
||||
"manufacturer": "UptimeRobot Team",
|
||||
"entry_type": "service",
|
||||
"model": self.monitor.type.name,
|
||||
"configuration_url": f"https://uptimerobot.com/dashboard#{self.monitor.id}",
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, str(self.monitor.id))},
|
||||
name=self.monitor.friendly_name,
|
||||
manufacturer="UptimeRobot Team",
|
||||
entry_type="service",
|
||||
model=self.monitor.type.name,
|
||||
configuration_url=f"https://uptimerobot.com/dashboard#{self.monitor.id}",
|
||||
)
|
||||
self._attr_extra_state_attributes = {
|
||||
ATTR_TARGET: self.monitor.url,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue