From afe4892ae6e8a714c312efc3bfb702a65cdb6d45 Mon Sep 17 00:00:00 2001 From: Shai Ungar Date: Fri, 6 May 2022 00:34:30 +0300 Subject: [PATCH] Add unique ids to sensors (#71367) --- homeassistant/components/sabnzbd/manifest.json | 2 -- homeassistant/components/sabnzbd/sensor.py | 11 ++++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/sabnzbd/manifest.json b/homeassistant/components/sabnzbd/manifest.json index 0702446d217..f112893b5e1 100644 --- a/homeassistant/components/sabnzbd/manifest.json +++ b/homeassistant/components/sabnzbd/manifest.json @@ -3,8 +3,6 @@ "name": "SABnzbd", "documentation": "https://www.home-assistant.io/integrations/sabnzbd", "requirements": ["pysabnzbd==1.1.1"], - "dependencies": ["configurator"], - "after_dependencies": ["discovery"], "codeowners": ["@shaiu"], "iot_class": "local_polling", "config_flow": true, diff --git a/homeassistant/components/sabnzbd/sensor.py b/homeassistant/components/sabnzbd/sensor.py index 1d661d90848..dee80945e9d 100644 --- a/homeassistant/components/sabnzbd/sensor.py +++ b/homeassistant/components/sabnzbd/sensor.py @@ -14,8 +14,10 @@ from . import DOMAIN, SIGNAL_SABNZBD_UPDATED from ...config_entries import ConfigEntry from ...const import DATA_GIGABYTES, DATA_MEGABYTES, DATA_RATE_MEGABYTES_PER_SECOND from ...core import HomeAssistant +from ...helpers.device_registry import DeviceEntryType +from ...helpers.entity import DeviceInfo from ...helpers.entity_platform import AddEntitiesCallback -from .const import KEY_API_DATA, KEY_NAME +from .const import DEFAULT_NAME, KEY_API_DATA, KEY_NAME @dataclass @@ -127,9 +129,16 @@ class SabnzbdSensor(SensorEntity): self, sabnzbd_api_data, client_name, description: SabnzbdSensorEntityDescription ): """Initialize the sensor.""" + unique_id = description.key + self._attr_unique_id = unique_id self.entity_description = description self._sabnzbd_api = sabnzbd_api_data self._attr_name = f"{client_name} {description.name}" + self._attr_device_info = DeviceInfo( + entry_type=DeviceEntryType.SERVICE, + identifiers={(DOMAIN, DOMAIN)}, + name=DEFAULT_NAME, + ) async def async_added_to_hass(self): """Call when entity about to be added to hass."""