From 490776436739bdadc701094594cf10fe2133e63b Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 4 May 2021 23:23:59 +0200 Subject: [PATCH] Remove YAML configuration from Daikin (#50080) --- homeassistant/components/daikin/__init__.py | 48 +++---------------- .../components/daikin/config_flow.py | 7 --- tests/components/daikin/test_config_flow.py | 23 +-------- 3 files changed, 7 insertions(+), 71 deletions(-) diff --git a/homeassistant/components/daikin/__init__.py b/homeassistant/components/daikin/__init__.py index fb38c38db0a..9d0d189248f 100644 --- a/homeassistant/components/daikin/__init__.py +++ b/homeassistant/components/daikin/__init__.py @@ -6,10 +6,9 @@ import logging from aiohttp import ClientConnectionError from async_timeout import timeout from pydaikin.daikin_base import Appliance -import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry -from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_HOSTS, CONF_PASSWORD +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady import homeassistant.helpers.config_validation as cv @@ -25,52 +24,16 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60) PLATFORMS = ["climate", "sensor", "switch"] -CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.Schema( - { - vol.Optional(CONF_HOSTS, default=[]): vol.All( - cv.ensure_list, [cv.string] - ) - } - ) - }, - ), - extra=vol.ALLOW_EXTRA, -) - - -async def async_setup(hass, config): - """Establish connection with Daikin.""" - if DOMAIN not in config: - return True - - hosts = config[DOMAIN][CONF_HOSTS] - if not hosts: - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT} - ) - ) - for host in hosts: - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, context={"source": SOURCE_IMPORT}, data={CONF_HOST: host} - ) - ) - return True +CONFIG_SCHEMA = cv.deprecated(DOMAIN) async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Establish connection with Daikin.""" conf = entry.data # For backwards compat, set unique ID - if entry.unique_id is None: - hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC]) - elif ".local" in entry.unique_id: + if entry.unique_id is None or ".local" in entry.unique_id: hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC]) + daikin_api = await daikin_api_setup( hass, conf[CONF_HOST], @@ -80,6 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): ) if not daikin_api: return False + hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api}) hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True diff --git a/homeassistant/components/daikin/config_flow.py b/homeassistant/components/daikin/config_flow.py index 9e980bed196..ea0709e5557 100644 --- a/homeassistant/components/daikin/config_flow.py +++ b/homeassistant/components/daikin/config_flow.py @@ -115,13 +115,6 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): user_input.get(CONF_PASSWORD), ) - async def async_step_import(self, user_input): - """Import a config entry.""" - host = user_input.get(CONF_HOST) - if not host: - return await self.async_step_user() - return await self._create_device(host) - async def async_step_zeroconf(self, discovery_info): """Prepare configuration for a discovered Daikin device.""" _LOGGER.debug("Zeroconf user_input: %s", discovery_info) diff --git a/tests/components/daikin/test_config_flow.py b/tests/components/daikin/test_config_flow.py index 076f9f54878..624268d7ee3 100644 --- a/tests/components/daikin/test_config_flow.py +++ b/tests/components/daikin/test_config_flow.py @@ -8,7 +8,7 @@ from aiohttp.web_exceptions import HTTPForbidden import pytest from homeassistant.components.daikin.const import KEY_MAC -from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER, SOURCE_ZEROCONF +from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_HOST from homeassistant.data_entry_flow import ( RESULT_TYPE_ABORT, @@ -80,27 +80,6 @@ async def test_abort_if_already_setup(hass, mock_daikin): assert result["reason"] == "already_configured" -async def test_import(hass, mock_daikin): - """Test import step.""" - result = await hass.config_entries.flow.async_init( - "daikin", - context={"source": SOURCE_IMPORT}, - data={}, - ) - assert result["type"] == RESULT_TYPE_FORM - assert result["step_id"] == "user" - - result = await hass.config_entries.flow.async_init( - "daikin", - context={"source": SOURCE_IMPORT}, - data={CONF_HOST: HOST}, - ) - assert result["type"] == RESULT_TYPE_CREATE_ENTRY - assert result["title"] == HOST - assert result["data"][CONF_HOST] == HOST - assert result["data"][KEY_MAC] == MAC - - @pytest.mark.parametrize( "s_effect,reason", [