mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Cleanup Version after removing YAML (#69020)
This commit is contained in:
parent
56998f219b
commit
fef43d4f39
@ -6,7 +6,7 @@ from typing import Any
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_NAME, CONF_SOURCE
|
||||
from homeassistant.const import CONF_SOURCE
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import (
|
||||
@ -20,25 +20,16 @@ from .const import (
|
||||
DEFAULT_CHANNEL,
|
||||
DEFAULT_CONFIGURATION,
|
||||
DEFAULT_IMAGE,
|
||||
DEFAULT_NAME,
|
||||
DEFAULT_NAME_CURRENT,
|
||||
DEFAULT_NAME_LATEST,
|
||||
DEFAULT_SOURCE,
|
||||
DOMAIN,
|
||||
POSTFIX_CONTAINER_NAME,
|
||||
SOURCE_DOCKER,
|
||||
SOURCE_HASSIO,
|
||||
STEP_USER,
|
||||
STEP_VERSION_SOURCE,
|
||||
VALID_BOARDS,
|
||||
VALID_CHANNELS,
|
||||
VALID_CONTAINER_IMAGES,
|
||||
VALID_IMAGES,
|
||||
VERSION_SOURCE_DOCKER_HUB,
|
||||
VERSION_SOURCE_LOCAL,
|
||||
VERSION_SOURCE_MAP,
|
||||
VERSION_SOURCE_MAP_INVERTED,
|
||||
VERSION_SOURCE_VERSIONS,
|
||||
)
|
||||
|
||||
|
||||
@ -137,16 +128,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
title=self._config_entry_name, data=self._entry_data
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
self._entry_data = _convert_imported_configuration(import_config)
|
||||
|
||||
self._async_abort_entries_match({**DEFAULT_CONFIGURATION, **self._entry_data})
|
||||
|
||||
return self.async_create_entry(
|
||||
title=self._config_entry_name, data=self._entry_data
|
||||
)
|
||||
|
||||
@property
|
||||
def _config_entry_name(self) -> str:
|
||||
"""Return the name of the config entry."""
|
||||
@ -159,36 +140,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return f"{name} {channel.title()}"
|
||||
|
||||
return name
|
||||
|
||||
|
||||
def _convert_imported_configuration(config: dict[str, Any]) -> Any:
|
||||
"""Convert a key from the imported configuration."""
|
||||
data = DEFAULT_CONFIGURATION.copy()
|
||||
if config.get(CONF_BETA):
|
||||
data[CONF_CHANNEL] = "beta"
|
||||
|
||||
if (source := config.get(CONF_SOURCE)) and source != DEFAULT_SOURCE:
|
||||
if source == SOURCE_HASSIO:
|
||||
data[CONF_SOURCE] = "supervisor"
|
||||
data[CONF_VERSION_SOURCE] = VERSION_SOURCE_VERSIONS
|
||||
elif source == SOURCE_DOCKER:
|
||||
data[CONF_SOURCE] = "container"
|
||||
data[CONF_VERSION_SOURCE] = VERSION_SOURCE_DOCKER_HUB
|
||||
else:
|
||||
data[CONF_SOURCE] = source
|
||||
data[CONF_VERSION_SOURCE] = VERSION_SOURCE_MAP_INVERTED[source]
|
||||
|
||||
if (image := config.get(CONF_IMAGE)) and image != DEFAULT_IMAGE:
|
||||
if data[CONF_SOURCE] == "container":
|
||||
data[CONF_IMAGE] = f"{config[CONF_IMAGE]}{POSTFIX_CONTAINER_NAME}"
|
||||
else:
|
||||
data[CONF_IMAGE] = config[CONF_IMAGE]
|
||||
|
||||
if (name := config.get(CONF_NAME)) and name != DEFAULT_NAME:
|
||||
data[CONF_NAME] = config[CONF_NAME]
|
||||
else:
|
||||
if data[CONF_SOURCE] == "local":
|
||||
data[CONF_NAME] = DEFAULT_NAME_CURRENT
|
||||
else:
|
||||
data[CONF_NAME] = DEFAULT_NAME_LATEST
|
||||
return data
|
||||
|
@ -31,7 +31,6 @@ ATTR_VERSION_SOURCE: Final = CONF_VERSION_SOURCE
|
||||
ATTR_SOURCE: Final = CONF_SOURCE
|
||||
|
||||
SOURCE_DOCKER: Final = "docker" # Kept to not break existing configurations
|
||||
SOURCE_HASSIO: Final = "hassio" # Kept to not break existing configurations
|
||||
|
||||
VERSION_SOURCE_DOCKER_HUB: Final = "Docker Hub"
|
||||
VERSION_SOURCE_HAIO: Final = "Home Assistant Website"
|
||||
@ -44,7 +43,6 @@ DEFAULT_BOARD: Final = "OVA"
|
||||
DEFAULT_CHANNEL: Final = "stable"
|
||||
DEFAULT_IMAGE: Final = "default"
|
||||
DEFAULT_NAME_CURRENT: Final = "Current Version"
|
||||
DEFAULT_NAME_LATEST: Final = "Latest Version"
|
||||
DEFAULT_NAME: Final = ""
|
||||
DEFAULT_SOURCE: Final = "local"
|
||||
DEFAULT_CONFIGURATION: Final[dict[str, Any]] = {
|
||||
@ -89,11 +87,6 @@ VERSION_SOURCE_MAP: Final[dict[str, str]] = {
|
||||
VERSION_SOURCE_PYPI: "pypi",
|
||||
}
|
||||
|
||||
VERSION_SOURCE_MAP_INVERTED: Final[dict[str, str]] = {
|
||||
value: key for key, value in VERSION_SOURCE_MAP.items()
|
||||
}
|
||||
|
||||
|
||||
VALID_SOURCES: Final[list[str]] = HA_VERSION_SOURCES + [
|
||||
"hassio", # Kept to not break existing configurations
|
||||
"docker", # Kept to not break existing configurations
|
||||
|
@ -19,19 +19,12 @@ from homeassistant.components.version.const import (
|
||||
)
|
||||
from homeassistant.const import CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
RESULT_TYPE_CREATE_ENTRY,
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .common import MOCK_VERSION, MOCK_VERSION_DATA, setup_version_integration
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.components.version.common import (
|
||||
MOCK_VERSION,
|
||||
MOCK_VERSION_DATA,
|
||||
setup_version_integration,
|
||||
)
|
||||
|
||||
|
||||
async def test_reload_config_entry(hass: HomeAssistant):
|
||||
@ -203,30 +196,3 @@ async def test_advanced_form_supervisor(hass: HomeAssistant) -> None:
|
||||
CONF_VERSION_SOURCE: VERSION_SOURCE_VERSIONS,
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_existing(hass: HomeAssistant) -> None:
|
||||
"""Test importing existing configuration."""
|
||||
with patch(
|
||||
"homeassistant.components.version.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user