mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Tesla wall connector config flow refactor continued (#60774)
This commit is contained in:
parent
c7eaba45f4
commit
a6ec646f98
@ -16,15 +16,5 @@
|
|||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"options": {
|
|
||||||
"step": {
|
|
||||||
"init": {
|
|
||||||
"title": "Configure options for Tesla Wall Connector",
|
|
||||||
"data": {
|
|
||||||
"scan_interval": "Update frequency"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,6 +29,16 @@ def mock_wall_connector_version():
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
async def mock_wall_connector_setup():
|
||||||
|
"""Mock component setup."""
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.tesla_wall_connector.async_setup_entry",
|
||||||
|
return_value=True,
|
||||||
|
):
|
||||||
|
yield
|
||||||
|
|
||||||
|
|
||||||
def get_default_version_data():
|
def get_default_version_data():
|
||||||
"""Return default version data object for a wall connector."""
|
"""Return default version data object for a wall connector."""
|
||||||
return Version(
|
return Version(
|
||||||
|
@ -3,7 +3,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
from tesla_wall_connector.exceptions import WallConnectorConnectionError
|
from tesla_wall_connector.exceptions import WallConnectorConnectionError
|
||||||
|
|
||||||
from homeassistant import config_entries, setup
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
||||||
from homeassistant.components.tesla_wall_connector.const import DOMAIN
|
from homeassistant.components.tesla_wall_connector.const import DOMAIN
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
@ -15,7 +15,6 @@ from tests.common import MockConfigEntry
|
|||||||
|
|
||||||
async def test_form(mock_wall_connector_version, hass: HomeAssistant) -> None:
|
async def test_form(mock_wall_connector_version, hass: HomeAssistant) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
@ -78,7 +77,9 @@ async def test_form_other_error(
|
|||||||
assert result2["errors"] == {"base": "unknown"}
|
assert result2["errors"] == {"base": "unknown"}
|
||||||
|
|
||||||
|
|
||||||
async def test_form_already_configured(mock_wall_connector_version, hass):
|
async def test_form_already_configured(
|
||||||
|
mock_wall_connector_setup, mock_wall_connector_version, hass
|
||||||
|
):
|
||||||
"""Test we get already configured."""
|
"""Test we get already configured."""
|
||||||
|
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -90,24 +91,22 @@ async def test_form_already_configured(mock_wall_connector_version, hass):
|
|||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
"homeassistant.components.tesla_wall_connector.async_setup_entry",
|
result["flow_id"],
|
||||||
return_value=True,
|
{CONF_HOST: "1.1.1.1"},
|
||||||
):
|
)
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
await hass.async_block_till_done()
|
||||||
result["flow_id"],
|
|
||||||
{CONF_HOST: "1.1.1.1"},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] == "abort"
|
assert result2["type"] == "abort"
|
||||||
assert result2["reason"] == "already_configured"
|
assert result2["reason"] == "already_configured"
|
||||||
|
|
||||||
# Test config entry got updated with latest IP
|
# Test config entry got updated with latest IP
|
||||||
assert entry.data[CONF_HOST] == "1.1.1.1"
|
assert entry.data[CONF_HOST] == "1.1.1.1"
|
||||||
|
|
||||||
|
|
||||||
async def test_dhcp_can_finish(mock_wall_connector_version, hass):
|
async def test_dhcp_can_finish(
|
||||||
|
mock_wall_connector_setup, mock_wall_connector_version, hass
|
||||||
|
):
|
||||||
"""Test DHCP discovery flow can finish right away."""
|
"""Test DHCP discovery flow can finish right away."""
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user