Add protocol type for legacy notify platforms (#77894)
parent
dbb556a812
commit
87ab14d758
|
@ -57,7 +57,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
await asyncio.wait([asyncio.create_task(setup) for setup in platform_setups])
|
||||
|
||||
async def persistent_notification(service: ServiceCall) -> None:
|
||||
"""Send notification via the built-in persistsent_notify integration."""
|
||||
"""Send notification via the built-in persistent_notify integration."""
|
||||
message = service.data[ATTR_MESSAGE]
|
||||
message.hass = hass
|
||||
check_templates_warn(hass, message)
|
||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
import asyncio
|
||||
from collections.abc import Coroutine
|
||||
from functools import partial
|
||||
from typing import Any, cast
|
||||
from typing import Any, Optional, Protocol, cast
|
||||
|
||||
from homeassistant.const import CONF_DESCRIPTION, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
|
@ -33,6 +33,26 @@ NOTIFY_SERVICES = "notify_services"
|
|||
NOTIFY_DISCOVERY_DISPATCHER = "notify_discovery_dispatcher"
|
||||
|
||||
|
||||
class LegacyNotifyPlatform(Protocol):
|
||||
"""Define the format of legacy notify platforms."""
|
||||
|
||||
async def async_get_service(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
discovery_info: DiscoveryInfoType | None = ...,
|
||||
) -> BaseNotificationService:
|
||||
"""Set up notification service."""
|
||||
|
||||
def get_service(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
discovery_info: DiscoveryInfoType | None = ...,
|
||||
) -> BaseNotificationService:
|
||||
"""Set up notification service."""
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_legacy(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
|
@ -50,8 +70,9 @@ def async_setup_legacy(
|
|||
if p_config is None:
|
||||
p_config = {}
|
||||
|
||||
platform = await async_prepare_setup_platform(
|
||||
hass, config, DOMAIN, integration_name
|
||||
platform = cast(
|
||||
Optional[LegacyNotifyPlatform],
|
||||
await async_prepare_setup_platform(hass, config, DOMAIN, integration_name),
|
||||
)
|
||||
|
||||
if platform is None:
|
||||
|
|
Loading…
Reference in New Issue