Remove YAML configuration from Jandy iAqualink (#72404)

This commit is contained in:
epenet 2022-05-24 10:49:05 +02:00 committed by GitHub
parent 3cd398a5bd
commit cc162bf691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 69 deletions

View File

@ -19,9 +19,7 @@ from iaqualink.device import (
) )
from iaqualink.exception import AqualinkServiceException from iaqualink.exception import AqualinkServiceException
from typing_extensions import Concatenate, ParamSpec from typing_extensions import Concatenate, ParamSpec
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN from homeassistant.components.light import DOMAIN as LIGHT_DOMAIN
@ -32,14 +30,12 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import ( from homeassistant.helpers.dispatcher import (
async_dispatcher_connect, async_dispatcher_connect,
async_dispatcher_send, async_dispatcher_send,
) )
from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN, UPDATE_INTERVAL from .const import DOMAIN, UPDATE_INTERVAL
@ -52,42 +48,13 @@ ATTR_CONFIG = "config"
PARALLEL_UPDATES = 0 PARALLEL_UPDATES = 0
PLATFORMS = [ PLATFORMS = [
BINARY_SENSOR_DOMAIN, Platform.BINARY_SENSOR,
CLIMATE_DOMAIN, Platform.CLIMATE,
LIGHT_DOMAIN, Platform.LIGHT,
SENSOR_DOMAIN, Platform.SENSOR,
SWITCH_DOMAIN, Platform.SWITCH,
] ]
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Aqualink component."""
if (conf := config.get(DOMAIN)) is not None:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=conf,
)
)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Aqualink from a config entry.""" """Set up Aqualink from a config entry."""

View File

@ -12,6 +12,7 @@ import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.data_entry_flow import FlowResult
from .const import DOMAIN from .const import DOMAIN
@ -21,7 +22,9 @@ class AqualinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
async def async_step_user(self, user_input: dict[str, Any] | None = None): async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle a flow start.""" """Handle a flow start."""
# Supporting a single account. # Supporting a single account.
entries = self._async_current_entries() entries = self._async_current_entries()
@ -54,7 +57,3 @@ class AqualinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
), ),
errors=errors, errors=errors,
) )
async def async_step_import(self, user_input: dict[str, Any] | None = None):
"""Occurs when an entry is setup through config."""
return await self.async_step_user(user_input)

View File

@ -5,13 +5,11 @@ from iaqualink.exception import (
AqualinkServiceException, AqualinkServiceException,
AqualinkServiceUnauthorizedException, AqualinkServiceUnauthorizedException,
) )
import pytest
from homeassistant.components.iaqualink import config_flow from homeassistant.components.iaqualink import config_flow
@pytest.mark.parametrize("step", ["import", "user"]) async def test_already_configured(hass, config_entry, config_data):
async def test_already_configured(hass, config_entry, config_data, step):
"""Test config flow when iaqualink component is already setup.""" """Test config flow when iaqualink component is already setup."""
config_entry.add_to_hass(hass) config_entry.add_to_hass(hass)
@ -19,81 +17,67 @@ async def test_already_configured(hass, config_entry, config_data, step):
flow.hass = hass flow.hass = hass
flow.context = {} flow.context = {}
fname = f"async_step_{step}" result = await flow.async_step_user(config_data)
func = getattr(flow, fname)
result = await func(config_data)
assert result["type"] == "abort" assert result["type"] == "abort"
@pytest.mark.parametrize("step", ["import", "user"]) async def test_without_config(hass):
async def test_without_config(hass, step):
"""Test config flow with no configuration.""" """Test config flow with no configuration."""
flow = config_flow.AqualinkFlowHandler() flow = config_flow.AqualinkFlowHandler()
flow.hass = hass flow.hass = hass
flow.context = {} flow.context = {}
fname = f"async_step_{step}" result = await flow.async_step_user()
func = getattr(flow, fname)
result = await func()
assert result["type"] == "form" assert result["type"] == "form"
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {} assert result["errors"] == {}
@pytest.mark.parametrize("step", ["import", "user"]) async def test_with_invalid_credentials(hass, config_data):
async def test_with_invalid_credentials(hass, config_data, step):
"""Test config flow with invalid username and/or password.""" """Test config flow with invalid username and/or password."""
flow = config_flow.AqualinkFlowHandler() flow = config_flow.AqualinkFlowHandler()
flow.hass = hass flow.hass = hass
fname = f"async_step_{step}"
func = getattr(flow, fname)
with patch( with patch(
"homeassistant.components.iaqualink.config_flow.AqualinkClient.login", "homeassistant.components.iaqualink.config_flow.AqualinkClient.login",
side_effect=AqualinkServiceUnauthorizedException, side_effect=AqualinkServiceUnauthorizedException,
): ):
result = await func(config_data) result = await flow.async_step_user(config_data)
assert result["type"] == "form" assert result["type"] == "form"
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {"base": "invalid_auth"} assert result["errors"] == {"base": "invalid_auth"}
@pytest.mark.parametrize("step", ["import", "user"]) async def test_service_exception(hass, config_data):
async def test_service_exception(hass, config_data, step):
"""Test config flow encountering service exception.""" """Test config flow encountering service exception."""
flow = config_flow.AqualinkFlowHandler() flow = config_flow.AqualinkFlowHandler()
flow.hass = hass flow.hass = hass
fname = f"async_step_{step}"
func = getattr(flow, fname)
with patch( with patch(
"homeassistant.components.iaqualink.config_flow.AqualinkClient.login", "homeassistant.components.iaqualink.config_flow.AqualinkClient.login",
side_effect=AqualinkServiceException, side_effect=AqualinkServiceException,
): ):
result = await func(config_data) result = await flow.async_step_user(config_data)
assert result["type"] == "form" assert result["type"] == "form"
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
@pytest.mark.parametrize("step", ["import", "user"]) async def test_with_existing_config(hass, config_data):
async def test_with_existing_config(hass, config_data, step):
"""Test config flow with existing configuration.""" """Test config flow with existing configuration."""
flow = config_flow.AqualinkFlowHandler() flow = config_flow.AqualinkFlowHandler()
flow.hass = hass flow.hass = hass
flow.context = {} flow.context = {}
fname = f"async_step_{step}"
func = getattr(flow, fname)
with patch( with patch(
"homeassistant.components.iaqualink.config_flow.AqualinkClient.login", "homeassistant.components.iaqualink.config_flow.AqualinkClient.login",
return_value=None, return_value=None,
): ):
result = await func(config_data) result = await flow.async_step_user(config_data)
assert result["type"] == "create_entry" assert result["type"] == "create_entry"
assert result["title"] == config_data["username"] assert result["title"] == config_data["username"]