updated apps
This commit is contained in:
@@ -3,7 +3,8 @@ from datetime import timedelta
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ENABLED, CONF_ID, CONF_PATH, EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers import device_registry, issue_registry as ir
|
||||
from homeassistant.helpers.helper_integration import async_remove_helper_config_entry_from_source_device
|
||||
from homeassistant.helpers.issue_registry import async_create_issue
|
||||
|
||||
from custom_components.powercalc.const import (
|
||||
@@ -50,7 +51,7 @@ async def async_migrate_config_entry(hass: HomeAssistant, config_entry: ConfigEn
|
||||
if version <= 3:
|
||||
_migrate_playbook_trigger(data)
|
||||
|
||||
if version <= 4 and config_entry.entry_id == ENTRY_GLOBAL_CONFIG_UNIQUE_ID:
|
||||
if version <= 4 and config_entry.unique_id == ENTRY_GLOBAL_CONFIG_UNIQUE_ID:
|
||||
_migrate_global_discovery_config(data)
|
||||
|
||||
if version <= 5:
|
||||
@@ -62,7 +63,24 @@ async def async_migrate_config_entry(hass: HomeAssistant, config_entry: ConfigEn
|
||||
if version <= 7:
|
||||
_migrate_invalid_power_sensor_category(data)
|
||||
|
||||
hass.config_entries.async_update_entry(config_entry, data=data, version=8)
|
||||
if version <= 8:
|
||||
_remove_config_entry_from_devices(hass, config_entry)
|
||||
|
||||
hass.config_entries.async_update_entry(config_entry, data=data, version=9)
|
||||
|
||||
|
||||
def _remove_config_entry_from_devices(hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
"""
|
||||
Remove powercalc config entry from devices.
|
||||
See: https://developers.home-assistant.io/blog/2025/07/18/updated-pattern-for-helpers-linking-to-devices/
|
||||
"""
|
||||
device_reg = device_registry.async_get(hass)
|
||||
for device_entry in device_registry.async_entries_for_config_entry(device_reg, config_entry.entry_id):
|
||||
async_remove_helper_config_entry_from_source_device(
|
||||
hass,
|
||||
helper_config_entry_id=config_entry.entry_id,
|
||||
source_device_id=device_entry.id,
|
||||
)
|
||||
|
||||
|
||||
def _migrate_power_template(data: dict) -> None:
|
||||
@@ -78,16 +96,22 @@ def _migrate_playbook_trigger(data: dict) -> None:
|
||||
|
||||
|
||||
def _migrate_global_discovery_config(data: dict) -> None:
|
||||
deprecated_keys = [
|
||||
CONF_ENABLE_AUTODISCOVERY_DEPRECATED,
|
||||
CONF_DISCOVERY_EXCLUDE_DEVICE_TYPES_DEPRECATED,
|
||||
CONF_DISCOVERY_EXCLUDE_SELF_USAGE_DEPRECATED,
|
||||
]
|
||||
# Nothing to convert when there are no legacy keys and the new format is already present;
|
||||
# avoid clobbering an existing discovery config.
|
||||
if not any(key in data for key in deprecated_keys) and CONF_DISCOVERY in data:
|
||||
return
|
||||
|
||||
data[CONF_DISCOVERY] = {
|
||||
CONF_ENABLED: data.get(CONF_ENABLE_AUTODISCOVERY_DEPRECATED, True),
|
||||
CONF_EXCLUDE_DEVICE_TYPES: data.get(CONF_DISCOVERY_EXCLUDE_DEVICE_TYPES_DEPRECATED, []),
|
||||
CONF_EXCLUDE_SELF_USAGE: data.get(CONF_DISCOVERY_EXCLUDE_SELF_USAGE_DEPRECATED, False),
|
||||
}
|
||||
for key in [
|
||||
CONF_ENABLE_AUTODISCOVERY_DEPRECATED,
|
||||
CONF_DISCOVERY_EXCLUDE_DEVICE_TYPES_DEPRECATED,
|
||||
CONF_DISCOVERY_EXCLUDE_SELF_USAGE_DEPRECATED,
|
||||
]:
|
||||
for key in deprecated_keys:
|
||||
data.pop(key, None)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user