Add configuration_url
to SMA integration (#59638)
This commit is contained in:
parent
7f07755f5c
commit
a68563cefd
2 changed files with 12 additions and 17 deletions
|
@ -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 (
|
||||
|
|
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue