mirror of
https://github.com/home-assistant/core.git
synced 2026-12-05 05:14:01 -04:00
Move persistent_notification service registration to services module (#184680)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
co-authored by
Claude Opus 5.5
Franck Nijhof
parent
efcd5c5624
commit
ea3b6898b2
@@ -8,7 +8,7 @@ from typing import Any
|
||||
import probatio
|
||||
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
@@ -33,10 +33,7 @@ from .helpers import ( # noqa: F401
|
||||
create,
|
||||
dismiss,
|
||||
)
|
||||
|
||||
SCHEMA_SERVICE_NOTIFICATION = probatio.Schema(
|
||||
{probatio.Required(ATTR_NOTIFICATION_ID): cv.string}
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -46,44 +43,7 @@ CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the persistent notification component."""
|
||||
|
||||
@callback
|
||||
def create_service(call: ServiceCall) -> None:
|
||||
"""Handle a create notification service call."""
|
||||
async_create(
|
||||
hass,
|
||||
call.data[ATTR_MESSAGE],
|
||||
call.data.get(ATTR_TITLE),
|
||||
call.data.get(ATTR_NOTIFICATION_ID),
|
||||
)
|
||||
|
||||
@callback
|
||||
def dismiss_service(call: ServiceCall) -> None:
|
||||
"""Handle the dismiss notification service call."""
|
||||
async_dismiss(hass, call.data[ATTR_NOTIFICATION_ID])
|
||||
|
||||
@callback
|
||||
def dismiss_all_service(call: ServiceCall) -> None:
|
||||
"""Handle the dismiss all notification service call."""
|
||||
async_dismiss_all(hass)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
"create",
|
||||
create_service,
|
||||
probatio.Schema(
|
||||
{
|
||||
probatio.Required(ATTR_MESSAGE): cv.string,
|
||||
probatio.Optional(ATTR_TITLE): cv.string,
|
||||
probatio.Optional(ATTR_NOTIFICATION_ID): cv.string,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, "dismiss", dismiss_service, SCHEMA_SERVICE_NOTIFICATION
|
||||
)
|
||||
|
||||
hass.services.async_register(DOMAIN, "dismiss_all", dismiss_all_service, None)
|
||||
async_setup_services(hass)
|
||||
|
||||
websocket_api.async_register_command(hass, websocket_get_notifications)
|
||||
websocket_api.async_register_command(hass, websocket_subscribe_notifications)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
"""Services for the Persistent Notification integration."""
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
from .const import ATTR_MESSAGE, ATTR_NOTIFICATION_ID, ATTR_TITLE, DOMAIN
|
||||
from .helpers import async_create, async_dismiss, async_dismiss_all
|
||||
|
||||
SCHEMA_SERVICE_NOTIFICATION = probatio.Schema(
|
||||
{probatio.Required(ATTR_NOTIFICATION_ID): cv.string}
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def _create_service(call: ServiceCall) -> None:
|
||||
"""Handle a create notification service call."""
|
||||
hass = call.hass
|
||||
async_create(
|
||||
hass,
|
||||
call.data[ATTR_MESSAGE],
|
||||
call.data.get(ATTR_TITLE),
|
||||
call.data.get(ATTR_NOTIFICATION_ID),
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def _dismiss_service(call: ServiceCall) -> None:
|
||||
"""Handle the dismiss notification service call."""
|
||||
hass = call.hass
|
||||
async_dismiss(hass, call.data[ATTR_NOTIFICATION_ID])
|
||||
|
||||
|
||||
@callback
|
||||
def _dismiss_all_service(call: ServiceCall) -> None:
|
||||
"""Handle the dismiss all notification service call."""
|
||||
hass = call.hass
|
||||
async_dismiss_all(hass)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up the services for the Persistent Notification integration."""
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
"create",
|
||||
_create_service,
|
||||
probatio.Schema(
|
||||
{
|
||||
probatio.Required(ATTR_MESSAGE): cv.string,
|
||||
probatio.Optional(ATTR_TITLE): cv.string,
|
||||
probatio.Optional(ATTR_NOTIFICATION_ID): cv.string,
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, "dismiss", _dismiss_service, SCHEMA_SERVICE_NOTIFICATION
|
||||
)
|
||||
|
||||
hass.services.async_register(DOMAIN, "dismiss_all", _dismiss_all_service, None)
|
||||
Reference in New Issue
Block a user