mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Remove deprecated yaml import for velux (#123724)
This commit is contained in:
parent
d8b13c8c02
commit
f46fe7eeb2
@ -1,48 +1,14 @@
|
|||||||
"""Support for VELUX KLF 200 devices."""
|
"""Support for VELUX KLF 200 devices."""
|
||||||
|
|
||||||
from pyvlx import Node, PyVLX, PyVLXException
|
from pyvlx import Node, PyVLX, PyVLXException
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER, PLATFORMS
|
from .const import DOMAIN, LOGGER, PLATFORMS
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
|
||||||
vol.All(
|
|
||||||
cv.deprecated(DOMAIN),
|
|
||||||
{
|
|
||||||
DOMAIN: vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_HOST): cv.string,
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
||||||
"""Set up the velux component."""
|
|
||||||
if DOMAIN not in config:
|
|
||||||
return True
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=config[DOMAIN],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up the velux component."""
|
"""Set up the velux component."""
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
"""Config flow for Velux integration."""
|
"""Config flow for Velux integration."""
|
||||||
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from pyvlx import PyVLX, PyVLXException
|
from pyvlx import PyVLX, PyVLXException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
|
|
||||||
@ -24,59 +20,6 @@ DATA_SCHEMA = vol.Schema(
|
|||||||
class VeluxConfigFlow(ConfigFlow, domain=DOMAIN):
|
class VeluxConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for velux."""
|
"""Handle a config flow for velux."""
|
||||||
|
|
||||||
async def async_step_import(self, config: dict[str, Any]) -> ConfigFlowResult:
|
|
||||||
"""Import a config entry."""
|
|
||||||
|
|
||||||
def create_repair(error: str | None = None) -> None:
|
|
||||||
if error:
|
|
||||||
async_create_issue(
|
|
||||||
self.hass,
|
|
||||||
DOMAIN,
|
|
||||||
f"deprecated_yaml_import_issue_{error}",
|
|
||||||
breaks_in_ha_version="2024.9.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key=f"deprecated_yaml_import_issue_{error}",
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
async_create_issue(
|
|
||||||
self.hass,
|
|
||||||
HOMEASSISTANT_DOMAIN,
|
|
||||||
f"deprecated_yaml_{DOMAIN}",
|
|
||||||
breaks_in_ha_version="2024.9.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key="deprecated_yaml",
|
|
||||||
translation_placeholders={
|
|
||||||
"domain": DOMAIN,
|
|
||||||
"integration_title": "Velux",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
for entry in self._async_current_entries():
|
|
||||||
if entry.data[CONF_HOST] == config[CONF_HOST]:
|
|
||||||
create_repair()
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
|
|
||||||
pyvlx = PyVLX(host=config[CONF_HOST], password=config[CONF_PASSWORD])
|
|
||||||
try:
|
|
||||||
await pyvlx.connect()
|
|
||||||
await pyvlx.disconnect()
|
|
||||||
except (PyVLXException, ConnectionError):
|
|
||||||
create_repair("cannot_connect")
|
|
||||||
return self.async_abort(reason="cannot_connect")
|
|
||||||
except Exception: # noqa: BLE001
|
|
||||||
create_repair("unknown")
|
|
||||||
return self.async_abort(reason="unknown")
|
|
||||||
|
|
||||||
create_repair()
|
|
||||||
return self.async_create_entry(
|
|
||||||
title=config[CONF_HOST],
|
|
||||||
data=config,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, str] | None = None
|
self, user_input: dict[str, str] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
|
@ -17,16 +17,6 @@
|
|||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"issues": {
|
|
||||||
"deprecated_yaml_import_issue_cannot_connect": {
|
|
||||||
"title": "The Velux YAML configuration import cannot connect to server",
|
|
||||||
"description": "Configuring Velux using YAML is being removed but there was an connection error importing your YAML configuration.\n\nMake sure your home assistant can reach the KLF 200."
|
|
||||||
},
|
|
||||||
"deprecated_yaml_import_issue_unknown": {
|
|
||||||
"title": "The Velux YAML configuration import failed with unknown error raised by pyvlx",
|
|
||||||
"description": "Configuring Velux using YAML is being removed but there was an unknown error importing your YAML configuration.\n\nCheck your configuration or have a look at the documentation of the integration."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": {
|
"services": {
|
||||||
"reboot_gateway": {
|
"reboot_gateway": {
|
||||||
"name": "Reboot gateway",
|
"name": "Reboot gateway",
|
||||||
|
@ -10,7 +10,7 @@ import pytest
|
|||||||
from pyvlx import PyVLXException
|
from pyvlx import PyVLXException
|
||||||
|
|
||||||
from homeassistant.components.velux import DOMAIN
|
from homeassistant.components.velux import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -69,22 +69,8 @@ async def test_user_errors(
|
|||||||
assert result["errors"] == {"base": error_name}
|
assert result["errors"] == {"base": error_name}
|
||||||
|
|
||||||
|
|
||||||
async def test_import_valid_config(hass: HomeAssistant) -> None:
|
async def test_flow_duplicate_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test import initialized flow with valid config."""
|
"""Test initialized flow with a duplicate entry."""
|
||||||
with patch(PYVLX_CONFIG_FLOW_CLASS_PATH, autospec=True):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=DUMMY_DATA,
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == DUMMY_DATA[CONF_HOST]
|
|
||||||
assert result["data"] == DUMMY_DATA
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("flow_source", [SOURCE_IMPORT, SOURCE_USER])
|
|
||||||
async def test_flow_duplicate_entry(hass: HomeAssistant, flow_source: str) -> None:
|
|
||||||
"""Test import initialized flow with a duplicate entry."""
|
|
||||||
with patch(PYVLX_CONFIG_FLOW_CLASS_PATH, autospec=True):
|
with patch(PYVLX_CONFIG_FLOW_CLASS_PATH, autospec=True):
|
||||||
conf_entry: MockConfigEntry = MockConfigEntry(
|
conf_entry: MockConfigEntry = MockConfigEntry(
|
||||||
domain=DOMAIN, title=DUMMY_DATA[CONF_HOST], data=DUMMY_DATA
|
domain=DOMAIN, title=DUMMY_DATA[CONF_HOST], data=DUMMY_DATA
|
||||||
@ -94,26 +80,8 @@ async def test_flow_duplicate_entry(hass: HomeAssistant, flow_source: str) -> No
|
|||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": flow_source},
|
context={"source": SOURCE_USER},
|
||||||
data=DUMMY_DATA,
|
data=DUMMY_DATA,
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(("error", "error_name"), error_types_to_test)
|
|
||||||
async def test_import_errors(
|
|
||||||
hass: HomeAssistant, error: Exception, error_name: str
|
|
||||||
) -> None:
|
|
||||||
"""Test import initialized flow with exceptions."""
|
|
||||||
with patch(
|
|
||||||
PYVLX_CONFIG_FLOW_CONNECT_FUNCTION_PATH,
|
|
||||||
side_effect=error,
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=DUMMY_DATA,
|
|
||||||
)
|
|
||||||
assert result["type"] is FlowResultType.ABORT
|
|
||||||
assert result["reason"] == error_name
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user