Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable config flow progress in peco config flow #105222

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions homeassistant/components/peco/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):

VERSION = 1

meter_verification: bool = False
meter_data: dict[str, str] = {}
meter_error: dict[str, str] = {}

Expand All @@ -53,17 +52,10 @@ async def _verify_meter(self, phone_number: str) -> None:
except HttpError:
self.meter_error = {"phone_number": "http_error", "type": "error"}

self.hass.async_create_task(
self.hass.config_entries.flow.async_configure(flow_id=self.flow_id)
)

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
if self.meter_verification is True:
return self.async_show_progress_done(next_step_id="finish_smart_meter")

if user_input is None:
return self.async_show_form(
step_id="user",
Expand All @@ -86,28 +78,22 @@ async def async_step_user(
await self.async_set_unique_id(f"{county}-{phone_number}")
self._abort_if_unique_id_configured()

self.meter_verification = True

if self.meter_error is not None:
# Clear any previous errors, since the user may have corrected them
self.meter_error = {}

self.hass.async_create_task(self._verify_meter(phone_number))
await self._verify_meter(phone_number)

self.meter_data = user_input

return self.async_show_progress(
step_id="user",
progress_action="verifying_meter",
)
return await self.async_step_finish_smart_meter()

async def async_step_finish_smart_meter(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the finish smart meter step."""
if "phone_number" in self.meter_error:
if self.meter_error["type"] == "error":
self.meter_verification = False
return self.async_show_form(
step_id="user",
data_schema=STEP_USER_DATA_SCHEMA,
Expand Down
30 changes: 0 additions & 30 deletions tests/components/peco/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ async def test_meter_value_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

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

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

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"phone_number": "invalid_phone_number"}
Expand All @@ -107,12 +101,6 @@ async def test_incompatible_meter_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

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

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

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

Expand All @@ -135,12 +123,6 @@ async def test_unresponsive_meter_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

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

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

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"phone_number": "unresponsive_meter"}
Expand All @@ -164,12 +146,6 @@ async def test_meter_http_error(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

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

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

assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user"
assert result["errors"] == {"phone_number": "http_error"}
Expand All @@ -193,12 +169,6 @@ async def test_smart_meter(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()

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

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

assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "Philadelphia - 1234567890"
assert result["data"]["phone_number"] == "1234567890"
Expand Down
Loading