mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Remove old code from deprecation in Rainmachine (#188667)
This commit is contained in:
@@ -4,7 +4,6 @@ from dataclasses import dataclass
|
||||
from typing import override
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
@@ -15,11 +14,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from . import RainMachineConfigEntry
|
||||
from .const import DATA_PROVISION_SETTINGS, DATA_RESTRICTIONS_CURRENT
|
||||
from .entity import RainMachineEntity, RainMachineEntityDescription
|
||||
from .util import (
|
||||
EntityDomainReplacementStrategy,
|
||||
async_finish_entity_domain_replacements,
|
||||
key_exists,
|
||||
)
|
||||
from .util import key_exists
|
||||
|
||||
TYPE_FLOW_SENSOR = "flow_sensor"
|
||||
TYPE_FREEZE = "freeze"
|
||||
@@ -100,27 +95,6 @@ async def async_setup_entry(
|
||||
"""Set up RainMachine binary sensors based on a config entry."""
|
||||
data = entry.runtime_data
|
||||
|
||||
async_finish_entity_domain_replacements(
|
||||
hass,
|
||||
entry,
|
||||
(
|
||||
EntityDomainReplacementStrategy(
|
||||
BINARY_SENSOR_DOMAIN,
|
||||
f"{data.controller.mac}_freeze_protection",
|
||||
f"switch.{data.controller.name.lower()}_freeze_protect_enabled",
|
||||
breaks_in_ha_version="2022.12.0",
|
||||
remove_old_entity=True,
|
||||
),
|
||||
EntityDomainReplacementStrategy(
|
||||
BINARY_SENSOR_DOMAIN,
|
||||
f"{data.controller.mac}_extra_water_on_hot_days",
|
||||
f"switch.{data.controller.name.lower()}_hot_days_extra_watering",
|
||||
breaks_in_ha_version="2022.12.0",
|
||||
remove_old_entity=True,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
api_category_sensor_map = {
|
||||
DATA_PROVISION_SETTINGS: ProvisionSettingsBinarySensor,
|
||||
DATA_RESTRICTIONS_CURRENT: CurrentRestrictionsBinarySensor,
|
||||
|
||||
@@ -5,7 +5,6 @@ from datetime import datetime, timedelta
|
||||
from typing import Any, cast, override
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DOMAIN as SENSOR_DOMAIN,
|
||||
RestoreSensor,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
@@ -21,13 +20,7 @@ from homeassistant.util.dt import utc_from_timestamp, utcnow
|
||||
from . import RainMachineConfigEntry, RainMachineData
|
||||
from .const import DATA_PROGRAMS, DATA_PROVISION_SETTINGS, DATA_ZONES
|
||||
from .entity import RainMachineEntity, RainMachineEntityDescription
|
||||
from .util import (
|
||||
RUN_STATE_MAP,
|
||||
EntityDomainReplacementStrategy,
|
||||
RunStates,
|
||||
async_finish_entity_domain_replacements,
|
||||
key_exists,
|
||||
)
|
||||
from .util import RUN_STATE_MAP, RunStates, key_exists
|
||||
|
||||
DEFAULT_ZONE_COMPLETION_TIME_WOBBLE_TOLERANCE = timedelta(seconds=5)
|
||||
|
||||
@@ -156,20 +149,6 @@ async def async_setup_entry(
|
||||
"""Set up RainMachine sensors based on a config entry."""
|
||||
data = entry.runtime_data
|
||||
|
||||
async_finish_entity_domain_replacements(
|
||||
hass,
|
||||
entry,
|
||||
(
|
||||
EntityDomainReplacementStrategy(
|
||||
SENSOR_DOMAIN,
|
||||
f"{data.controller.mac}_freeze_protect_temp",
|
||||
f"select.{data.controller.name.lower()}_freeze_protect_temperature",
|
||||
breaks_in_ha_version="2022.12.0",
|
||||
remove_old_entity=True,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
api_category_sensor_map = {
|
||||
DATA_PROVISION_SETTINGS: ProvisionSettingsSensor,
|
||||
}
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
"""Define RainMachine utilities."""
|
||||
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import LOGGER
|
||||
|
||||
|
||||
class RunStates(StrEnum):
|
||||
"""Define an enum for program/zone run states."""
|
||||
@@ -27,44 +19,6 @@ RUN_STATE_MAP = {
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntityDomainReplacementStrategy:
|
||||
"""Define an entity replacement."""
|
||||
|
||||
old_domain: str
|
||||
old_unique_id: str
|
||||
replacement_entity_id: str
|
||||
breaks_in_ha_version: str
|
||||
remove_old_entity: bool = True
|
||||
|
||||
|
||||
@callback
|
||||
def async_finish_entity_domain_replacements(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entity_replacement_strategies: Iterable[EntityDomainReplacementStrategy],
|
||||
) -> None:
|
||||
"""Remove old entities and create a repairs issue with info on their replacement."""
|
||||
ent_reg = er.async_get(hass)
|
||||
for strategy in entity_replacement_strategies:
|
||||
try:
|
||||
[registry_entry] = [
|
||||
registry_entry
|
||||
for registry_entry in ent_reg.entities.get_entries_for_config_entry_id(
|
||||
entry.entry_id
|
||||
)
|
||||
if registry_entry.domain == strategy.old_domain
|
||||
and registry_entry.unique_id == strategy.old_unique_id
|
||||
]
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
old_entity_id = registry_entry.entity_id
|
||||
if strategy.remove_old_entity:
|
||||
LOGGER.debug('Removing old entity: "%s"', old_entity_id)
|
||||
ent_reg.async_remove(old_entity_id)
|
||||
|
||||
|
||||
def key_exists(data: dict[str, Any], search_key: str) -> bool:
|
||||
"""Return whether a key exists in a nested dict."""
|
||||
for key, value in data.items():
|
||||
|
||||
Reference in New Issue
Block a user