From d0390860fb5cc8e2f228db27594f21bb6e30dd33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 24 Nov 2022 14:54:41 +0100 Subject: [PATCH] Add repair abort flow to demo integration (#82614) --- homeassistant/components/demo/__init__.py | 9 ++++++ homeassistant/components/demo/repairs.py | 14 ++++++++++ homeassistant/components/demo/strings.json | 9 ++++++ .../components/demo/translations/en.json | 12 ++++++++ tests/components/demo/test_init.py | 28 +++++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/homeassistant/components/demo/__init__.py b/homeassistant/components/demo/__init__.py index 3bbafefa6ae..dd14d9f7b2a 100644 --- a/homeassistant/components/demo/__init__.py +++ b/homeassistant/components/demo/__init__.py @@ -230,6 +230,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: translation_key="bad_psu", ) + async_create_issue( + hass, + DOMAIN, + "cold_tea", + is_fixable=True, + severity=IssueSeverity.WARNING, + translation_key="cold_tea", + ) + return True diff --git a/homeassistant/components/demo/repairs.py b/homeassistant/components/demo/repairs.py index cddc937a71a..1ea00374457 100644 --- a/homeassistant/components/demo/repairs.py +++ b/homeassistant/components/demo/repairs.py @@ -29,6 +29,16 @@ class DemoFixFlow(RepairsFlow): 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, @@ -39,5 +49,9 @@ async def async_create_fix_flow( # 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() diff --git a/homeassistant/components/demo/strings.json b/homeassistant/components/demo/strings.json index e02d64f157f..7be1a133a74 100644 --- a/homeassistant/components/demo/strings.json +++ b/homeassistant/components/demo/strings.json @@ -23,6 +23,15 @@ } } }, + "cold_tea": { + "title": "The tea is cold", + "fix_flow": { + "step": {}, + "abort": { + "not_tea_time": "Can not re-heat the tea at this time" + } + } + }, "transmogrifier_deprecated": { "title": "The transmogrifier component is deprecated", "description": "The transmogrifier component is now deprecated due to the lack of local control available in the new API" diff --git a/homeassistant/components/demo/translations/en.json b/homeassistant/components/demo/translations/en.json index a98f0d3c28d..150ee6c8830 100644 --- a/homeassistant/components/demo/translations/en.json +++ b/homeassistant/components/demo/translations/en.json @@ -11,6 +11,15 @@ }, "title": "The power supply is not stable" }, + "cold_tea": { + "fix_flow": { + "abort": { + "not_tea_time": "Can not re-heat the tea at this time" + }, + "step": {} + }, + "title": "The tea is cold" + }, "out_of_blinker_fluid": { "fix_flow": { "step": { @@ -33,6 +42,9 @@ }, "options": { "step": { + "init": { + "data": {} + }, "options_1": { "data": { "bool": "Optional boolean", diff --git a/tests/components/demo/test_init.py b/tests/components/demo/test_init.py index 1dd049f8ab4..7ba339a71d2 100644 --- a/tests/components/demo/test_init.py +++ b/tests/components/demo/test_init.py @@ -192,6 +192,20 @@ async def test_issues_created(mock_history, hass, hass_client, hass_ws_client): "translation_key": "bad_psu", "translation_placeholders": None, }, + { + "breaks_in_ha_version": None, + "created": ANY, + "dismissed_version": None, + "domain": "demo", + "is_fixable": True, + "issue_domain": None, + "issue_id": "cold_tea", + "learn_more_url": None, + "severity": "warning", + "translation_key": "cold_tea", + "translation_placeholders": None, + "ignored": False, + }, ] } @@ -280,5 +294,19 @@ async def test_issues_created(mock_history, hass, hass_client, hass_ws_client): "translation_key": "bad_psu", "translation_placeholders": None, }, + { + "breaks_in_ha_version": None, + "created": ANY, + "dismissed_version": None, + "domain": "demo", + "is_fixable": True, + "issue_domain": None, + "issue_id": "cold_tea", + "learn_more_url": None, + "severity": "warning", + "translation_key": "cold_tea", + "translation_placeholders": None, + "ignored": False, + }, ] }