mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove YAML configuration from Daikin (#50080)
This commit is contained in:
parent
4cf910affc
commit
4907764367
@ -6,10 +6,9 @@ import logging
|
|||||||
from aiohttp import ClientConnectionError
|
from aiohttp import ClientConnectionError
|
||||||
from async_timeout import timeout
|
from async_timeout import timeout
|
||||||
from pydaikin.daikin_base import Appliance
|
from pydaikin.daikin_base import Appliance
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_HOSTS, CONF_PASSWORD
|
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -25,52 +24,16 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
|||||||
|
|
||||||
PLATFORMS = ["climate", "sensor", "switch"]
|
PLATFORMS = ["climate", "sensor", "switch"]
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Establish connection with Daikin."""
|
"""Establish connection with Daikin."""
|
||||||
conf = entry.data
|
conf = entry.data
|
||||||
# For backwards compat, set unique ID
|
# For backwards compat, set unique ID
|
||||||
if entry.unique_id is None:
|
if entry.unique_id is None or ".local" in entry.unique_id:
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
|
|
||||||
elif ".local" in entry.unique_id:
|
|
||||||
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
|
hass.config_entries.async_update_entry(entry, unique_id=conf[KEY_MAC])
|
||||||
|
|
||||||
daikin_api = await daikin_api_setup(
|
daikin_api = await daikin_api_setup(
|
||||||
hass,
|
hass,
|
||||||
conf[CONF_HOST],
|
conf[CONF_HOST],
|
||||||
@ -80,6 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
)
|
)
|
||||||
if not daikin_api:
|
if not daikin_api:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api})
|
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api})
|
||||||
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
||||||
return True
|
return True
|
||||||
|
@ -115,13 +115,6 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
user_input.get(CONF_PASSWORD),
|
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):
|
async def async_step_zeroconf(self, discovery_info):
|
||||||
"""Prepare configuration for a discovered Daikin device."""
|
"""Prepare configuration for a discovered Daikin device."""
|
||||||
_LOGGER.debug("Zeroconf user_input: %s", discovery_info)
|
_LOGGER.debug("Zeroconf user_input: %s", discovery_info)
|
||||||
|
@ -8,7 +8,7 @@ from aiohttp.web_exceptions import HTTPForbidden
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.daikin.const import KEY_MAC
|
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.const import CONF_HOST
|
||||||
from homeassistant.data_entry_flow import (
|
from homeassistant.data_entry_flow import (
|
||||||
RESULT_TYPE_ABORT,
|
RESULT_TYPE_ABORT,
|
||||||
@ -80,27 +80,6 @@ async def test_abort_if_already_setup(hass, mock_daikin):
|
|||||||
assert result["reason"] == "already_configured"
|
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(
|
@pytest.mark.parametrize(
|
||||||
"s_effect,reason",
|
"s_effect,reason",
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user