mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Remove YAML support from nexia (#45379)
This commit is contained in:
parent
5de8639798
commit
db83aea1df
@ -6,9 +6,8 @@ import logging
|
|||||||
|
|
||||||
from nexia.home import NexiaHome
|
from nexia.home import NexiaHome
|
||||||
from requests.exceptions import ConnectTimeout, HTTPError
|
from requests.exceptions import ConnectTimeout, HTTPError
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
@ -20,19 +19,7 @@ from .util import is_invalid_auth_code
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
|
||||||
{
|
|
||||||
DOMAIN: vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
},
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
DEFAULT_UPDATE_RATE = 120
|
DEFAULT_UPDATE_RATE = 120
|
||||||
|
|
||||||
@ -40,17 +27,8 @@ DEFAULT_UPDATE_RATE = 120
|
|||||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||||
"""Set up the nexia component from YAML."""
|
"""Set up the nexia component from YAML."""
|
||||||
|
|
||||||
conf = config.get(DOMAIN)
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
if not conf:
|
|
||||||
return True
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,13 +79,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, user_input):
|
|
||||||
"""Handle import."""
|
|
||||||
for entry in self._async_current_entries():
|
|
||||||
if entry.data[CONF_USERNAME] == user_input[CONF_USERNAME]:
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
return await self.async_step_user(user_input)
|
|
||||||
|
|
||||||
|
|
||||||
class CannotConnect(exceptions.HomeAssistantError):
|
class CannotConnect(exceptions.HomeAssistantError):
|
||||||
"""Error to indicate we cannot connect."""
|
"""Error to indicate we cannot connect."""
|
||||||
|
@ -139,45 +139,3 @@ async def test_form_broad_exception(hass):
|
|||||||
|
|
||||||
assert result2["type"] == "form"
|
assert result2["type"] == "form"
|
||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_import(hass):
|
|
||||||
"""Test we get the form with import source."""
|
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.nexia.config_flow.NexiaHome.get_name",
|
|
||||||
return_value="myhouse",
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.nexia.config_flow.NexiaHome.login",
|
|
||||||
side_effect=MagicMock(),
|
|
||||||
), patch(
|
|
||||||
"homeassistant.components.nexia.async_setup", return_value=True
|
|
||||||
) as mock_setup, patch(
|
|
||||||
"homeassistant.components.nexia.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry:
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == "create_entry"
|
|
||||||
assert result["title"] == "myhouse"
|
|
||||||
assert result["data"] == {
|
|
||||||
CONF_USERNAME: "username",
|
|
||||||
CONF_PASSWORD: "password",
|
|
||||||
}
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={CONF_USERNAME: "username", CONF_PASSWORD: "password"},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result2["type"] == "abort"
|
|
||||||
assert result2["reason"] == "already_configured"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user