mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Improve notify typing (#78575)
This commit is contained in:
parent
fbd265aa2d
commit
383c83d15f
@ -2,7 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Coroutine
|
||||
from collections.abc import Callable, Coroutine
|
||||
from functools import partial
|
||||
from typing import Any, Optional, Protocol, cast
|
||||
|
||||
@ -162,9 +162,11 @@ async def async_reload(hass: HomeAssistant, integration_name: str) -> None:
|
||||
if not _async_integration_has_notify_services(hass, integration_name):
|
||||
return
|
||||
|
||||
notify_services: list[BaseNotificationService] = hass.data[NOTIFY_SERVICES][
|
||||
integration_name
|
||||
]
|
||||
tasks = [
|
||||
notify_service.async_register_services()
|
||||
for notify_service in hass.data[NOTIFY_SERVICES][integration_name]
|
||||
notify_service.async_register_services() for notify_service in notify_services
|
||||
]
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
@ -173,15 +175,20 @@ async def async_reload(hass: HomeAssistant, integration_name: str) -> None:
|
||||
@bind_hass
|
||||
async def async_reset_platform(hass: HomeAssistant, integration_name: str) -> None:
|
||||
"""Unregister notify services for an integration."""
|
||||
if NOTIFY_DISCOVERY_DISPATCHER in hass.data:
|
||||
hass.data[NOTIFY_DISCOVERY_DISPATCHER]()
|
||||
notify_discovery_dispatcher: Callable[[], None] | None = hass.data.get(
|
||||
NOTIFY_DISCOVERY_DISPATCHER
|
||||
)
|
||||
if notify_discovery_dispatcher:
|
||||
notify_discovery_dispatcher()
|
||||
hass.data[NOTIFY_DISCOVERY_DISPATCHER] = None
|
||||
if not _async_integration_has_notify_services(hass, integration_name):
|
||||
return
|
||||
|
||||
notify_services: list[BaseNotificationService] = hass.data[NOTIFY_SERVICES][
|
||||
integration_name
|
||||
]
|
||||
tasks = [
|
||||
notify_service.async_unregister_services()
|
||||
for notify_service in hass.data[NOTIFY_SERVICES][integration_name]
|
||||
notify_service.async_unregister_services() for notify_service in notify_services
|
||||
]
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
Loading…
x
Reference in New Issue
Block a user