mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add events to repairs issue registry changes (#75784)
This commit is contained in:
parent
e2dd2c9424
commit
0ff34f232c
@ -13,6 +13,7 @@ import homeassistant.util.dt as dt_util
|
|||||||
from .models import IssueSeverity
|
from .models import IssueSeverity
|
||||||
|
|
||||||
DATA_REGISTRY = "issue_registry"
|
DATA_REGISTRY = "issue_registry"
|
||||||
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED = "repairs_issue_registry_updated"
|
||||||
STORAGE_KEY = "repairs.issue_registry"
|
STORAGE_KEY = "repairs.issue_registry"
|
||||||
STORAGE_VERSION = 1
|
STORAGE_VERSION = 1
|
||||||
SAVE_DELAY = 10
|
SAVE_DELAY = 10
|
||||||
@ -82,6 +83,10 @@ class IssueRegistry:
|
|||||||
)
|
)
|
||||||
self.issues[(domain, issue_id)] = issue
|
self.issues[(domain, issue_id)] = issue
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
|
self.hass.bus.async_fire(
|
||||||
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
|
{"action": "create", "domain": domain, "issue_id": issue_id},
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
issue = self.issues[(domain, issue_id)] = dataclasses.replace(
|
issue = self.issues[(domain, issue_id)] = dataclasses.replace(
|
||||||
issue,
|
issue,
|
||||||
@ -93,6 +98,10 @@ class IssueRegistry:
|
|||||||
translation_key=translation_key,
|
translation_key=translation_key,
|
||||||
translation_placeholders=translation_placeholders,
|
translation_placeholders=translation_placeholders,
|
||||||
)
|
)
|
||||||
|
self.hass.bus.async_fire(
|
||||||
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
|
{"action": "update", "domain": domain, "issue_id": issue_id},
|
||||||
|
)
|
||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
|
||||||
@ -103,6 +112,10 @@ class IssueRegistry:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
|
self.hass.bus.async_fire(
|
||||||
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
|
{"action": "remove", "domain": domain, "issue_id": issue_id},
|
||||||
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_ignore(self, domain: str, issue_id: str, ignore: bool) -> IssueEntry:
|
def async_ignore(self, domain: str, issue_id: str, ignore: bool) -> IssueEntry:
|
||||||
@ -118,6 +131,10 @@ class IssueRegistry:
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
|
self.hass.bus.async_fire(
|
||||||
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
|
{"action": "update", "domain": domain, "issue_id": issue_id},
|
||||||
|
)
|
||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
"""Test the repairs websocket API."""
|
"""Test the repairs websocket API."""
|
||||||
from homeassistant.components.repairs import async_create_issue, issue_registry
|
from homeassistant.components.repairs import async_create_issue, issue_registry
|
||||||
from homeassistant.components.repairs.const import DOMAIN
|
from homeassistant.components.repairs.const import DOMAIN
|
||||||
from homeassistant.components.repairs.issue_handler import async_ignore_issue
|
from homeassistant.components.repairs.issue_handler import (
|
||||||
|
async_delete_issue,
|
||||||
|
async_ignore_issue,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import flush_store
|
from tests.common import async_capture_events, flush_store
|
||||||
|
|
||||||
|
|
||||||
async def test_load_issues(hass: HomeAssistant) -> None:
|
async def test_load_issues(hass: HomeAssistant) -> None:
|
||||||
@ -33,8 +36,22 @@ async def test_load_issues(hass: HomeAssistant) -> None:
|
|||||||
"translation_key": "even_worse",
|
"translation_key": "even_worse",
|
||||||
"translation_placeholders": {"def": "456"},
|
"translation_placeholders": {"def": "456"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"breaks_in_ha_version": "2022.7",
|
||||||
|
"domain": "test",
|
||||||
|
"issue_id": "issue_3",
|
||||||
|
"is_fixable": True,
|
||||||
|
"learn_more_url": "https://checkboxrace.com",
|
||||||
|
"severity": "other",
|
||||||
|
"translation_key": "even_worse",
|
||||||
|
"translation_placeholders": {"def": "789"},
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
events = async_capture_events(
|
||||||
|
hass, issue_registry.EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED
|
||||||
|
)
|
||||||
|
|
||||||
for issue in issues:
|
for issue in issues:
|
||||||
async_create_issue(
|
async_create_issue(
|
||||||
hass,
|
hass,
|
||||||
@ -47,7 +64,45 @@ async def test_load_issues(hass: HomeAssistant) -> None:
|
|||||||
translation_key=issue["translation_key"],
|
translation_key=issue["translation_key"],
|
||||||
translation_placeholders=issue["translation_placeholders"],
|
translation_placeholders=issue["translation_placeholders"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(events) == 3
|
||||||
|
assert events[0].data == {
|
||||||
|
"action": "create",
|
||||||
|
"domain": "test",
|
||||||
|
"issue_id": "issue_1",
|
||||||
|
}
|
||||||
|
assert events[1].data == {
|
||||||
|
"action": "create",
|
||||||
|
"domain": "test",
|
||||||
|
"issue_id": "issue_2",
|
||||||
|
}
|
||||||
|
assert events[2].data == {
|
||||||
|
"action": "create",
|
||||||
|
"domain": "test",
|
||||||
|
"issue_id": "issue_3",
|
||||||
|
}
|
||||||
|
|
||||||
async_ignore_issue(hass, issues[0]["domain"], issues[0]["issue_id"], True)
|
async_ignore_issue(hass, issues[0]["domain"], issues[0]["issue_id"], True)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(events) == 4
|
||||||
|
assert events[3].data == {
|
||||||
|
"action": "update",
|
||||||
|
"domain": "test",
|
||||||
|
"issue_id": "issue_1",
|
||||||
|
}
|
||||||
|
|
||||||
|
async_delete_issue(hass, issues[2]["domain"], issues[2]["issue_id"])
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(events) == 5
|
||||||
|
assert events[4].data == {
|
||||||
|
"action": "remove",
|
||||||
|
"domain": "test",
|
||||||
|
"issue_id": "issue_3",
|
||||||
|
}
|
||||||
|
|
||||||
registry: issue_registry.IssueRegistry = hass.data[issue_registry.DATA_REGISTRY]
|
registry: issue_registry.IssueRegistry = hass.data[issue_registry.DATA_REGISTRY]
|
||||||
assert len(registry.issues) == 2
|
assert len(registry.issues) == 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user