Version: remove deprecated YAML import (#69010)
parent
bb322a18bb
commit
56998f219b
|
@ -1,69 +1,19 @@
|
|||
"""Sensor that can display the current Home Assistant versions."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Final
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
from voluptuous.schema_builder import Schema
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, StateType
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from .const import (
|
||||
ATTR_SOURCE,
|
||||
CONF_BETA,
|
||||
CONF_IMAGE,
|
||||
CONF_SOURCE,
|
||||
DEFAULT_BETA,
|
||||
DEFAULT_IMAGE,
|
||||
DEFAULT_NAME,
|
||||
DEFAULT_SOURCE,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
VALID_IMAGES,
|
||||
VALID_SOURCES,
|
||||
)
|
||||
from .const import CONF_SOURCE, DEFAULT_NAME, DOMAIN
|
||||
from .coordinator import VersionDataUpdateCoordinator
|
||||
from .entity import VersionEntity
|
||||
|
||||
PLATFORM_SCHEMA: Final[Schema] = SENSOR_PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Optional(CONF_BETA, default=DEFAULT_BETA): cv.boolean,
|
||||
vol.Optional(CONF_IMAGE, default=DEFAULT_IMAGE): vol.In(VALID_IMAGES),
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_SOURCE, default=DEFAULT_SOURCE): vol.In(VALID_SOURCES),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the legacy version sensor platform."""
|
||||
LOGGER.warning(
|
||||
"Configuration of the Version platform in YAML is deprecated and will be "
|
||||
"removed in Home Assistant 2022.4; Your existing configuration "
|
||||
"has been imported into the UI automatically and can be safely removed "
|
||||
"from your configuration.yaml file"
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={ATTR_SOURCE: SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -1,54 +1,12 @@
|
|||
"""The test for the version sensor platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
|
||||
from pyhaversion import HaVersionChannel, HaVersionSource
|
||||
from pyhaversion.exceptions import HaVersionException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.version.const import (
|
||||
CONF_BETA,
|
||||
CONF_CHANNEL,
|
||||
CONF_IMAGE,
|
||||
CONF_VERSION_SOURCE,
|
||||
DEFAULT_NAME_LATEST,
|
||||
DOMAIN,
|
||||
VERSION_SOURCE_DOCKER_HUB,
|
||||
VERSION_SOURCE_VERSIONS,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import (
|
||||
MOCK_VERSION,
|
||||
MOCK_VERSION_DATA,
|
||||
TEST_DEFAULT_IMPORT_CONFIG,
|
||||
mock_get_version_update,
|
||||
setup_version_integration,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_sensor_wrapper(
|
||||
hass: HomeAssistant, config: dict[str, Any]
|
||||
) -> ConfigEntry:
|
||||
"""Set up the Version sensor platform."""
|
||||
with patch(
|
||||
"pyhaversion.HaVersion.get_version",
|
||||
return_value=(MOCK_VERSION, MOCK_VERSION_DATA),
|
||||
):
|
||||
assert await async_setup_component(
|
||||
hass, "sensor", {"sensor": {"platform": DOMAIN, **config}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
config_entry = config_entries[-1]
|
||||
assert config_entry.source == "import"
|
||||
return config_entry
|
||||
from .common import MOCK_VERSION, mock_get_version_update, setup_version_integration
|
||||
|
||||
|
||||
async def test_version_sensor(hass: HomeAssistant):
|
||||
|
@ -73,60 +31,3 @@ async def test_update(hass: HomeAssistant, caplog: pytest.LogCaptureFixture):
|
|||
await mock_get_version_update(hass, side_effect=HaVersionException)
|
||||
assert hass.states.get("sensor.local_installation").state == "unavailable"
|
||||
assert "Error fetching version data" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"yaml,converted",
|
||||
(
|
||||
(
|
||||
{},
|
||||
TEST_DEFAULT_IMPORT_CONFIG,
|
||||
),
|
||||
(
|
||||
{CONF_NAME: "test"},
|
||||
{**TEST_DEFAULT_IMPORT_CONFIG, CONF_NAME: "test"},
|
||||
),
|
||||
(
|
||||
{CONF_SOURCE: "hassio", CONF_IMAGE: "odroid-n2"},
|
||||
{
|
||||
**TEST_DEFAULT_IMPORT_CONFIG,
|
||||
CONF_NAME: DEFAULT_NAME_LATEST,
|
||||
CONF_SOURCE: HaVersionSource.SUPERVISOR,
|
||||
CONF_VERSION_SOURCE: VERSION_SOURCE_VERSIONS,
|
||||
CONF_IMAGE: "odroid-n2",
|
||||
},
|
||||
),
|
||||
(
|
||||
{CONF_SOURCE: "docker"},
|
||||
{
|
||||
**TEST_DEFAULT_IMPORT_CONFIG,
|
||||
CONF_NAME: DEFAULT_NAME_LATEST,
|
||||
CONF_SOURCE: HaVersionSource.CONTAINER,
|
||||
CONF_VERSION_SOURCE: VERSION_SOURCE_DOCKER_HUB,
|
||||
},
|
||||
),
|
||||
(
|
||||
{CONF_BETA: True},
|
||||
{
|
||||
**TEST_DEFAULT_IMPORT_CONFIG,
|
||||
CONF_CHANNEL: HaVersionChannel.BETA,
|
||||
},
|
||||
),
|
||||
(
|
||||
{CONF_SOURCE: "container", CONF_IMAGE: "odroid-n2"},
|
||||
{
|
||||
**TEST_DEFAULT_IMPORT_CONFIG,
|
||||
CONF_NAME: DEFAULT_NAME_LATEST,
|
||||
CONF_SOURCE: HaVersionSource.CONTAINER,
|
||||
CONF_VERSION_SOURCE: VERSION_SOURCE_DOCKER_HUB,
|
||||
CONF_IMAGE: "odroid-n2-homeassistant",
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
async def test_config_import(
|
||||
hass: HomeAssistant, yaml: dict[str, Any], converted: dict[str, Any]
|
||||
) -> None:
|
||||
"""Test importing YAML configuration."""
|
||||
config_entry = await async_setup_sensor_wrapper(hass, yaml)
|
||||
assert config_entry.data == converted
|
||||
|
|
Loading…
Reference in New Issue