|
|
|
@@ -27,6 +27,15 @@ from . import USER_INPUT, async_init_integration, get_bluetooth_service_info
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def mock_setup_entry() -> Generator[AsyncMock]:
|
|
|
|
|
"""Override async_setup_entry."""
|
|
|
|
|
with patch(
|
|
|
|
|
"homeassistant.components.lamarzocco.async_setup_entry", return_value=True
|
|
|
|
|
) as mock_setup_entry:
|
|
|
|
|
yield mock_setup_entry
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def __do_successful_user_step(
|
|
|
|
|
hass: HomeAssistant, result: ConfigFlowResult, mock_cloud_client: MagicMock
|
|
|
|
|
) -> ConfigFlowResult:
|
|
|
|
@@ -47,25 +56,24 @@ async def __do_sucessful_machine_selection_step(
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Successfully configure the machine selection step."""
|
|
|
|
|
|
|
|
|
|
result3 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result2["flow_id"],
|
|
|
|
|
{CONF_MACHINE: "GS012345"},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result3["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
|
|
|
|
|
assert result3["title"] == "GS012345"
|
|
|
|
|
assert result3["data"] == {
|
|
|
|
|
assert result["title"] == "GS012345"
|
|
|
|
|
assert result["data"] == {
|
|
|
|
|
**USER_INPUT,
|
|
|
|
|
CONF_TOKEN: None,
|
|
|
|
|
}
|
|
|
|
|
assert result3["result"].unique_id == "GS012345"
|
|
|
|
|
assert result["result"].unique_id == "GS012345"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_form(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test we get the form."""
|
|
|
|
|
result = await hass.config_entries.flow.async_init(
|
|
|
|
@@ -75,13 +83,12 @@ async def test_form(
|
|
|
|
|
assert result["errors"] == {}
|
|
|
|
|
assert result["step_id"] == "user"
|
|
|
|
|
|
|
|
|
|
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
await __do_sucessful_machine_selection_step(hass, result2)
|
|
|
|
|
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
await __do_sucessful_machine_selection_step(hass, result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_form_abort_already_configured(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test we abort if already configured."""
|
|
|
|
@@ -93,25 +100,25 @@ async def test_form_abort_already_configured(
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["errors"] == {}
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
assert result2["type"] is FlowResultType.FORM
|
|
|
|
|
assert result2["step_id"] == "machine_selection"
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "machine_selection"
|
|
|
|
|
|
|
|
|
|
result3 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result2["flow_id"],
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
{
|
|
|
|
|
CONF_MACHINE: "GS012345",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
assert result3["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result3["reason"] == "already_configured"
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["reason"] == "already_configured"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
@@ -124,7 +131,6 @@ async def test_form_abort_already_configured(
|
|
|
|
|
async def test_form_invalid_auth(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
side_effect: Exception,
|
|
|
|
|
error: str,
|
|
|
|
|
) -> None:
|
|
|
|
@@ -135,25 +141,24 @@ async def test_form_invalid_auth(
|
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result2["type"] is FlowResultType.FORM
|
|
|
|
|
assert result2["errors"] == {"base": error}
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["errors"] == {"base": error}
|
|
|
|
|
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
# test recovery from failure
|
|
|
|
|
mock_cloud_client.list_things.side_effect = None
|
|
|
|
|
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
await __do_sucessful_machine_selection_step(hass, result2)
|
|
|
|
|
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
await __do_sucessful_machine_selection_step(hass, result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_form_no_machines(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test we don't have any devices."""
|
|
|
|
|
|
|
|
|
@@ -164,20 +169,20 @@ async def test_form_no_machines(
|
|
|
|
|
DOMAIN, context={"source": SOURCE_USER}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result2["type"] is FlowResultType.FORM
|
|
|
|
|
assert result2["errors"] == {"base": "no_machines"}
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["errors"] == {"base": "no_machines"}
|
|
|
|
|
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
# test recovery from failure
|
|
|
|
|
mock_cloud_client.list_things.return_value = original_return
|
|
|
|
|
|
|
|
|
|
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
await __do_sucessful_machine_selection_step(hass, result2)
|
|
|
|
|
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
await __do_sucessful_machine_selection_step(hass, result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_reauth_flow(
|
|
|
|
@@ -194,14 +199,14 @@ async def test_reauth_flow(
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "reauth_confirm"
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
{CONF_PASSWORD: "new_password"},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result2["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
assert result2["reason"] == "reauth_successful"
|
|
|
|
|
assert result["reason"] == "reauth_successful"
|
|
|
|
|
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
|
|
|
|
assert mock_config_entry.data[CONF_PASSWORD] == "new_password"
|
|
|
|
|
|
|
|
|
@@ -210,7 +215,6 @@ async def test_reconfigure_flow(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Testing reconfgure flow."""
|
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
@@ -220,7 +224,7 @@ async def test_reconfigure_flow(
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "reconfigure"
|
|
|
|
|
|
|
|
|
|
result2 = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
result = await __do_successful_user_step(hass, result, mock_cloud_client)
|
|
|
|
|
service_info = get_bluetooth_service_info(ModelName.GS3_MP, "GS012345")
|
|
|
|
|
|
|
|
|
|
with (
|
|
|
|
@@ -229,24 +233,24 @@ async def test_reconfigure_flow(
|
|
|
|
|
return_value=[service_info],
|
|
|
|
|
),
|
|
|
|
|
):
|
|
|
|
|
result3 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result2["flow_id"],
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
{
|
|
|
|
|
CONF_MACHINE: "GS012345",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
assert result3["type"] is FlowResultType.FORM
|
|
|
|
|
assert result3["step_id"] == "bluetooth_selection"
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "bluetooth_selection"
|
|
|
|
|
|
|
|
|
|
result4 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result3["flow_id"],
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
{CONF_MAC: service_info.address},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result4["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result4["reason"] == "reconfigure_successful"
|
|
|
|
|
assert result["type"] is FlowResultType.ABORT
|
|
|
|
|
assert result["reason"] == "reconfigure_successful"
|
|
|
|
|
|
|
|
|
|
assert mock_config_entry.title == "My LaMarzocco"
|
|
|
|
|
assert mock_config_entry.data == {
|
|
|
|
@@ -259,7 +263,6 @@ async def test_bluetooth_discovery(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test bluetooth discovery."""
|
|
|
|
|
service_info = get_bluetooth_service_info(
|
|
|
|
@@ -274,14 +277,14 @@ async def test_bluetooth_discovery(
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "user"
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
|
|
|
|
|
assert result2["title"] == "GS012345"
|
|
|
|
|
assert result2["data"] == {
|
|
|
|
|
assert result["title"] == "GS012345"
|
|
|
|
|
assert result["data"] == {
|
|
|
|
|
**USER_INPUT,
|
|
|
|
|
CONF_MAC: "aa:bb:cc:dd:ee:ff",
|
|
|
|
|
CONF_TOKEN: "dummyToken",
|
|
|
|
@@ -291,8 +294,6 @@ async def test_bluetooth_discovery(
|
|
|
|
|
async def test_bluetooth_discovery_already_configured(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test bluetooth discovery."""
|
|
|
|
@@ -312,7 +313,6 @@ async def test_bluetooth_discovery_errors(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test bluetooth discovery errors."""
|
|
|
|
|
service_info = get_bluetooth_service_info(
|
|
|
|
@@ -330,24 +330,24 @@ async def test_bluetooth_discovery_errors(
|
|
|
|
|
original_return = deepcopy(mock_cloud_client.list_things.return_value)
|
|
|
|
|
mock_cloud_client.list_things.return_value[0].serial_number = "GS98765"
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
assert result2["type"] is FlowResultType.FORM
|
|
|
|
|
assert result2["errors"] == {"base": "machine_not_found"}
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["errors"] == {"base": "machine_not_found"}
|
|
|
|
|
assert len(mock_cloud_client.list_things.mock_calls) == 1
|
|
|
|
|
|
|
|
|
|
mock_cloud_client.list_things.return_value = original_return
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
|
|
|
|
|
assert result2["title"] == "GS012345"
|
|
|
|
|
assert result2["data"] == {
|
|
|
|
|
assert result["title"] == "GS012345"
|
|
|
|
|
assert result["data"] == {
|
|
|
|
|
**USER_INPUT,
|
|
|
|
|
CONF_MAC: "aa:bb:cc:dd:ee:ff",
|
|
|
|
|
CONF_TOKEN: None,
|
|
|
|
@@ -357,8 +357,6 @@ async def test_bluetooth_discovery_errors(
|
|
|
|
|
async def test_dhcp_discovery(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test dhcp discovery."""
|
|
|
|
|
|
|
|
|
@@ -375,12 +373,12 @@ async def test_dhcp_discovery(
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "user"
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result = await hass.config_entries.flow.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
USER_INPUT,
|
|
|
|
|
)
|
|
|
|
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result2["data"] == {
|
|
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result["data"] == {
|
|
|
|
|
**USER_INPUT,
|
|
|
|
|
CONF_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
|
|
|
|
CONF_TOKEN: None,
|
|
|
|
@@ -389,8 +387,6 @@ async def test_dhcp_discovery(
|
|
|
|
|
|
|
|
|
|
async def test_dhcp_discovery_abort_on_hostname_changed(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test dhcp discovery aborts when hostname was changed manually."""
|
|
|
|
@@ -411,7 +407,6 @@ async def test_dhcp_discovery_abort_on_hostname_changed(
|
|
|
|
|
async def test_dhcp_already_configured_and_update(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_cloud_client: MagicMock,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test discovered IP address change."""
|
|
|
|
@@ -436,9 +431,7 @@ async def test_dhcp_already_configured_and_update(
|
|
|
|
|
|
|
|
|
|
async def test_options_flow(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_lamarzocco: MagicMock,
|
|
|
|
|
mock_config_entry: MockConfigEntry,
|
|
|
|
|
mock_setup_entry: Generator[AsyncMock],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test options flow."""
|
|
|
|
|
await async_init_integration(hass, mock_config_entry)
|
|
|
|
@@ -449,7 +442,7 @@ async def test_options_flow(
|
|
|
|
|
assert result["type"] is FlowResultType.FORM
|
|
|
|
|
assert result["step_id"] == "init"
|
|
|
|
|
|
|
|
|
|
result2 = await hass.config_entries.options.async_configure(
|
|
|
|
|
result = await hass.config_entries.options.async_configure(
|
|
|
|
|
result["flow_id"],
|
|
|
|
|
user_input={
|
|
|
|
|
CONF_USE_BLUETOOTH: False,
|
|
|
|
@@ -457,7 +450,7 @@ async def test_options_flow(
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
assert result2["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result2["data"] == {
|
|
|
|
|
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
|
|
|
assert result["data"] == {
|
|
|
|
|
CONF_USE_BLUETOOTH: False,
|
|
|
|
|
}
|
|
|
|
|