From 88c12fa1afb38e18725f503d46d348eec2337887 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Thu, 21 May 2026 17:58:28 +0000 Subject: [PATCH] Remove issue on config entry removal --- homeassistant/components/min_max/__init__.py | 11 ++++- tests/components/min_max/test_init.py | 51 +++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/min_max/__init__.py b/homeassistant/components/min_max/__init__.py index 3a64644c7365..8e6a5f080af3 100644 --- a/homeassistant/components/min_max/__init__.py +++ b/homeassistant/components/min_max/__init__.py @@ -3,7 +3,11 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue +from homeassistant.helpers.issue_registry import ( + IssueSeverity, + async_create_issue, + async_delete_issue, +) from .const import DOMAIN @@ -31,3 +35,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + + +async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: + """Remove a config entry.""" + async_delete_issue(hass, DOMAIN, f"migrate_to_group_sensor-{entry.entry_id}") diff --git a/tests/components/min_max/test_init.py b/tests/components/min_max/test_init.py index e781da2d0a3b..86099d1c885b 100644 --- a/tests/components/min_max/test_init.py +++ b/tests/components/min_max/test_init.py @@ -25,7 +25,7 @@ async def test_setup_migrates_to_groups( hass_client: ClientSessionGenerator, hass_ws_client: WebSocketGenerator, ) -> None: - """Test setting up and removing a config entry.""" + """Test migrating to group sensors.""" assert await async_setup_component(hass, "repairs", {}) hass.states.async_set("sensor.input_one", "10") hass.states.async_set("sensor.input_two", "20") @@ -108,3 +108,52 @@ async def test_setup_migrates_to_groups( await hass.async_block_till_done() state = hass.states.get(min_max_entity_id) assert state.state == "30.0" + + +async def test_issue_is_deleted_on_removal( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + issue_registry: ir.IssueRegistry, + freezer: FrozenDateTimeFactory, + snapshot: SnapshotAssertion, + hass_client: ClientSessionGenerator, + hass_ws_client: WebSocketGenerator, +) -> None: + """Test issue is removed on config entry removal.""" + assert await async_setup_component(hass, "repairs", {}) + hass.states.async_set("sensor.input_one", "10") + hass.states.async_set("sensor.input_two", "20") + + input_sensors = ["sensor.input_one", "sensor.input_two"] + + # Setup the config entry + config_entry = MockConfigEntry( + data={}, + domain=DOMAIN, + entry_id="123", + options={ + "entity_ids": input_sensors, + "name": "My min_max", + "round_digits": 2.0, + "type": "max", + }, + title="My min_max", + ) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) + await hass.async_block_till_done() + + issue = issue_registry.async_get_issue( + DOMAIN, f"migrate_to_group_sensor-{config_entry.entry_id}" + ) + assert issue is not None + assert issue.is_fixable is True + assert issue.breaks_in_ha_version == "2026.12.0" + + assert await hass.config_entries.async_remove(config_entry.entry_id) + await hass.async_block_till_done() + + issue = issue_registry.async_get_issue( + DOMAIN, f"migrate_to_group_sensor-{config_entry.entry_id}" + ) + assert issue is None