Improve issue_registry event typing (#117023)
parent
b9d26c097f
commit
f9e2ab2e81
|
@ -6,7 +6,7 @@ import dataclasses
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
import functools as ft
|
import functools as ft
|
||||||
from typing import Any, cast
|
from typing import Any, Literal, TypedDict, cast
|
||||||
|
|
||||||
from awesomeversion import AwesomeVersion, AwesomeVersionStrategy
|
from awesomeversion import AwesomeVersion, AwesomeVersionStrategy
|
||||||
|
|
||||||
|
@ -14,18 +14,29 @@ from homeassistant.const import __version__ as ha_version
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.util.async_ import run_callback_threadsafe
|
from homeassistant.util.async_ import run_callback_threadsafe
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
from homeassistant.util.event_type import EventType
|
||||||
from homeassistant.util.hass_dict import HassKey
|
from homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
from .registry import BaseRegistry
|
from .registry import BaseRegistry
|
||||||
from .storage import Store
|
from .storage import Store
|
||||||
|
|
||||||
DATA_REGISTRY: HassKey[IssueRegistry] = HassKey("issue_registry")
|
DATA_REGISTRY: HassKey[IssueRegistry] = HassKey("issue_registry")
|
||||||
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED = "repairs_issue_registry_updated"
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED: EventType[EventIssueRegistryUpdatedData] = (
|
||||||
|
EventType("repairs_issue_registry_updated")
|
||||||
|
)
|
||||||
STORAGE_KEY = "repairs.issue_registry"
|
STORAGE_KEY = "repairs.issue_registry"
|
||||||
STORAGE_VERSION_MAJOR = 1
|
STORAGE_VERSION_MAJOR = 1
|
||||||
STORAGE_VERSION_MINOR = 2
|
STORAGE_VERSION_MINOR = 2
|
||||||
|
|
||||||
|
|
||||||
|
class EventIssueRegistryUpdatedData(TypedDict):
|
||||||
|
"""Event data for when the issue registry is updated."""
|
||||||
|
|
||||||
|
action: Literal["create", "remove", "update"]
|
||||||
|
domain: str
|
||||||
|
issue_id: str
|
||||||
|
|
||||||
|
|
||||||
class IssueSeverity(StrEnum):
|
class IssueSeverity(StrEnum):
|
||||||
"""Issue severity."""
|
"""Issue severity."""
|
||||||
|
|
||||||
|
@ -155,7 +166,11 @@ class IssueRegistry(BaseRegistry):
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
self.hass.bus.async_fire_internal(
|
self.hass.bus.async_fire_internal(
|
||||||
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
{"action": "create", "domain": domain, "issue_id": issue_id},
|
EventIssueRegistryUpdatedData(
|
||||||
|
action="create",
|
||||||
|
domain=domain,
|
||||||
|
issue_id=issue_id,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
replacement = dataclasses.replace(
|
replacement = dataclasses.replace(
|
||||||
|
@ -177,7 +192,11 @@ class IssueRegistry(BaseRegistry):
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
self.hass.bus.async_fire_internal(
|
self.hass.bus.async_fire_internal(
|
||||||
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
{"action": "update", "domain": domain, "issue_id": issue_id},
|
EventIssueRegistryUpdatedData(
|
||||||
|
action="update",
|
||||||
|
domain=domain,
|
||||||
|
issue_id=issue_id,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
@ -192,7 +211,11 @@ class IssueRegistry(BaseRegistry):
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
self.hass.bus.async_fire_internal(
|
self.hass.bus.async_fire_internal(
|
||||||
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
{"action": "remove", "domain": domain, "issue_id": issue_id},
|
EventIssueRegistryUpdatedData(
|
||||||
|
action="remove",
|
||||||
|
domain=domain,
|
||||||
|
issue_id=issue_id,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -212,7 +235,11 @@ class IssueRegistry(BaseRegistry):
|
||||||
self.async_schedule_save()
|
self.async_schedule_save()
|
||||||
self.hass.bus.async_fire_internal(
|
self.hass.bus.async_fire_internal(
|
||||||
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
EVENT_REPAIRS_ISSUE_REGISTRY_UPDATED,
|
||||||
{"action": "update", "domain": domain, "issue_id": issue_id},
|
EventIssueRegistryUpdatedData(
|
||||||
|
action="update",
|
||||||
|
domain=domain,
|
||||||
|
issue_id=issue_id,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return issue
|
return issue
|
||||||
|
|
Loading…
Reference in New Issue