diff --git a/homeassistant/components/notify/__init__.py b/homeassistant/components/notify/__init__.py index 1fc7836ecd858e..5aac58b2bad302 100644 --- a/homeassistant/components/notify/__init__.py +++ b/homeassistant/components/notify/__init__.py @@ -102,11 +102,17 @@ async def persistent_notification(service: ServiceCall) -> None: title = title_tpl.async_render(parse_result=False) notification_id = None + actions = None if data := service.data.get(ATTR_DATA): notification_id = data.get(pn.ATTR_NOTIFICATION_ID) + actions = data.get(pn.ATTR_ACTIONS) pn.async_create( - hass, message.async_render(parse_result=False), title, notification_id + hass, + message.async_render(parse_result=False), + title, + notification_id, + actions, ) hass.services.async_register( diff --git a/homeassistant/components/persistent_notification/__init__.py b/homeassistant/components/persistent_notification/__init__.py index a785d015ffb620..bdfff25d9f7625 100644 --- a/homeassistant/components/persistent_notification/__init__.py +++ b/homeassistant/components/persistent_notification/__init__.py @@ -30,7 +30,16 @@ ATTR_MESSAGE: Final = "message" ATTR_NOTIFICATION_ID: Final = "notification_id" ATTR_TITLE: Final = "title" +ATTR_ACTION: Final = "action" ATTR_STATUS: Final = "status" +ATTR_ACTIONS: Final = "actions" + + +class NotificationAction(TypedDict): + """Action for a persistent notification.""" + + action: str + title: str class Notification(TypedDict): @@ -40,6 +49,7 @@ class Notification(TypedDict): message: str notification_id: str title: str | None + actions: list[NotificationAction] | None class UpdateType(StrEnum): @@ -81,9 +91,10 @@ def create( message: str, title: str | None = None, notification_id: str | None = None, + actions: list[NotificationAction] | None = None, ) -> None: """Generate a notification.""" - hass.add_job(async_create, hass, message, title, notification_id) + hass.add_job(async_create, hass, message, title, notification_id, actions) @bind_hass @@ -99,6 +110,7 @@ def async_create( message: str, title: str | None = None, notification_id: str | None = None, + actions: list[NotificationAction] | None = None, ) -> None: """Generate a notification.""" notifications = _async_get_or_create_notifications(hass) @@ -108,6 +120,7 @@ def async_create( ATTR_MESSAGE: message, ATTR_NOTIFICATION_ID: notification_id, ATTR_TITLE: title, + ATTR_ACTIONS: actions, ATTR_CREATED_AT: dt_util.utcnow(), } @@ -166,6 +179,7 @@ def create_service(call: ServiceCall) -> None: call.data[ATTR_MESSAGE], call.data.get(ATTR_TITLE), call.data.get(ATTR_NOTIFICATION_ID), + call.data.get(ATTR_ACTIONS), ) @callback @@ -187,6 +201,17 @@ def dismiss_all_service(call: ServiceCall) -> None: vol.Required(ATTR_MESSAGE): vol.Any(cv.dynamic_template, cv.string), vol.Optional(ATTR_TITLE): vol.Any(cv.dynamic_template, cv.string), vol.Optional(ATTR_NOTIFICATION_ID): cv.string, + vol.Optional(ATTR_ACTIONS): vol.All( + cv.ensure_list, + [ + vol.Schema( + { + vol.Required(ATTR_ACTION): cv.string, + vol.Required(ATTR_TITLE): cv.string, + } + ) + ], + ), } ), ) diff --git a/homeassistant/components/persistent_notification/services.yaml b/homeassistant/components/persistent_notification/services.yaml index c335d96260087d..553c4188d3dd10 100644 --- a/homeassistant/components/persistent_notification/services.yaml +++ b/homeassistant/components/persistent_notification/services.yaml @@ -9,6 +9,9 @@ create: example: Test notification selector: text: + actions: + selector: + object: notification_id: example: 1234 selector: diff --git a/homeassistant/components/persistent_notification/strings.json b/homeassistant/components/persistent_notification/strings.json index ca89a4d33cd630..3e0fed30b7ed86 100644 --- a/homeassistant/components/persistent_notification/strings.json +++ b/homeassistant/components/persistent_notification/strings.json @@ -13,6 +13,10 @@ "name": "Title", "description": "Optional title of the notification." }, + "actions": { + "name": "Actions", + "description": "Optional actions to be presented to the user with the notification." + }, "notification_id": { "name": "Notification ID", "description": "ID of the notification. This new notification will overwrite an existing notification with the same ID."