2021-09-18 19:25:05 +00:00
|
|
|
"""Test the switchbot config flow."""
|
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2022-07-24 21:38:07 +00:00
|
|
|
from homeassistant.components.switchbot.const import CONF_RETRY_COUNT
|
2022-07-24 16:38:45 +00:00
|
|
|
from homeassistant.config_entries import SOURCE_BLUETOOTH, SOURCE_USER
|
|
|
|
from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_PASSWORD, CONF_SENSOR_TYPE
|
2022-07-07 19:28:18 +00:00
|
|
|
from homeassistant.data_entry_flow import FlowResultType
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-22 16:03:02 +00:00
|
|
|
from . import (
|
2022-07-24 16:38:45 +00:00
|
|
|
NOT_SWITCHBOT_INFO,
|
2022-07-22 16:03:02 +00:00
|
|
|
USER_INPUT,
|
2022-07-24 16:38:45 +00:00
|
|
|
WOCURTAIN_SERVICE_INFO,
|
2022-08-10 19:02:08 +00:00
|
|
|
WOHAND_ENCRYPTED_SERVICE_INFO,
|
|
|
|
WOHAND_SERVICE_ALT_ADDRESS_INFO,
|
2022-07-24 16:38:45 +00:00
|
|
|
WOHAND_SERVICE_INFO,
|
2022-08-22 18:02:26 +00:00
|
|
|
WOHAND_SERVICE_INFO_NOT_CONNECTABLE,
|
2022-07-24 16:38:45 +00:00
|
|
|
WOSENSORTH_SERVICE_INFO,
|
2022-07-22 16:03:02 +00:00
|
|
|
init_integration,
|
|
|
|
patch_async_setup_entry,
|
|
|
|
)
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
2021-09-18 19:25:05 +00:00
|
|
|
DOMAIN = "switchbot"
|
|
|
|
|
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_bluetooth_discovery(hass):
|
|
|
|
"""Test discovery via bluetooth with a valid device."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_BLUETOOTH},
|
|
|
|
data=WOHAND_SERVICE_INFO,
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.FORM
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["step_id"] == "confirm"
|
2022-07-24 16:38:45 +00:00
|
|
|
|
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
2022-08-10 19:02:08 +00:00
|
|
|
{},
|
2022-07-24 16:38:45 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["title"] == "Bot EEFF"
|
2022-07-24 16:38:45 +00:00
|
|
|
assert result["data"] == {
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
|
|
|
2022-08-10 19:02:08 +00:00
|
|
|
async def test_bluetooth_discovery_requires_password(hass):
|
|
|
|
"""Test discovery via bluetooth with a valid device that needs a password."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_BLUETOOTH},
|
|
|
|
data=WOHAND_ENCRYPTED_SERVICE_INFO,
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.FORM
|
|
|
|
assert result["step_id"] == "password"
|
|
|
|
|
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
{CONF_PASSWORD: "abc123"},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
|
|
assert result["title"] == "Bot 923B"
|
|
|
|
assert result["data"] == {
|
|
|
|
CONF_ADDRESS: "798A8547-2A3D-C609-55FF-73FA824B923B",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
CONF_PASSWORD: "abc123",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_bluetooth_discovery_already_setup(hass):
|
|
|
|
"""Test discovery via bluetooth with a valid device when already setup."""
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data={
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
CONF_NAME: "test-name",
|
|
|
|
CONF_PASSWORD: "test-password",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
},
|
|
|
|
unique_id="aabbccddeeff",
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
2021-09-18 19:25:05 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
2022-07-24 16:38:45 +00:00
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_BLUETOOTH},
|
|
|
|
data=WOHAND_SERVICE_INFO,
|
2021-09-18 19:25:05 +00:00
|
|
|
)
|
2022-07-24 16:38:45 +00:00
|
|
|
assert result["type"] == FlowResultType.ABORT
|
|
|
|
assert result["reason"] == "already_configured"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_async_step_bluetooth_not_switchbot(hass):
|
|
|
|
"""Test discovery via bluetooth not switchbot."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_BLUETOOTH},
|
|
|
|
data=NOT_SWITCHBOT_INFO,
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.ABORT
|
|
|
|
assert result["reason"] == "not_supported"
|
|
|
|
|
|
|
|
|
2022-08-22 18:02:26 +00:00
|
|
|
async def test_async_step_bluetooth_not_connectable(hass):
|
|
|
|
"""Test discovery via bluetooth and its not connectable switchbot."""
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_BLUETOOTH},
|
|
|
|
data=WOHAND_SERVICE_INFO_NOT_CONNECTABLE,
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.ABORT
|
|
|
|
assert result["reason"] == "not_supported"
|
|
|
|
|
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_user_setup_wohand(hass):
|
|
|
|
"""Test the user initiated form with password and valid mac."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[WOHAND_SERVICE_INFO],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.FORM
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["step_id"] == "confirm"
|
|
|
|
assert result["errors"] is None
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-03-31 18:12:02 +00:00
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
2021-09-18 19:25:05 +00:00
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
2022-08-10 19:02:08 +00:00
|
|
|
{},
|
2021-09-18 19:25:05 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["title"] == "Bot EEFF"
|
2021-09-18 19:25:05 +00:00
|
|
|
assert result["data"] == {
|
2022-07-24 16:38:45 +00:00
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
2021-09-18 19:25:05 +00:00
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
2021-09-21 17:35:47 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_user_setup_wohand_already_configured(hass):
|
|
|
|
"""Test the user initiated form with password and valid mac."""
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data={
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
CONF_NAME: "test-name",
|
|
|
|
CONF_PASSWORD: "test-password",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
},
|
|
|
|
unique_id="aabbccddeeff",
|
2021-09-21 17:35:47 +00:00
|
|
|
)
|
2022-07-24 16:38:45 +00:00
|
|
|
entry.add_to_hass(hass)
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[WOHAND_SERVICE_INFO],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.ABORT
|
|
|
|
assert result["reason"] == "no_unconfigured_devices"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_user_setup_wocurtain(hass):
|
|
|
|
"""Test the user initiated form with password and valid mac."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[WOCURTAIN_SERVICE_INFO],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.FORM
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["step_id"] == "confirm"
|
|
|
|
assert result["errors"] is None
|
|
|
|
|
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
{},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
|
|
|
assert result["title"] == "Curtain EEFF"
|
|
|
|
assert result["data"] == {
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
CONF_SENSOR_TYPE: "curtain",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
|
|
async def test_user_setup_wocurtain_or_bot(hass):
|
|
|
|
"""Test the user initiated form with valid address."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
2022-08-22 18:02:26 +00:00
|
|
|
return_value=[
|
|
|
|
NOT_SWITCHBOT_INFO,
|
|
|
|
WOCURTAIN_SERVICE_INFO,
|
|
|
|
WOHAND_SERVICE_ALT_ADDRESS_INFO,
|
|
|
|
WOHAND_SERVICE_INFO_NOT_CONNECTABLE,
|
|
|
|
],
|
2022-08-10 19:02:08 +00:00
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.FORM
|
2021-09-21 17:35:47 +00:00
|
|
|
assert result["step_id"] == "user"
|
|
|
|
assert result["errors"] == {}
|
|
|
|
|
2022-03-31 18:12:02 +00:00
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
2021-09-21 17:35:47 +00:00
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
2022-08-10 19:02:08 +00:00
|
|
|
USER_INPUT,
|
2021-09-21 17:35:47 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["title"] == "Curtain EEFF"
|
2021-09-21 17:35:47 +00:00
|
|
|
assert result["data"] == {
|
2022-07-24 16:38:45 +00:00
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
2021-09-21 17:35:47 +00:00
|
|
|
CONF_SENSOR_TYPE: "curtain",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
2022-07-22 16:03:02 +00:00
|
|
|
|
|
|
|
|
2022-08-10 19:02:08 +00:00
|
|
|
async def test_user_setup_wocurtain_or_bot_with_password(hass):
|
|
|
|
"""Test the user initiated form and valid address and a bot with a password."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
2022-08-22 18:02:26 +00:00
|
|
|
return_value=[
|
|
|
|
WOCURTAIN_SERVICE_INFO,
|
|
|
|
WOHAND_ENCRYPTED_SERVICE_INFO,
|
|
|
|
WOHAND_SERVICE_INFO_NOT_CONNECTABLE,
|
|
|
|
],
|
2022-08-10 19:02:08 +00:00
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.FORM
|
|
|
|
assert result["step_id"] == "user"
|
|
|
|
assert result["errors"] == {}
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
{CONF_ADDRESS: "798A8547-2A3D-C609-55FF-73FA824B923B"},
|
|
|
|
)
|
|
|
|
assert result2["type"] == FlowResultType.FORM
|
|
|
|
assert result2["step_id"] == "password"
|
|
|
|
assert result2["errors"] is None
|
|
|
|
|
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result3 = await hass.config_entries.flow.async_configure(
|
|
|
|
result2["flow_id"],
|
|
|
|
{CONF_PASSWORD: "abc123"},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert result3["type"] == FlowResultType.CREATE_ENTRY
|
|
|
|
assert result3["title"] == "Bot 923B"
|
|
|
|
assert result3["data"] == {
|
|
|
|
CONF_ADDRESS: "798A8547-2A3D-C609-55FF-73FA824B923B",
|
|
|
|
CONF_PASSWORD: "abc123",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
|
|
async def test_user_setup_single_bot_with_password(hass):
|
|
|
|
"""Test the user initiated form for a bot with a password."""
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[WOHAND_ENCRYPTED_SERVICE_INFO],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.FORM
|
|
|
|
assert result["step_id"] == "password"
|
|
|
|
assert result["errors"] is None
|
|
|
|
|
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
{CONF_PASSWORD: "abc123"},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
|
|
assert result2["title"] == "Bot 923B"
|
|
|
|
assert result2["data"] == {
|
|
|
|
CONF_ADDRESS: "798A8547-2A3D-C609-55FF-73FA824B923B",
|
|
|
|
CONF_PASSWORD: "abc123",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
|
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_user_setup_wosensor(hass):
|
|
|
|
"""Test the user initiated form with password and valid mac."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[WOSENSORTH_SERVICE_INFO],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
2022-07-22 16:03:02 +00:00
|
|
|
assert result["type"] == FlowResultType.FORM
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["step_id"] == "confirm"
|
|
|
|
assert result["errors"] is None
|
2022-07-22 16:03:02 +00:00
|
|
|
|
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
2022-08-10 19:02:08 +00:00
|
|
|
{},
|
2022-07-22 16:03:02 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["title"] == "Meter EEFF"
|
2022-07-22 16:03:02 +00:00
|
|
|
assert result["data"] == {
|
2022-07-24 16:38:45 +00:00
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
2022-07-22 16:03:02 +00:00
|
|
|
CONF_SENSOR_TYPE: "hygrometer",
|
|
|
|
}
|
|
|
|
|
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
2021-09-21 17:35:47 +00:00
|
|
|
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_user_no_devices(hass):
|
|
|
|
"""Test the user initiated form with password and valid mac."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
)
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.ABORT
|
2021-09-27 20:12:40 +00:00
|
|
|
assert result["reason"] == "no_unconfigured_devices"
|
2021-09-18 19:25:05 +00:00
|
|
|
|
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
async def test_async_step_user_takes_precedence_over_discovery(hass):
|
|
|
|
"""Test manual setup takes precedence over discovery."""
|
2021-09-18 19:25:05 +00:00
|
|
|
result = await hass.config_entries.flow.async_init(
|
2022-07-24 16:38:45 +00:00
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_BLUETOOTH},
|
|
|
|
data=WOCURTAIN_SERVICE_INFO,
|
2021-09-18 19:25:05 +00:00
|
|
|
)
|
2022-07-24 16:38:45 +00:00
|
|
|
assert result["type"] == FlowResultType.FORM
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result["step_id"] == "confirm"
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
with patch(
|
|
|
|
"homeassistant.components.switchbot.config_flow.async_discovered_service_info",
|
|
|
|
return_value=[WOCURTAIN_SERVICE_INFO],
|
|
|
|
):
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN,
|
|
|
|
context={"source": SOURCE_USER},
|
|
|
|
)
|
|
|
|
assert result["type"] == FlowResultType.FORM
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
result["flow_id"],
|
2022-08-10 19:02:08 +00:00
|
|
|
user_input={},
|
2022-07-24 16:38:45 +00:00
|
|
|
)
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
2022-08-10 19:02:08 +00:00
|
|
|
assert result2["title"] == "Curtain EEFF"
|
2022-07-24 16:38:45 +00:00
|
|
|
assert result2["data"] == {
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
CONF_SENSOR_TYPE: "curtain",
|
|
|
|
}
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
|
|
|
# Verify the original one was aborted
|
|
|
|
assert not hass.config_entries.flow.async_progress(DOMAIN)
|
2021-09-18 19:25:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_options_flow(hass):
|
|
|
|
"""Test updating options."""
|
2022-07-24 16:38:45 +00:00
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
data={
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
CONF_NAME: "test-name",
|
|
|
|
CONF_PASSWORD: "test-password",
|
|
|
|
CONF_SENSOR_TYPE: "bot",
|
|
|
|
},
|
|
|
|
options={
|
|
|
|
CONF_RETRY_COUNT: 10,
|
|
|
|
},
|
|
|
|
unique_id="aabbccddeeff",
|
|
|
|
)
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
|
2022-03-31 18:12:02 +00:00
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
2021-09-18 19:25:05 +00:00
|
|
|
entry = await init_integration(hass)
|
|
|
|
|
2021-09-21 17:35:47 +00:00
|
|
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.FORM
|
2021-09-21 17:35:47 +00:00
|
|
|
assert result["step_id"] == "init"
|
|
|
|
assert result["errors"] is None
|
2021-09-18 19:25:05 +00:00
|
|
|
|
|
|
|
result = await hass.config_entries.options.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
user_input={
|
2021-09-21 17:35:47 +00:00
|
|
|
CONF_RETRY_COUNT: 3,
|
2021-09-18 19:25:05 +00:00
|
|
|
},
|
|
|
|
)
|
2021-09-21 17:35:47 +00:00
|
|
|
await hass.async_block_till_done()
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
2021-09-21 17:35:47 +00:00
|
|
|
assert result["data"][CONF_RETRY_COUNT] == 3
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-24 16:38:45 +00:00
|
|
|
assert len(mock_setup_entry.mock_calls) == 2
|
2021-09-18 19:25:05 +00:00
|
|
|
|
|
|
|
# Test changing of entry options.
|
|
|
|
|
2022-03-31 18:12:02 +00:00
|
|
|
with patch_async_setup_entry() as mock_setup_entry:
|
2021-09-21 17:35:47 +00:00
|
|
|
entry = await init_integration(hass)
|
|
|
|
|
|
|
|
result = await hass.config_entries.options.async_init(entry.entry_id)
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.FORM
|
2021-09-21 17:35:47 +00:00
|
|
|
assert result["step_id"] == "init"
|
|
|
|
assert result["errors"] is None
|
|
|
|
|
2021-09-18 19:25:05 +00:00
|
|
|
result = await hass.config_entries.options.async_configure(
|
|
|
|
result["flow_id"],
|
|
|
|
user_input={
|
2021-09-21 17:35:47 +00:00
|
|
|
CONF_RETRY_COUNT: 6,
|
2021-09-18 19:25:05 +00:00
|
|
|
},
|
|
|
|
)
|
2021-09-21 17:35:47 +00:00
|
|
|
await hass.async_block_till_done()
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2022-07-07 19:28:18 +00:00
|
|
|
assert result["type"] == FlowResultType.CREATE_ENTRY
|
2021-09-21 17:35:47 +00:00
|
|
|
assert result["data"][CONF_RETRY_COUNT] == 6
|
2021-09-18 19:25:05 +00:00
|
|
|
|
2021-09-21 17:35:47 +00:00
|
|
|
assert len(mock_setup_entry.mock_calls) == 1
|
2022-07-24 16:38:45 +00:00
|
|
|
|
|
|
|
assert entry.options[CONF_RETRY_COUNT] == 6
|