mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Cleanup unused import in solarlog config flow (#124713)
This commit is contained in:
parent
35d318818a
commit
18b49a6f62
@ -101,23 +101,6 @@ class SolarLogConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors=self._errors,
|
errors=self._errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
|
||||||
"""Import a config entry."""
|
|
||||||
|
|
||||||
user_input = {
|
|
||||||
CONF_HOST: DEFAULT_HOST,
|
|
||||||
CONF_NAME: DEFAULT_NAME,
|
|
||||||
"extended_data": False,
|
|
||||||
**import_data,
|
|
||||||
}
|
|
||||||
|
|
||||||
user_input[CONF_HOST] = self._parse_url(user_input[CONF_HOST])
|
|
||||||
|
|
||||||
if self._host_in_configuration_exists(user_input[CONF_HOST]):
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
|
|
||||||
return await self.async_step_user(user_input)
|
|
||||||
|
|
||||||
async def async_step_reconfigure(
|
async def async_step_reconfigure(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
|
@ -7,7 +7,7 @@ from solarlog_cli.solarlog_exceptions import SolarLogConnectionError, SolarLogEr
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.solarlog import config_flow
|
from homeassistant.components.solarlog import config_flow
|
||||||
from homeassistant.components.solarlog.const import DEFAULT_HOST, DOMAIN
|
from homeassistant.components.solarlog.const import DOMAIN
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
@ -123,35 +123,6 @@ async def test_form_exceptions(
|
|||||||
assert result["data"]["extended_data"] is False
|
assert result["data"]["extended_data"] is False
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass: HomeAssistant, test_connect) -> None:
|
|
||||||
"""Test import step."""
|
|
||||||
flow = init_config_flow(hass)
|
|
||||||
|
|
||||||
# import with only host
|
|
||||||
result = await flow.async_step_import({CONF_HOST: HOST})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == "solarlog"
|
|
||||||
assert result["data"][CONF_HOST] == HOST
|
|
||||||
|
|
||||||
# import with only name
|
|
||||||
result = await flow.async_step_import({CONF_NAME: NAME})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == "solarlog_test_1_2_3"
|
|
||||||
assert result["data"][CONF_HOST] == DEFAULT_HOST
|
|
||||||
|
|
||||||
# import with host and name
|
|
||||||
result = await flow.async_step_import({CONF_HOST: HOST, CONF_NAME: NAME})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == "solarlog_test_1_2_3"
|
|
||||||
assert result["data"][CONF_HOST] == HOST
|
|
||||||
|
|
||||||
|
|
||||||
async def test_abort_if_already_setup(hass: HomeAssistant, test_connect) -> None:
|
async def test_abort_if_already_setup(hass: HomeAssistant, test_connect) -> None:
|
||||||
"""Test we abort if the device is already setup."""
|
"""Test we abort if the device is already setup."""
|
||||||
flow = init_config_flow(hass)
|
flow = init_config_flow(hass)
|
||||||
@ -160,11 +131,11 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_connect) -> None
|
|||||||
).add_to_hass(hass)
|
).add_to_hass(hass)
|
||||||
|
|
||||||
# Should fail, same HOST different NAME (default)
|
# Should fail, same HOST different NAME (default)
|
||||||
result = await flow.async_step_import(
|
result = await flow.async_step_user(
|
||||||
{CONF_HOST: HOST, CONF_NAME: "solarlog_test_7_8_9", "extended_data": False}
|
{CONF_HOST: HOST, CONF_NAME: "solarlog_test_7_8_9", "extended_data": False}
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.ABORT
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["reason"] == "already_configured"
|
assert result["errors"] == {CONF_HOST: "already_configured"}
|
||||||
|
|
||||||
# Should fail, same HOST and NAME
|
# Should fail, same HOST and NAME
|
||||||
result = await flow.async_step_user({CONF_HOST: HOST, CONF_NAME: NAME})
|
result = await flow.async_step_user({CONF_HOST: HOST, CONF_NAME: NAME})
|
||||||
@ -172,7 +143,7 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_connect) -> None
|
|||||||
assert result["errors"] == {CONF_HOST: "already_configured"}
|
assert result["errors"] == {CONF_HOST: "already_configured"}
|
||||||
|
|
||||||
# SHOULD pass, diff HOST (without http://), different NAME
|
# SHOULD pass, diff HOST (without http://), different NAME
|
||||||
result = await flow.async_step_import(
|
result = await flow.async_step_user(
|
||||||
{CONF_HOST: "2.2.2.2", CONF_NAME: "solarlog_test_7_8_9", "extended_data": False}
|
{CONF_HOST: "2.2.2.2", CONF_NAME: "solarlog_test_7_8_9", "extended_data": False}
|
||||||
)
|
)
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||||
@ -180,7 +151,7 @@ async def test_abort_if_already_setup(hass: HomeAssistant, test_connect) -> None
|
|||||||
assert result["data"][CONF_HOST] == "http://2.2.2.2"
|
assert result["data"][CONF_HOST] == "http://2.2.2.2"
|
||||||
|
|
||||||
# SHOULD pass, diff HOST, same NAME
|
# SHOULD pass, diff HOST, same NAME
|
||||||
result = await flow.async_step_import(
|
result = await flow.async_step_user(
|
||||||
{CONF_HOST: "http://2.2.2.2", CONF_NAME: NAME, "extended_data": False}
|
{CONF_HOST: "http://2.2.2.2", CONF_NAME: NAME, "extended_data": False}
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user