From a68563cefd62fcb78914daea9a453e6eee3c8dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Klomp?= Date: Wed, 17 Nov 2021 03:10:41 +0100 Subject: [PATCH] Add `configuration_url` to SMA integration (#59638) --- homeassistant/components/sma/__init__.py | 11 ++++++++++- homeassistant/components/sma/sensor.py | 18 ++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/sma/__init__.py b/homeassistant/components/sma/__init__.py index 1a48bee7797..6a7243b0343 100644 --- a/homeassistant/components/sma/__init__.py +++ b/homeassistant/components/sma/__init__.py @@ -20,6 +20,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import ( @@ -143,7 +144,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: # Get updated device info - device_info = await sma.device_info() + sma_device_info = await sma.device_info() + device_info = DeviceInfo( + configuration_url=url, + identifiers={(DOMAIN, entry.unique_id)}, + manufacturer=sma_device_info["manufacturer"], + model=sma_device_info["type"], + name=sma_device_info["name"], + sw_version=sma_device_info["sw_version"], + ) # Get all device sensors sensor_def = await sma.get_sensors() except ( diff --git a/homeassistant/components/sma/sensor.py b/homeassistant/components/sma/sensor.py index 853edee823c..7fa84f25bd2 100644 --- a/homeassistant/components/sma/sensor.py +++ b/homeassistant/components/sma/sensor.py @@ -156,7 +156,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity): self, coordinator: DataUpdateCoordinator, config_entry_unique_id: str, - device_info: dict[str, Any], + device_info: DeviceInfo, pysma_sensor: pysma.sensor.Sensor, ) -> None: """Initialize the sensor.""" @@ -164,7 +164,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity): self._sensor = pysma_sensor self._enabled_default = self._sensor.enabled self._config_entry_unique_id = config_entry_unique_id - self._device_info = device_info + self._attr_device_info = device_info if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR: self._attr_state_class = STATE_CLASS_TOTAL_INCREASING @@ -199,20 +199,6 @@ class SMAsensor(CoordinatorEntity, SensorEntity): f"{self._config_entry_unique_id}-{self._sensor.key}_{self._sensor.key_idx}" ) - @property - def device_info(self) -> DeviceInfo | None: - """Return the device information.""" - if not self._device_info: - return None - - return DeviceInfo( - identifiers={(DOMAIN, self._config_entry_unique_id)}, - manufacturer=self._device_info["manufacturer"], - model=self._device_info["type"], - name=self._device_info["name"], - sw_version=self._device_info["sw_version"], - ) - @property def entity_registry_enabled_default(self) -> bool: """Return if the entity should be enabled when first added to the entity registry."""