mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Remove YAML configuration from SolarEdge (#50105)
* Remove YAML configuration from SolarEdge * Restore already setup tests
This commit is contained in:
parent
2bff7f8020
commit
cbf4632895
@ -1,45 +1,13 @@
|
|||||||
"""The solaredge integration."""
|
"""The solaredge integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
from .const import CONF_SITE_ID, DEFAULT_NAME, DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
vol.All(
|
|
||||||
cv.deprecated(DOMAIN),
|
|
||||||
{
|
|
||||||
DOMAIN: vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
|
||||||
vol.Required(CONF_SITE_ID): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: dict[str, Any]) -> bool:
|
|
||||||
"""Platform setup, do nothing."""
|
|
||||||
if DOMAIN not in config:
|
|
||||||
return True
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=dict(config[DOMAIN])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
@ -89,11 +89,3 @@ class SolarEdgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
),
|
),
|
||||||
errors=self._errors,
|
errors=self._errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(
|
|
||||||
self, user_input: dict[str, Any] | None = None
|
|
||||||
) -> FlowResult:
|
|
||||||
"""Import a config entry."""
|
|
||||||
if self._site_in_configuration_exists(user_input[CONF_SITE_ID]):
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
return await self.async_step_user(user_input)
|
|
||||||
|
@ -51,43 +51,14 @@ async def test_user(hass: HomeAssistant, test_api: Mock) -> None:
|
|||||||
assert result["data"][CONF_API_KEY] == API_KEY
|
assert result["data"][CONF_API_KEY] == API_KEY
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass: HomeAssistant, test_api: Mock) -> None:
|
|
||||||
"""Test import step."""
|
|
||||||
flow = init_config_flow(hass)
|
|
||||||
|
|
||||||
# import with site_id and api_key
|
|
||||||
result = await flow.async_step_import(
|
|
||||||
{CONF_API_KEY: API_KEY, CONF_SITE_ID: SITE_ID}
|
|
||||||
)
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["title"] == "solaredge"
|
|
||||||
assert result["data"][CONF_SITE_ID] == SITE_ID
|
|
||||||
assert result["data"][CONF_API_KEY] == API_KEY
|
|
||||||
|
|
||||||
# import with all
|
|
||||||
result = await flow.async_step_import(
|
|
||||||
{CONF_API_KEY: API_KEY, CONF_SITE_ID: SITE_ID, CONF_NAME: NAME}
|
|
||||||
)
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
||||||
assert result["title"] == "solaredge_site_1_2_3"
|
|
||||||
assert result["data"][CONF_SITE_ID] == SITE_ID
|
|
||||||
assert result["data"][CONF_API_KEY] == API_KEY
|
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_already_setup(hass: HomeAssistant, test_api: str) -> None:
|
async def test_abort_if_already_setup(hass: HomeAssistant, test_api: str) -> None:
|
||||||
"""Test we abort if the site_id is already setup."""
|
"""Test we abort if the site_id is already setup."""
|
||||||
flow = init_config_flow(hass)
|
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain="solaredge",
|
domain="solaredge",
|
||||||
data={CONF_NAME: DEFAULT_NAME, CONF_SITE_ID: SITE_ID, CONF_API_KEY: API_KEY},
|
data={CONF_NAME: DEFAULT_NAME, CONF_SITE_ID: SITE_ID, CONF_API_KEY: API_KEY},
|
||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
|
||||||
# import: Should fail, same SITE_ID
|
flow = init_config_flow(hass)
|
||||||
result = await flow.async_step_import(
|
|
||||||
{CONF_NAME: DEFAULT_NAME, CONF_SITE_ID: SITE_ID, CONF_API_KEY: API_KEY}
|
|
||||||
)
|
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
# user: Should fail, same SITE_ID
|
# user: Should fail, same SITE_ID
|
||||||
result = await flow.async_step_user(
|
result = await flow.async_step_user(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user