Group optimizer sensors under site device
This commit is contained in:
@@ -7,16 +7,57 @@ from datetime import timedelta
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_URL, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .api import SolarEdgeOptimizerApiClient
|
||||
from .const import CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
|
||||
from .const import (
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONFIG_ENTRY_VERSION,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
from .coordinator import SolarEdgeOptimizerCoordinator
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
type SolarEdgeOptimizerConfigEntry = ConfigEntry[SolarEdgeOptimizerCoordinator]
|
||||
|
||||
|
||||
async def async_migrate_entry(
|
||||
hass: HomeAssistant, entry: SolarEdgeOptimizerConfigEntry
|
||||
) -> bool:
|
||||
"""Migrate optimizer devices to one site device."""
|
||||
if entry.version > CONFIG_ENTRY_VERSION:
|
||||
LOGGER.error(
|
||||
"Cannot migrate config entry from version %s to %s",
|
||||
entry.version,
|
||||
CONFIG_ENTRY_VERSION,
|
||||
)
|
||||
return False
|
||||
|
||||
if entry.version < 2:
|
||||
site_id = entry.unique_id
|
||||
if site_id:
|
||||
device_registry = dr.async_get(hass)
|
||||
legacy_prefix = f"{site_id}_"
|
||||
for device in dr.async_entries_for_config_entry(
|
||||
device_registry, entry.entry_id
|
||||
):
|
||||
if any(
|
||||
domain == DOMAIN and identifier.startswith(legacy_prefix)
|
||||
for domain, identifier in device.identifiers
|
||||
):
|
||||
device_registry.async_remove_device(device.id)
|
||||
|
||||
hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
version=CONFIG_ENTRY_VERSION,
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: SolarEdgeOptimizerConfigEntry
|
||||
) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user