Skip to content

Commit

Permalink
Move to FlowResultType
Browse files Browse the repository at this point in the history
  • Loading branch information
IceBotYT committed Sep 26, 2022
1 parent 4f9bf60 commit ceed38c
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions tests/components/peco/test_config_flow.py
Expand Up @@ -8,28 +8,22 @@
from homeassistant import config_entries
from homeassistant.components.peco.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import (
RESULT_TYPE_ABORT,
RESULT_TYPE_CREATE_ENTRY,
RESULT_TYPE_FORM,
RESULT_TYPE_MENU,
RESULT_TYPE_SHOW_PROGRESS,
)
from homeassistant.data_entry_flow import FlowResultType


async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"next_step_id": "outage_counter"},
)
await hass.async_block_till_done()
assert result2["type"] == RESULT_TYPE_FORM
assert result2["type"] == FlowResultType.FORM
assert result2["step_id"] == "outage_counter"

with patch(
Expand All @@ -44,7 +38,7 @@ async def test_form(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert result3["type"] == RESULT_TYPE_CREATE_ENTRY
assert result3["type"] == FlowResultType.CREATE_ENTRY
assert result3["title"] == "Philadelphia Outage Count"
assert result3["data"] == {
"county": "PHILADELPHIA",
Expand All @@ -56,7 +50,7 @@ async def test_invalid_county(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

with raises(MultipleInvalid):
await hass.config_entries.flow.async_configure(
Expand All @@ -70,14 +64,14 @@ async def test_invalid_county(hass: HomeAssistant) -> None:
second_result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert second_result["type"] == RESULT_TYPE_MENU
assert second_result["type"] == FlowResultType.MENU

second_result2 = await hass.config_entries.flow.async_configure(
second_result["flow_id"],
{"next_step_id": "outage_counter"},
)
await hass.async_block_till_done()
assert second_result2["type"] == RESULT_TYPE_FORM
assert second_result2["type"] == FlowResultType.FORM
assert second_result2["step_id"] == "outage_counter"

with patch(
Expand All @@ -92,7 +86,7 @@ async def test_invalid_county(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert second_result3["type"] == RESULT_TYPE_CREATE_ENTRY
assert second_result3["type"] == FlowResultType.CREATE_ENTRY
assert second_result3["title"] == "Philadelphia Outage Count"
assert second_result3["data"] == {
"county": "PHILADELPHIA",
Expand All @@ -104,7 +98,7 @@ async def test_meter_value_error(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -113,7 +107,7 @@ async def test_meter_value_error(hass: HomeAssistant) -> None:
},
)
await hass.async_block_till_done()
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"

result = await hass.config_entries.flow.async_configure(
Expand All @@ -124,13 +118,13 @@ async def test_meter_value_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert result["type"] == RESULT_TYPE_SHOW_PROGRESS
assert result["type"] == FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "smart_meter"
assert result["progress_action"] == "verifying_meter"

result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"
assert result["errors"] == {"base": "invalid_phone_number"}

Expand All @@ -140,7 +134,7 @@ async def test_incompatible_meter_error(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -149,7 +143,7 @@ async def test_incompatible_meter_error(hass: HomeAssistant) -> None:
},
)
await hass.async_block_till_done()
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"

with patch("peco.PecoOutageApi.meter_check", side_effect=IncompatibleMeterError()):
Expand All @@ -161,13 +155,13 @@ async def test_incompatible_meter_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert result["type"] == RESULT_TYPE_SHOW_PROGRESS
assert result["type"] == FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "smart_meter"
assert result["progress_action"] == "verifying_meter"

result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] == RESULT_TYPE_ABORT
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "incompatible_meter"


Expand All @@ -176,7 +170,7 @@ async def test_unresponsive_meter_error(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -185,7 +179,7 @@ async def test_unresponsive_meter_error(hass: HomeAssistant) -> None:
},
)
await hass.async_block_till_done()
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"

with patch("peco.PecoOutageApi.meter_check", side_effect=UnresponsiveMeterError()):
Expand All @@ -197,13 +191,13 @@ async def test_unresponsive_meter_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert result["type"] == RESULT_TYPE_SHOW_PROGRESS
assert result["type"] == FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "smart_meter"
assert result["progress_action"] == "verifying_meter"

result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"
assert result["errors"] == {"base": "unresponsive_meter"}

Expand All @@ -213,7 +207,7 @@ async def test_meter_http_error(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -222,7 +216,7 @@ async def test_meter_http_error(hass: HomeAssistant) -> None:
},
)
await hass.async_block_till_done()
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"

with patch("peco.PecoOutageApi.meter_check", side_effect=HttpError):
Expand All @@ -234,13 +228,13 @@ async def test_meter_http_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert result["type"] == RESULT_TYPE_SHOW_PROGRESS
assert result["type"] == FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "smart_meter"
assert result["progress_action"] == "verifying_meter"

result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"
assert result["errors"] == {"base": "http_error"}

Expand All @@ -250,7 +244,7 @@ async def test_smart_meter(hass: HomeAssistant) -> None:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_MENU
assert result["type"] == FlowResultType.MENU

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -259,7 +253,7 @@ async def test_smart_meter(hass: HomeAssistant) -> None:
},
)
await hass.async_block_till_done()
assert result["type"] == RESULT_TYPE_FORM
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "smart_meter"

with patch("peco.PecoOutageApi.meter_check", return_value=True):
Expand All @@ -271,12 +265,12 @@ async def test_smart_meter(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

assert result["type"] == RESULT_TYPE_SHOW_PROGRESS
assert result["type"] == FlowResultType.SHOW_PROGRESS
assert result["step_id"] == "smart_meter"
assert result["progress_action"] == "verifying_meter"

result = await hass.config_entries.flow.async_configure(result["flow_id"])

assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "1234567890 Smart Meter"
assert result["data"]["phone_number"] == "1234567890"

0 comments on commit ceed38c

Please sign in to comment.