Remove deprecated Vallox YAML configuration (#91096)
Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
7e041a95c9
commit
e680ec6247
3 changed files with 3 additions and 193 deletions
|
@ -17,12 +17,12 @@ from vallox_websocket_api.vallox import (
|
||||||
)
|
)
|
||||||
import voluptuous as vol
|
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_NAME, Platform
|
from homeassistant.const import CONF_HOST, CONF_NAME, Platform
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.typing import ConfigType, StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
|
@ -159,22 +159,6 @@ class ValloxDataUpdateCoordinator(DataUpdateCoordinator[ValloxState]):
|
||||||
"""The DataUpdateCoordinator for Vallox."""
|
"""The DataUpdateCoordinator for Vallox."""
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
||||||
"""Set up the integration from configuration.yaml (DEPRECATED)."""
|
|
||||||
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 client and boot the platforms."""
|
"""Set up the client and boot the platforms."""
|
||||||
host = entry.data[CONF_HOST]
|
host = entry.data[CONF_HOST]
|
||||||
|
|
|
@ -40,38 +40,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_import(self, data: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Handle import from YAML."""
|
|
||||||
# We need to use the name from the YAML configuration to avoid
|
|
||||||
# breaking existing entity IDs.
|
|
||||||
name = data.get(CONF_NAME, DEFAULT_NAME)
|
|
||||||
host = data[CONF_HOST]
|
|
||||||
|
|
||||||
self._async_abort_entries_match({CONF_HOST: host})
|
|
||||||
|
|
||||||
reason = None
|
|
||||||
try:
|
|
||||||
await validate_host(self.hass, host)
|
|
||||||
except InvalidHost:
|
|
||||||
_LOGGER.error("An invalid host is configured for Vallox: %s", host)
|
|
||||||
reason = "invalid_host"
|
|
||||||
except ValloxApiException:
|
|
||||||
_LOGGER.error("Cannot connect to Vallox host %s", host)
|
|
||||||
reason = "cannot_connect"
|
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
_LOGGER.exception("Unexpected exception")
|
|
||||||
reason = "unknown"
|
|
||||||
else:
|
|
||||||
return self.async_create_entry(
|
|
||||||
title=name,
|
|
||||||
data={
|
|
||||||
**data,
|
|
||||||
CONF_NAME: name,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.async_abort(reason=reason)
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
||||||
from vallox_websocket_api import ValloxApiException, ValloxWebsocketException
|
from vallox_websocket_api import ValloxApiException, ValloxWebsocketException
|
||||||
|
|
||||||
from homeassistant.components.vallox.const import DOMAIN
|
from homeassistant.components.vallox.const 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_NAME
|
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
@ -150,145 +150,3 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
assert result["type"] == FlowResultType.ABORT
|
||||||
assert result["reason"] == "already_configured"
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_with_custom_name(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that import is handled."""
|
|
||||||
name = "Vallox 90 MV"
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.vallox.config_flow.Vallox.get_info",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.vallox.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry:
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "1.2.3.4", "name": name},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == name
|
|
||||||
assert result["data"] == {"host": "1.2.3.4", "name": "Vallox 90 MV"}
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_without_custom_name(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that import is handled."""
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.vallox.config_flow.Vallox.get_info",
|
|
||||||
return_value=None,
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.vallox.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry:
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "1.2.3.4"},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == "Vallox"
|
|
||||||
assert result["data"] == {"host": "1.2.3.4", "name": "Vallox"}
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_invalid_ip(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that invalid IP error is handled during import."""
|
|
||||||
name = "Vallox 90 MV"
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "vallox90mv.host.name", "name": name},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "invalid_host"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_already_configured(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that an already configured Vallox device is handled during import."""
|
|
||||||
name = "Vallox 145 MV"
|
|
||||||
|
|
||||||
mock_entry = MockConfigEntry(
|
|
||||||
domain=DOMAIN,
|
|
||||||
data={
|
|
||||||
CONF_HOST: "40.10.20.30",
|
|
||||||
CONF_NAME: "Vallox 145 MV",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
mock_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "40.10.20.30", "name": name},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_cannot_connect_os_error(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that cannot connect error is handled."""
|
|
||||||
name = "Vallox 90 MV"
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.vallox.config_flow.Vallox.get_info",
|
|
||||||
side_effect=ValloxWebsocketException,
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "1.2.3.4", "name": name},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "cannot_connect"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_cannot_connect_vallox_api_exception(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that cannot connect error is handled."""
|
|
||||||
name = "Vallox 90 MV"
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.vallox.config_flow.Vallox.get_info",
|
|
||||||
side_effect=ValloxApiException,
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "5.6.3.1", "name": name},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "cannot_connect"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_unknown_exception(hass: HomeAssistant) -> None:
|
|
||||||
"""Test that unknown exceptions are handled."""
|
|
||||||
name = "Vallox 245 MV"
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.vallox.config_flow.Vallox.get_info",
|
|
||||||
side_effect=Exception,
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={"host": "1.2.3.4", "name": name},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "unknown"
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue