Add configuration_url to SMA integration (#59638)

This commit is contained in:
René Klomp 2021-11-17 03:10:41 +01:00 committed by GitHub
parent 7f07755f5c
commit a68563cefd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 17 deletions

View file

@ -20,6 +20,7 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import ( from .const import (
@ -143,7 +144,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
try: try:
# Get updated device info # 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 # Get all device sensors
sensor_def = await sma.get_sensors() sensor_def = await sma.get_sensors()
except ( except (

View file

@ -156,7 +156,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
self, self,
coordinator: DataUpdateCoordinator, coordinator: DataUpdateCoordinator,
config_entry_unique_id: str, config_entry_unique_id: str,
device_info: dict[str, Any], device_info: DeviceInfo,
pysma_sensor: pysma.sensor.Sensor, pysma_sensor: pysma.sensor.Sensor,
) -> None: ) -> None:
"""Initialize the sensor.""" """Initialize the sensor."""
@ -164,7 +164,7 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
self._sensor = pysma_sensor self._sensor = pysma_sensor
self._enabled_default = self._sensor.enabled self._enabled_default = self._sensor.enabled
self._config_entry_unique_id = config_entry_unique_id 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: if self.native_unit_of_measurement == ENERGY_KILO_WATT_HOUR:
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING 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}" 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 @property
def entity_registry_enabled_default(self) -> bool: def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry.""" """Return if the entity should be enabled when first added to the entity registry."""