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