Delete binary door deprecation issue on unload at Home Connect (#129947)

pull/129970/head
J. Diego Rodríguez Royo 2024-11-06 14:44:17 +01:00 committed by Franck Nijhof
parent 22b5071c26
commit dfc3423c83
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 20 additions and 4 deletions

View File

@ -13,7 +13,11 @@ from homeassistant.components.script import scripts_with_entity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_create_issue,
async_delete_issue,
)
from .api import HomeConnectDevice
from .const import (
@ -206,3 +210,9 @@ class HomeConnectDoorBinarySensor(HomeConnectBinarySensor):
"items": "\n".join([f"- {item}" for item in items]),
},
)
async def async_will_remove_from_hass(self) -> None:
"""Call when entity will be removed from hass."""
async_delete_issue(
self.hass, DOMAIN, f"deprecated_binary_common_door_sensor_{self.entity_id}"
)

View File

@ -152,6 +152,7 @@ async def test_create_issue(
"""Test we create an issue when an automation or script is using a deprecated entity."""
entity_id = "binary_sensor.washer_door"
get_appliances.return_value = [appliance]
issue_id = f"deprecated_binary_common_door_sensor_{entity_id}"
assert await async_setup_component(
hass,
@ -196,6 +197,11 @@ async def test_create_issue(
assert scripts_with_entity(hass, entity_id)[0] == "script.test"
assert len(issue_registry.issues) == 1
assert issue_registry.async_get_issue(
DOMAIN, f"deprecated_binary_common_door_sensor_{entity_id}"
)
assert issue_registry.async_get_issue(DOMAIN, issue_id)
await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
# Assert the issue is no longer present
assert not issue_registry.async_get_issue(DOMAIN, issue_id)
assert len(issue_registry.issues) == 0