Remove support for spesific container images

This commit is contained in:
ludeeus 2023-07-03 07:33:19 +00:00
parent 79a122e1e5
commit 680920a48d
No known key found for this signature in database
5 changed files with 98 additions and 20 deletions

View file

@ -15,6 +15,7 @@ from .const import (
CONF_CHANNEL,
CONF_IMAGE,
CONF_SOURCE,
DEFAULT_IMAGE,
DOMAIN,
PLATFORMS,
)
@ -26,9 +27,9 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up the version integration from a config entry."""
board = entry.data[CONF_BOARD]
source = entry.data[CONF_SOURCE]
if board not in BOARD_MAP:
if (board := entry.data[CONF_BOARD]) not in BOARD_MAP:
_LOGGER.error(
'Board "%s" is (no longer) valid. Please remove the integration "%s"',
board,
@ -36,12 +37,23 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)
return False
if (image := entry.data[CONF_IMAGE]) != DEFAULT_IMAGE and source in (
"container",
"docker",
):
_LOGGER.error(
'Image "%s" is (no longer) valid. Please remove the integration "%s"',
image,
entry.title,
)
return False
coordinator = VersionDataUpdateCoordinator(
hass=hass,
api=HaVersion(
session=async_get_clientsession(hass),
source=entry.data[CONF_SOURCE],
image=entry.data[CONF_IMAGE],
source=source,
image=image,
board=BOARD_MAP[board],
channel=entry.data[CONF_CHANNEL].lower(),
),

View file

@ -26,7 +26,6 @@ from .const import (
STEP_VERSION_SOURCE,
VALID_BOARDS,
VALID_CHANNELS,
VALID_CONTAINER_IMAGES,
VALID_IMAGES,
VERSION_SOURCE_LOCAL,
VERSION_SOURCE_MAP,
@ -103,14 +102,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
),
}
)
else:
data_schema = data_schema.extend(
{
vol.Required(CONF_IMAGE, default=DEFAULT_IMAGE): vol.In(
VALID_CONTAINER_IMAGES
)
}
)
else:
data_schema = vol.Schema({vol.Required(CONF_BETA, default=False): bool})

View file

@ -114,10 +114,6 @@ VALID_IMAGES: Final = [
"tinker",
]
VALID_CONTAINER_IMAGES: Final[list[str]] = [
f"{image}{POSTFIX_CONTAINER_NAME}" if image != DEFAULT_IMAGE else image
for image in VALID_IMAGES
]
VALID_CHANNELS: Final[list[str]] = [
str(channel.value).title() for channel in HaVersionChannel
]

View file

@ -141,15 +141,15 @@ async def test_advanced_form_container(hass: HomeAssistant) -> None:
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_IMAGE: "odroid-n2-homeassistant"}
result["flow_id"], {CONF_CHANNEL: "Beta"}
)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == VERSION_SOURCE_DOCKER_HUB
assert result["title"] == f"{VERSION_SOURCE_DOCKER_HUB} Beta"
assert result["data"] == {
**DEFAULT_CONFIGURATION,
CONF_IMAGE: "odroid-n2-homeassistant",
CONF_CHANNEL: "beta",
CONF_SOURCE: HaVersionSource.CONTAINER,
CONF_VERSION_SOURCE: VERSION_SOURCE_DOCKER_HUB,
}

View file

@ -0,0 +1,79 @@
"""The tests for version init."""
from __future__ import annotations
from unittest.mock import patch
import pytest
from homeassistant.components.version.const import (
CONF_BOARD,
CONF_IMAGE,
DEFAULT_CONFIGURATION,
)
from homeassistant.const import CONF_SOURCE
from homeassistant.core import HomeAssistant
from .common import (
MOCK_VERSION,
MOCK_VERSION_CONFIG_ENTRY_DATA,
MOCK_VERSION_DATA,
)
from tests.common import MockConfigEntry
async def test_unsupported_board(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test configuring with an unsupported board."""
mock_entry = MockConfigEntry(
**{
**MOCK_VERSION_CONFIG_ENTRY_DATA,
"data": {
**DEFAULT_CONFIGURATION,
CONF_BOARD: "not-supported",
},
}
)
mock_entry.add_to_hass(hass)
with patch(
"pyhaversion.HaVersion.get_version",
return_value=(MOCK_VERSION, MOCK_VERSION_DATA),
):
assert not await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
assert (
'Board "not-supported" is (no longer) valid. Please remove the integration "Local installation"'
in caplog.text
)
async def test_unsupported_container_image(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test configuring with an unsupported container image."""
mock_entry = MockConfigEntry(
**{
**MOCK_VERSION_CONFIG_ENTRY_DATA,
"data": {
**DEFAULT_CONFIGURATION,
CONF_IMAGE: "not-supported-homeassistant",
CONF_SOURCE: "container",
},
}
)
mock_entry.add_to_hass(hass)
with patch(
"pyhaversion.HaVersion.get_version",
return_value=(MOCK_VERSION, MOCK_VERSION_DATA),
):
assert not await hass.config_entries.async_setup(mock_entry.entry_id)
await hass.async_block_till_done()
assert (
'Image "not-supported-homeassistant" is (no longer) valid. Please remove the integration "Local installation"'
in caplog.text
)