mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add protocol type for legacy notify platforms (#77894)
This commit is contained in:
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])
|
await asyncio.wait([asyncio.create_task(setup) for setup in platform_setups])
|
||||||
|
|
||||||
async def persistent_notification(service: ServiceCall) -> None:
|
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 = service.data[ATTR_MESSAGE]
|
||||||
message.hass = hass
|
message.hass = hass
|
||||||
check_templates_warn(hass, message)
|
check_templates_warn(hass, message)
|
||||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Coroutine
|
from collections.abc import Coroutine
|
||||||
from functools import partial
|
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.const import CONF_DESCRIPTION, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
@ -33,6 +33,26 @@ NOTIFY_SERVICES = "notify_services"
|
|||||||
NOTIFY_DISCOVERY_DISPATCHER = "notify_discovery_dispatcher"
|
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
|
@callback
|
||||||
def async_setup_legacy(
|
def async_setup_legacy(
|
||||||
hass: HomeAssistant, config: ConfigType
|
hass: HomeAssistant, config: ConfigType
|
||||||
@ -50,8 +70,9 @@ def async_setup_legacy(
|
|||||||
if p_config is None:
|
if p_config is None:
|
||||||
p_config = {}
|
p_config = {}
|
||||||
|
|
||||||
platform = await async_prepare_setup_platform(
|
platform = cast(
|
||||||
hass, config, DOMAIN, integration_name
|
Optional[LegacyNotifyPlatform],
|
||||||
|
await async_prepare_setup_platform(hass, config, DOMAIN, integration_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
if platform is None:
|
if platform is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user