diff --git a/.coveragerc b/.coveragerc index 3c587e11cf6..341494b1424 100644 --- a/.coveragerc +++ b/.coveragerc @@ -388,6 +388,7 @@ omit = homeassistant/components/flume/__init__.py homeassistant/components/flume/sensor.py homeassistant/components/flunearyou/__init__.py + homeassistant/components/flunearyou/repairs.py homeassistant/components/flunearyou/sensor.py homeassistant/components/folder/sensor.py homeassistant/components/folder_watcher/* diff --git a/homeassistant/components/flunearyou/__init__.py b/homeassistant/components/flunearyou/__init__.py index 5e48e1561b5..75349002ec0 100644 --- a/homeassistant/components/flunearyou/__init__.py +++ b/homeassistant/components/flunearyou/__init__.py @@ -9,6 +9,7 @@ from typing import Any from pyflunearyou import Client from pyflunearyou.errors import FluNearYouError +from homeassistant.components.repairs import IssueSeverity, async_create_issue from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, Platform from homeassistant.core import HomeAssistant @@ -26,6 +27,15 @@ PLATFORMS = [Platform.SENSOR] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Flu Near You as config entry.""" + async_create_issue( + hass, + DOMAIN, + "integration_removal", + is_fixable=True, + severity=IssueSeverity.ERROR, + translation_key="integration_removal", + ) + websession = aiohttp_client.async_get_clientsession(hass) client = Client(session=websession) diff --git a/homeassistant/components/flunearyou/manifest.json b/homeassistant/components/flunearyou/manifest.json index ee69961d1b0..fa98bf2e01e 100644 --- a/homeassistant/components/flunearyou/manifest.json +++ b/homeassistant/components/flunearyou/manifest.json @@ -3,6 +3,7 @@ "name": "Flu Near You", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/flunearyou", + "dependencies": ["repairs"], "requirements": ["pyflunearyou==2.0.2"], "codeowners": ["@bachya"], "iot_class": "cloud_polling", diff --git a/homeassistant/components/flunearyou/repairs.py b/homeassistant/components/flunearyou/repairs.py new file mode 100644 index 00000000000..f48085ba623 --- /dev/null +++ b/homeassistant/components/flunearyou/repairs.py @@ -0,0 +1,42 @@ +"""Repairs platform for the Flu Near You integration.""" +from __future__ import annotations + +import asyncio + +import voluptuous as vol + +from homeassistant import data_entry_flow +from homeassistant.components.repairs import RepairsFlow +from homeassistant.core import HomeAssistant + +from .const import DOMAIN + + +class FluNearYouFixFlow(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: + removal_tasks = [ + self.hass.config_entries.async_remove(entry.entry_id) + for entry in self.hass.config_entries.async_entries(DOMAIN) + ] + await asyncio.gather(*removal_tasks) + return self.async_create_entry(title="Fixed issue", data={}) + return self.async_show_form(step_id="confirm", data_schema=vol.Schema({})) + + +async def async_create_fix_flow( + hass: HomeAssistant, issue_id: str +) -> FluNearYouFixFlow: + """Create flow.""" + return FluNearYouFixFlow() diff --git a/homeassistant/components/flunearyou/strings.json b/homeassistant/components/flunearyou/strings.json index 4df0326fc3b..59ec6125a34 100644 --- a/homeassistant/components/flunearyou/strings.json +++ b/homeassistant/components/flunearyou/strings.json @@ -16,5 +16,18 @@ "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_location%]" } + }, + "issues": { + "integration_removal": { + "title": "Flu Near You is no longer available", + "fix_flow": { + "step": { + "confirm": { + "title": "Remove Flu Near You", + "description": "The external data source powering the Flu Near You integration is no longer available; thus, the integration no longer works.\n\nPress SUBMIT to remove Flu Near You from your Home Assistant instance." + } + } + } + } } } diff --git a/homeassistant/components/flunearyou/translations/en.json b/homeassistant/components/flunearyou/translations/en.json index 29af5b2b288..3dcbfa2a628 100644 --- a/homeassistant/components/flunearyou/translations/en.json +++ b/homeassistant/components/flunearyou/translations/en.json @@ -16,5 +16,18 @@ "title": "Configure Flu Near You" } } + }, + "issues": { + "integration_removal": { + "fix_flow": { + "step": { + "confirm": { + "description": "The data source that powered the Flu Near You integration is no longer available. Press SUBMIT to remove all configured instances of the integration from Home Assistant.", + "title": "Remove Flu Near You" + } + } + }, + "title": "Flu Near You is no longer available" + } } } \ No newline at end of file