From c94c7fae1b10a7f7759182fd17b6922d0a28651c Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 18 Jul 2023 20:57:41 +0200 Subject: [PATCH] Add device info to ISS (#96469) Co-authored-by: Franck Nijhof --- homeassistant/components/iss/config_flow.py | 4 +--- homeassistant/components/iss/const.py | 2 ++ homeassistant/components/iss/sensor.py | 23 +++++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/iss/config_flow.py b/homeassistant/components/iss/config_flow.py index 2beffc7c894..f8ebd9db723 100644 --- a/homeassistant/components/iss/config_flow.py +++ b/homeassistant/components/iss/config_flow.py @@ -7,9 +7,7 @@ from homeassistant.const import CONF_SHOW_ON_MAP from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult -from .const import DOMAIN - -DEFAULT_NAME = "ISS" +from .const import DEFAULT_NAME, DOMAIN class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): diff --git a/homeassistant/components/iss/const.py b/homeassistant/components/iss/const.py index 3d240041b67..c3bdcf6fa32 100644 --- a/homeassistant/components/iss/const.py +++ b/homeassistant/components/iss/const.py @@ -1,3 +1,5 @@ """Constants for iss.""" DOMAIN = "iss" + +DEFAULT_NAME = "ISS" diff --git a/homeassistant/components/iss/sensor.py b/homeassistant/components/iss/sensor.py index fac23dfd9fa..32516ee99c9 100644 --- a/homeassistant/components/iss/sensor.py +++ b/homeassistant/components/iss/sensor.py @@ -8,6 +8,8 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CONF_SHOW_ON_MAP from homeassistant.core import HomeAssistant +from homeassistant.helpers.device_registry import DeviceEntryType +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, @@ -15,7 +17,7 @@ from homeassistant.helpers.update_coordinator import ( ) from . import IssData -from .const import DOMAIN +from .const import DEFAULT_NAME, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -28,23 +30,32 @@ async def async_setup_entry( """Set up the sensor platform.""" coordinator: DataUpdateCoordinator[IssData] = hass.data[DOMAIN] - name = entry.title show_on_map = entry.options.get(CONF_SHOW_ON_MAP, False) - async_add_entities([IssSensor(coordinator, name, show_on_map)]) + async_add_entities([IssSensor(coordinator, entry, show_on_map)]) class IssSensor(CoordinatorEntity[DataUpdateCoordinator[IssData]], SensorEntity): """Implementation of the ISS sensor.""" + _attr_has_entity_name = True + _attr_name = None + def __init__( - self, coordinator: DataUpdateCoordinator[IssData], name: str, show: bool + self, + coordinator: DataUpdateCoordinator[IssData], + entry: ConfigEntry, + show: bool, ) -> None: """Initialize the sensor.""" super().__init__(coordinator) - self._state = None - self._attr_name = name + self._attr_unique_id = f"{entry.entry_id}_people" self._show_on_map = show + self._attr_device_info = DeviceInfo( + identifiers={(DOMAIN, entry.entry_id)}, + name=DEFAULT_NAME, + entry_type=DeviceEntryType.SERVICE, + ) @property def native_value(self) -> int: