Remove Volvooncall integration yaml import (#90288)

Depr yaml import
This commit is contained in:
G Johansson 2023-03-26 09:42:38 +02:00 committed by GitHub
parent b3f3f234c6
commit e8f3b9c09a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 121 deletions

View file

@ -4,28 +4,21 @@ import logging
from aiohttp.client_exceptions import ClientResponseError
import async_timeout
import voluptuous as vol
from volvooncall import Connection
from volvooncall.dashboard import Instrument
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD,
CONF_REGION,
CONF_RESOURCES,
CONF_SCAN_INTERVAL,
CONF_UNIT_SYSTEM,
CONF_USERNAME,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -35,11 +28,9 @@ from homeassistant.helpers.update_coordinator import (
from .const import (
CONF_MUTABLE,
CONF_SCANDINAVIAN_MILES,
CONF_SERVICE_URL,
DEFAULT_UPDATE_INTERVAL,
DOMAIN,
PLATFORMS,
RESOURCES,
UNIT_SYSTEM_IMPERIAL,
UNIT_SYSTEM_METRIC,
UNIT_SYSTEM_SCANDINAVIAN_MILES,
@ -49,68 +40,6 @@ from .errors import InvalidAuth
_LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_UPDATE_INTERVAL
): vol.All(cv.time_period, vol.Clamp(min=DEFAULT_UPDATE_INTERVAL)),
vol.Optional(CONF_NAME, default={}): cv.schema_with_slug_keys(
cv.string
),
vol.Optional(CONF_RESOURCES): vol.All(
cv.ensure_list, [vol.In(RESOURCES)]
),
vol.Optional(CONF_REGION): cv.string,
vol.Optional(CONF_SERVICE_URL): cv.string,
vol.Optional(CONF_MUTABLE, default=True): cv.boolean,
vol.Optional(CONF_SCANDINAVIAN_MILES, default=False): cv.boolean,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Migrate from YAML to ConfigEntry."""
if DOMAIN not in config:
return True
hass.data[DOMAIN] = {}
if not hass.config_entries.async_entries(DOMAIN):
new_conf = {}
new_conf[CONF_USERNAME] = config[DOMAIN][CONF_USERNAME]
new_conf[CONF_PASSWORD] = config[DOMAIN][CONF_PASSWORD]
new_conf[CONF_REGION] = config[DOMAIN].get(CONF_REGION)
new_conf[CONF_SCANDINAVIAN_MILES] = config[DOMAIN][CONF_SCANDINAVIAN_MILES]
new_conf[CONF_MUTABLE] = config[DOMAIN][CONF_MUTABLE]
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=new_conf
)
)
async_create_issue(
hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version=None,
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up the Volvo On Call component from a ConfigEntry."""

View file

@ -106,10 +106,6 @@ class VolvoOnCallConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
step_id="user", data_schema=user_schema, errors=errors
)
async def async_step_import(self, import_data) -> FlowResult:
"""Import volvooncall config from configuration.yaml."""
return await self.async_step_user(import_data)
async def async_step_reauth(self, user_input: Mapping[str, Any]) -> FlowResult:
"""Perform reauth upon an API authentication error."""
self._reauth_entry = self.hass.config_entries.async_get_entry(

View file

@ -19,11 +19,5 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
},
"issues": {
"deprecated_yaml": {
"title": "The Volvo On Call YAML configuration is being removed",
"description": "Configuring the Volvo On Call platform using YAML is being removed in a future release of Home Assistant.\n\nYour existing configuration has been imported into the UI automatically. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
}
}

View file

@ -130,45 +130,6 @@ async def test_form_other_exception(hass: HomeAssistant) -> None:
assert result2["errors"] == {"base": "unknown"}
async def test_import(hass: HomeAssistant) -> None:
"""Test a YAML import."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}
)
assert result["type"] == FlowResultType.FORM
assert len(result["errors"]) == 0
with patch("volvooncall.Connection.get"), patch(
"homeassistant.components.volvooncall.async_setup",
return_value=True,
), patch(
"homeassistant.components.volvooncall.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
"region": "na",
"unit_system": "metric",
"mutable": True,
},
)
await hass.async_block_till_done()
assert result2["type"] == FlowResultType.CREATE_ENTRY
assert result2["title"] == "test-username"
assert result2["data"] == {
"username": "test-username",
"password": "test-password",
"region": "na",
"unit_system": "metric",
"mutable": True,
}
assert len(mock_setup_entry.mock_calls) == 1
async def test_reauth(hass: HomeAssistant) -> None:
"""Test that we handle the reauth flow."""