mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 14:29:21 -04:00
Mod
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Repairs platform for the Min/Max integration."""
|
||||
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -11,7 +11,7 @@ from homeassistant.components.repairs import (
|
||||
RepairsFlowResult,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_ENTITIES
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@@ -23,9 +23,9 @@ from .const import CONF_ENTITY_IDS, CONF_ROUND_DIGITS, DOMAIN
|
||||
class MigrateToGroupSensorFlow(RepairsFlow):
|
||||
"""Repair flow to migrate Min/Max helper to Group sensor."""
|
||||
|
||||
def __init__(self, entry: ConfigEntry) -> None:
|
||||
def __init__(self, entry_id: str) -> None:
|
||||
"""Create flow."""
|
||||
self.entry = entry
|
||||
self.entry_id = entry_id
|
||||
super().__init__()
|
||||
|
||||
async def async_step_init(
|
||||
@@ -39,18 +39,21 @@ class MigrateToGroupSensorFlow(RepairsFlow):
|
||||
) -> RepairsFlowResult:
|
||||
"""Handle the migration step of a fix flow."""
|
||||
entity_reg = er.async_get(self.hass)
|
||||
entry = self.hass.config_entries.async_get_entry(self.entry_id)
|
||||
if not entry:
|
||||
return self.async_abort(reason="entity_not_found")
|
||||
old_entity = entity_reg.async_get_entity_id(
|
||||
SENSOR_DOMAIN, DOMAIN, self.entry.entry_id
|
||||
SENSOR_DOMAIN, DOMAIN, entry.entry_id
|
||||
)
|
||||
if not old_entity:
|
||||
return self.async_abort(reason="entity_not_found")
|
||||
|
||||
if user_input is not None:
|
||||
config = dict(self.entry.options)
|
||||
config = dict(entry.options)
|
||||
config[CONF_ENTITIES] = config.pop(CONF_ENTITY_IDS)
|
||||
config.pop(CONF_ROUND_DIGITS)
|
||||
config[CONF_HIDE_MEMBERS] = False
|
||||
config["old_config_entry_id"] = self.entry.entry_id
|
||||
config["old_config_entry_id"] = entry.entry_id
|
||||
|
||||
import_result = await self.hass.config_entries.flow.async_init(
|
||||
GROUP_DOMAIN,
|
||||
@@ -87,11 +90,8 @@ async def async_create_fix_flow(
|
||||
data: dict[str, Any] | None,
|
||||
) -> RepairsFlow:
|
||||
"""Create flow."""
|
||||
if data and (entry_id := data.get("entry_id")):
|
||||
entry_id = cast(str, entry_id)
|
||||
entry = hass.config_entries.async_get_entry(entry_id)
|
||||
if TYPE_CHECKING:
|
||||
assert entry
|
||||
return MigrateToGroupSensorFlow(entry)
|
||||
if data and "entry_id" in data:
|
||||
entry_id = data["entry_id"]
|
||||
return MigrateToGroupSensorFlow(entry_id)
|
||||
|
||||
return ConfirmRepairFlow()
|
||||
|
||||
Reference in New Issue
Block a user