mirror of https://github.com/home-assistant/core
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""Repairs platform for the demo integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import data_entry_flow
|
|
from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
class DemoFixFlow(RepairsFlow):
|
|
"""Handler for an issue fixing flow."""
|
|
|
|
async def async_step_init(
|
|
self, user_input: dict[str, str] | None = None
|
|
) -> data_entry_flow.FlowResult:
|
|
"""Handle the first step of a fix flow."""
|
|
|
|
return await self.async_step_confirm()
|
|
|
|
async def async_step_confirm(
|
|
self, user_input: dict[str, str] | None = None
|
|
) -> data_entry_flow.FlowResult:
|
|
"""Handle the confirm step of a fix flow."""
|
|
if user_input is not None:
|
|
return self.async_create_entry(data={})
|
|
|
|
return self.async_show_form(step_id="confirm", data_schema=vol.Schema({}))
|
|
|
|
|
|
class DemoColdTeaFixFlow(RepairsFlow):
|
|
"""Handler for cold tea."""
|
|
|
|
async def async_step_init(
|
|
self, user_input: dict[str, str] | None = None
|
|
) -> data_entry_flow.FlowResult:
|
|
"""Handle the first step of a fix flow."""
|
|
return self.async_abort(reason="not_tea_time")
|
|
|
|
|
|
async def async_create_fix_flow(
|
|
hass: HomeAssistant,
|
|
issue_id: str,
|
|
data: dict[str, str | int | float | None] | None,
|
|
) -> RepairsFlow:
|
|
"""Create flow."""
|
|
if issue_id == "bad_psu":
|
|
# The bad_psu issue doesn't have its own flow
|
|
return ConfirmRepairFlow()
|
|
|
|
if issue_id == "cold_tea":
|
|
# The cold_tea issue have it's own flow
|
|
return DemoColdTeaFixFlow()
|
|
|
|
# Other issues have a custom flow
|
|
return DemoFixFlow()
|