mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add action enums to ntfy (#190881)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Constants for the ntfy integration."""
|
||||
|
||||
from enum import StrEnum
|
||||
from typing import Final
|
||||
|
||||
DOMAIN = "ntfy"
|
||||
@@ -15,3 +16,31 @@ SECTION_FILTER = "filter"
|
||||
NTFY_EVENT = "ntfy_event"
|
||||
|
||||
SUBENTRY_TYPE_TOPIC = "topic"
|
||||
|
||||
|
||||
class NtfyService(StrEnum):
|
||||
"""Store keys for ntfy services."""
|
||||
|
||||
PUBLISH = "publish"
|
||||
CLEAR = "clear"
|
||||
DELETE = "delete"
|
||||
|
||||
|
||||
class NtfyServiceArgument(StrEnum):
|
||||
"""Store keys for ntfy service arguments."""
|
||||
|
||||
TITLE = "title"
|
||||
MESSAGE = "message"
|
||||
MARKDOWN = "markdown"
|
||||
TAGS = "tags"
|
||||
PRIORITY = "priority"
|
||||
CLICK = "click"
|
||||
DELAY = "delay"
|
||||
ATTACH = "attach"
|
||||
ATTACH_FILE = "attach_file"
|
||||
FILENAME = "filename"
|
||||
EMAIL = "email"
|
||||
CALL = "call"
|
||||
ICON = "icon"
|
||||
ACTIONS = "actions"
|
||||
SEQUENCE_ID = "sequence_id"
|
||||
|
||||
@@ -25,17 +25,10 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, NtfyServiceArgument
|
||||
from .coordinator import NtfyConfigEntry
|
||||
from .entity import NtfyBaseEntity
|
||||
from .services import (
|
||||
ACTIONS_MAP,
|
||||
ATTR_ACTION,
|
||||
ATTR_ACTIONS,
|
||||
ATTR_ATTACH_FILE,
|
||||
ATTR_FILENAME,
|
||||
ATTR_SEQUENCE_ID,
|
||||
)
|
||||
from .services import ACTIONS_MAP, ATTR_ACTION
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -79,20 +72,20 @@ class NtfyNotifyEntity(NtfyBaseEntity, NotifyEntity):
|
||||
"""Shared internal helper to publish a message to a topic."""
|
||||
attachment = None
|
||||
params: dict[str, Any] = kwargs
|
||||
delay: timedelta | None = params.get("delay")
|
||||
delay: timedelta | None = params.get(NtfyServiceArgument.DELAY)
|
||||
if delay:
|
||||
params["delay"] = f"{delay.total_seconds()}s"
|
||||
if params.get("email"):
|
||||
params[NtfyServiceArgument.DELAY] = f"{delay.total_seconds()}s"
|
||||
if params.get(NtfyServiceArgument.EMAIL):
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="delay_no_email",
|
||||
)
|
||||
if params.get("call"):
|
||||
if params.get(NtfyServiceArgument.CALL):
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="delay_no_call",
|
||||
)
|
||||
if file := params.pop(ATTR_ATTACH_FILE, None):
|
||||
if file := params.pop(NtfyServiceArgument.ATTACH_FILE, None):
|
||||
media_content_id: str = file["media_content_id"]
|
||||
if media_content_id.startswith("media-source://tts/"):
|
||||
_, attachment = await tts.async_get_media_source_audio(
|
||||
@@ -117,11 +110,11 @@ class NtfyNotifyEntity(NtfyBaseEntity, NotifyEntity):
|
||||
media.path.read_bytes
|
||||
)
|
||||
|
||||
params.setdefault(ATTR_FILENAME, media.path.name)
|
||||
params.setdefault(NtfyServiceArgument.FILENAME, media.path.name)
|
||||
|
||||
actions: list[dict[str, Any]] | None = params.get(ATTR_ACTIONS)
|
||||
actions: list[dict[str, Any]] | None = params.get(NtfyServiceArgument.ACTIONS)
|
||||
if actions:
|
||||
params["actions"] = [
|
||||
params[NtfyServiceArgument.ACTIONS] = [
|
||||
ACTIONS_MAP[action[ATTR_ACTION]](
|
||||
**{k: v for k, v in action.items() if k != ATTR_ACTION}
|
||||
)
|
||||
@@ -155,7 +148,7 @@ class NtfyNotifyEntity(NtfyBaseEntity, NotifyEntity):
|
||||
params: dict[str, Any] = kwargs
|
||||
|
||||
try:
|
||||
await self.ntfy.clear(self.topic, params[ATTR_SEQUENCE_ID])
|
||||
await self.ntfy.clear(self.topic, params[NtfyServiceArgument.SEQUENCE_ID])
|
||||
except NtfyUnauthorizedAuthenticationError as e:
|
||||
self.config_entry.async_start_reauth(self.hass)
|
||||
raise HomeAssistantError(
|
||||
@@ -175,7 +168,7 @@ class NtfyNotifyEntity(NtfyBaseEntity, NotifyEntity):
|
||||
params: dict[str, Any] = kwargs
|
||||
|
||||
try:
|
||||
await self.ntfy.delete(self.topic, params[ATTR_SEQUENCE_ID])
|
||||
await self.ntfy.delete(self.topic, params[NtfyServiceArgument.SEQUENCE_ID])
|
||||
except NtfyUnauthorizedAuthenticationError as e:
|
||||
self.config_entry.async_start_reauth(self.hass)
|
||||
raise HomeAssistantError(
|
||||
|
||||
@@ -7,35 +7,15 @@ from aiontfy import BroadcastAction, CopyAction, HttpAction, ViewAction
|
||||
import probatio
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_MESSAGE,
|
||||
ATTR_TITLE,
|
||||
DOMAIN as NOTIFY_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_ICON
|
||||
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv, service
|
||||
from homeassistant.helpers.selector import MediaSelector
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, NtfyService, NtfyServiceArgument
|
||||
|
||||
SERVICE_PUBLISH = "publish"
|
||||
SERVICE_CLEAR = "clear"
|
||||
SERVICE_DELETE = "delete"
|
||||
ATTR_ATTACH = "attach"
|
||||
ATTR_CALL = "call"
|
||||
ATTR_CLICK = "click"
|
||||
ATTR_DELAY = "delay"
|
||||
ATTR_EMAIL = "email"
|
||||
ATTR_MARKDOWN = "markdown"
|
||||
ATTR_PRIORITY = "priority"
|
||||
ATTR_TAGS = "tags"
|
||||
ATTR_SEQUENCE_ID = "sequence_id"
|
||||
ATTR_ATTACH_FILE = "attach_file"
|
||||
ATTR_FILENAME = "filename"
|
||||
GRP_ATTACHMENT = "attachment"
|
||||
MSG_ATTACHMENT = "Only one attachment source is allowed: URL or local file"
|
||||
ATTR_ACTIONS = "actions"
|
||||
ATTR_ACTION = "action"
|
||||
ATTR_VIEW = "view"
|
||||
ATTR_BROADCAST = "broadcast"
|
||||
@@ -61,8 +41,9 @@ MAX_ACTIONS_ALLOWED = 3 # ntfy only supports up to 3 actions per notification
|
||||
|
||||
def validate_filename(params: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Validate filename."""
|
||||
if ATTR_FILENAME in params and not (
|
||||
ATTR_ATTACH_FILE in params or ATTR_ATTACH in params
|
||||
if NtfyServiceArgument.FILENAME in params and not (
|
||||
NtfyServiceArgument.ATTACH_FILE in params
|
||||
or NtfyServiceArgument.ATTACH in params
|
||||
):
|
||||
raise probatio.Invalid("Filename only allowed when attachment is provided")
|
||||
return params
|
||||
@@ -105,34 +86,36 @@ COPY_SCHEMA = ACTION_SCHEMA.extend(
|
||||
SERVICE_PUBLISH_SCHEMA = probatio.All(
|
||||
cv.make_entity_service_schema(
|
||||
{
|
||||
probatio.Optional(ATTR_TITLE): cv.string,
|
||||
probatio.Optional(ATTR_MESSAGE): cv.string,
|
||||
probatio.Optional(ATTR_MARKDOWN): cv.boolean,
|
||||
probatio.Optional(ATTR_TAGS): probatio.All(probatio.EnsureList(), [str]),
|
||||
probatio.Optional(ATTR_PRIORITY): probatio.All(
|
||||
probatio.Optional(NtfyServiceArgument.TITLE): cv.string,
|
||||
probatio.Optional(NtfyServiceArgument.MESSAGE): cv.string,
|
||||
probatio.Optional(NtfyServiceArgument.MARKDOWN): cv.boolean,
|
||||
probatio.Optional(NtfyServiceArgument.TAGS): probatio.All(
|
||||
probatio.EnsureList(), [str]
|
||||
),
|
||||
probatio.Optional(NtfyServiceArgument.PRIORITY): probatio.All(
|
||||
probatio.Coerce(int), probatio.Range(1, 5)
|
||||
),
|
||||
probatio.Optional(ATTR_CLICK): probatio.All(
|
||||
probatio.Optional(NtfyServiceArgument.CLICK): probatio.All(
|
||||
probatio.Url(), probatio.Coerce(URL)
|
||||
),
|
||||
probatio.Optional(ATTR_DELAY): probatio.All(
|
||||
probatio.Optional(NtfyServiceArgument.DELAY): probatio.All(
|
||||
cv.time_period,
|
||||
probatio.Range(min=timedelta(seconds=10), max=timedelta(days=3)),
|
||||
),
|
||||
probatio.Optional(ATTR_EMAIL): probatio.Email(),
|
||||
probatio.Optional(ATTR_CALL): cv.string,
|
||||
probatio.Optional(ATTR_ICON): probatio.All(
|
||||
probatio.Optional(NtfyServiceArgument.EMAIL): probatio.Email(),
|
||||
probatio.Optional(NtfyServiceArgument.CALL): cv.string,
|
||||
probatio.Optional(NtfyServiceArgument.ICON): probatio.All(
|
||||
probatio.Url(), probatio.Coerce(URL)
|
||||
),
|
||||
probatio.Optional(ATTR_SEQUENCE_ID): cv.string,
|
||||
probatio.Optional(NtfyServiceArgument.SEQUENCE_ID): cv.string,
|
||||
probatio.Exclusive(
|
||||
ATTR_ATTACH, GRP_ATTACHMENT, MSG_ATTACHMENT
|
||||
NtfyServiceArgument.ATTACH, GRP_ATTACHMENT, MSG_ATTACHMENT
|
||||
): probatio.All(probatio.Url(), probatio.Coerce(URL)),
|
||||
probatio.Exclusive(
|
||||
ATTR_ATTACH_FILE, GRP_ATTACHMENT, MSG_ATTACHMENT
|
||||
NtfyServiceArgument.ATTACH_FILE, GRP_ATTACHMENT, MSG_ATTACHMENT
|
||||
): MediaSelector({"accept": ["*/*"]}),
|
||||
probatio.Optional(ATTR_FILENAME): cv.string,
|
||||
probatio.Optional(ATTR_ACTIONS): probatio.All(
|
||||
probatio.Optional(NtfyServiceArgument.FILENAME): cv.string,
|
||||
probatio.Optional(NtfyServiceArgument.ACTIONS): probatio.All(
|
||||
probatio.EnsureList(),
|
||||
probatio.Length(
|
||||
max=MAX_ACTIONS_ALLOWED,
|
||||
@@ -157,7 +140,7 @@ SERVICE_PUBLISH_SCHEMA = probatio.All(
|
||||
|
||||
SERVICE_CLEAR_DELETE_SCHEMA = cv.make_entity_service_schema(
|
||||
{
|
||||
probatio.Required(ATTR_SEQUENCE_ID): cv.string,
|
||||
probatio.Required(NtfyServiceArgument.SEQUENCE_ID): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -169,7 +152,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
entity_domain=NOTIFY_DOMAIN,
|
||||
schema=SERVICE_PUBLISH_SCHEMA,
|
||||
description_placeholders={
|
||||
@@ -181,7 +164,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_CLEAR,
|
||||
NtfyService.CLEAR,
|
||||
entity_domain=NOTIFY_DOMAIN,
|
||||
schema=SERVICE_CLEAR_DELETE_SCHEMA,
|
||||
func="clear",
|
||||
@@ -190,7 +173,7 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
service.async_register_platform_entity_service(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SERVICE_DELETE,
|
||||
NtfyService.DELETE,
|
||||
entity_domain=NOTIFY_DOMAIN,
|
||||
schema=SERVICE_CLEAR_DELETE_SCHEMA,
|
||||
func="delete",
|
||||
|
||||
@@ -14,27 +14,9 @@ from pytest_homeassistant.common import AsyncMock, MockConfigEntry, patch
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components import media_source
|
||||
from homeassistant.components.notify import ATTR_MESSAGE, ATTR_TITLE
|
||||
from homeassistant.components.ntfy.const import DOMAIN
|
||||
from homeassistant.components.ntfy.services import (
|
||||
ATTR_ACTIONS,
|
||||
ATTR_ATTACH,
|
||||
ATTR_ATTACH_FILE,
|
||||
ATTR_CALL,
|
||||
ATTR_CLICK,
|
||||
ATTR_DELAY,
|
||||
ATTR_EMAIL,
|
||||
ATTR_FILENAME,
|
||||
ATTR_MARKDOWN,
|
||||
ATTR_PRIORITY,
|
||||
ATTR_SEQUENCE_ID,
|
||||
ATTR_TAGS,
|
||||
SERVICE_CLEAR,
|
||||
SERVICE_DELETE,
|
||||
SERVICE_PUBLISH,
|
||||
)
|
||||
from homeassistant.components.ntfy.const import DOMAIN, NtfyService, NtfyServiceArgument
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON
|
||||
from homeassistant.const import CommonServiceArgument
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -56,20 +38,20 @@ async def test_ntfy_publish(
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_MESSAGE: "Hello",
|
||||
ATTR_TITLE: "World",
|
||||
ATTR_ATTACH: "https://example.org/download.zip",
|
||||
ATTR_CLICK: "https://example.org",
|
||||
ATTR_DELAY: {"days": 1, "seconds": 30},
|
||||
ATTR_ICON: "https://example.org/logo.png",
|
||||
ATTR_MARKDOWN: True,
|
||||
ATTR_PRIORITY: "5",
|
||||
ATTR_TAGS: ["partying_face", "grin"],
|
||||
ATTR_SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
ATTR_ACTIONS: [
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.MESSAGE: "Hello",
|
||||
NtfyServiceArgument.TITLE: "World",
|
||||
NtfyServiceArgument.ATTACH: "https://example.org/download.zip",
|
||||
NtfyServiceArgument.CLICK: "https://example.org",
|
||||
NtfyServiceArgument.DELAY: {"days": 1, "seconds": 30},
|
||||
NtfyServiceArgument.ICON: "https://example.org/logo.png",
|
||||
NtfyServiceArgument.MARKDOWN: True,
|
||||
NtfyServiceArgument.PRIORITY: "5",
|
||||
NtfyServiceArgument.TAGS: ["partying_face", "grin"],
|
||||
NtfyServiceArgument.SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
NtfyServiceArgument.ACTIONS: [
|
||||
{
|
||||
"action": "broadcast",
|
||||
"label": "Take picture",
|
||||
@@ -176,11 +158,11 @@ async def test_send_message_exception(
|
||||
with pytest.raises(HomeAssistantError, match=error_msg):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_MESSAGE: "triggered",
|
||||
ATTR_TITLE: "test",
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.MESSAGE: "triggered",
|
||||
NtfyServiceArgument.TITLE: "test",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -195,19 +177,25 @@ async def test_send_message_exception(
|
||||
[
|
||||
(
|
||||
ServiceValidationError,
|
||||
{ATTR_DELAY: {"days": 1, "seconds": 30}, ATTR_CALL: "1234567890"},
|
||||
{
|
||||
NtfyServiceArgument.DELAY: {"days": 1, "seconds": 30},
|
||||
NtfyServiceArgument.CALL: "1234567890",
|
||||
},
|
||||
"Delayed call notifications are not supported",
|
||||
),
|
||||
(
|
||||
ServiceValidationError,
|
||||
{ATTR_DELAY: {"days": 1, "seconds": 30}, ATTR_EMAIL: "mail@example.org"},
|
||||
{
|
||||
NtfyServiceArgument.DELAY: {"days": 1, "seconds": 30},
|
||||
NtfyServiceArgument.EMAIL: "mail@example.org",
|
||||
},
|
||||
"Delayed email notifications are not supported",
|
||||
),
|
||||
(
|
||||
probatio.MultipleInvalid,
|
||||
{
|
||||
ATTR_ATTACH: "https://example.com/Epic Sax Guy 10 Hours.mp4",
|
||||
ATTR_ATTACH_FILE: {
|
||||
NtfyServiceArgument.ATTACH: "https://example.com/Epic Sax Guy 10 Hours.mp4",
|
||||
NtfyServiceArgument.ATTACH_FILE: {
|
||||
"media_content_id": (
|
||||
"media-source://media_source/local/Epic Sax Guy 10 Hours.mp4"
|
||||
),
|
||||
@@ -219,14 +207,14 @@ async def test_send_message_exception(
|
||||
(
|
||||
probatio.MultipleInvalid,
|
||||
{
|
||||
ATTR_FILENAME: "Epic Sax Guy 10 Hours.mp4",
|
||||
NtfyServiceArgument.FILENAME: "Epic Sax Guy 10 Hours.mp4",
|
||||
},
|
||||
"Filename only allowed when attachment is provided",
|
||||
),
|
||||
(
|
||||
probatio.MultipleInvalid,
|
||||
{
|
||||
ATTR_ACTIONS: [
|
||||
NtfyServiceArgument.ACTIONS: [
|
||||
{"action": "broadcast", "label": "1"},
|
||||
{"action": "broadcast", "label": "2"},
|
||||
{"action": "broadcast", "label": "3"},
|
||||
@@ -237,7 +225,7 @@ async def test_send_message_exception(
|
||||
),
|
||||
(
|
||||
probatio.MultipleInvalid,
|
||||
{ATTR_ACTIONS: [{"action": "copy", "label": "Copy"}]},
|
||||
{NtfyServiceArgument.ACTIONS: [{"action": "copy", "label": "Copy"}]},
|
||||
r"required key not provided at 'actions\[0\]\.value'",
|
||||
),
|
||||
],
|
||||
@@ -261,8 +249,8 @@ async def test_send_message_validation_errors(
|
||||
with pytest.raises(exception, match=error_msg):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
{ATTR_ENTITY_ID: "notify.mytopic", **payload},
|
||||
NtfyService.PUBLISH,
|
||||
{CommonServiceArgument.ENTITY_ID: "notify.mytopic", **payload},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@@ -270,9 +258,9 @@ async def test_send_message_validation_errors(
|
||||
@pytest.mark.parametrize(
|
||||
("service", "call_method"),
|
||||
[
|
||||
(SERVICE_PUBLISH, "publish"),
|
||||
(SERVICE_CLEAR, "clear"),
|
||||
(SERVICE_DELETE, "delete"),
|
||||
(NtfyService.PUBLISH, "publish"),
|
||||
(NtfyService.CLEAR, "clear"),
|
||||
(NtfyService.DELETE, "delete"),
|
||||
],
|
||||
)
|
||||
async def test_send_message_reauth_flow(
|
||||
@@ -298,7 +286,10 @@ async def test_send_message_reauth_flow(
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: "notify.mytopic", ATTR_SEQUENCE_ID: "Mc3otamDNcpJ"},
|
||||
{
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
@@ -329,10 +320,10 @@ async def test_ntfy_publish_attachment_upload(
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_ATTACH_FILE: {
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.ATTACH_FILE: {
|
||||
"media_content_id": (
|
||||
"media-source://media_source/local/Epic Sax Guy 10 Hours.mp4"
|
||||
),
|
||||
@@ -368,14 +359,14 @@ async def test_ntfy_publish_upload_camera_snapshot(
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_ATTACH_FILE: {
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.ATTACH_FILE: {
|
||||
"media_content_id": "media-source://camera/camera.demo_camera",
|
||||
"media_content_type": "image/jpeg",
|
||||
},
|
||||
ATTR_FILENAME: "Epic Sax Guy 10 Hours.jpg",
|
||||
NtfyServiceArgument.FILENAME: "Epic Sax Guy 10 Hours.jpg",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -417,10 +408,10 @@ async def test_ntfy_publish_upload_media_source_not_supported(
|
||||
):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_ATTACH_FILE: {
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.ATTACH_FILE: {
|
||||
"media_content_id": "media-source://xbox/123456789/",
|
||||
"media_content_type": "video/mp4",
|
||||
},
|
||||
@@ -447,10 +438,10 @@ async def test_ntfy_publish_upload_media_image_source(
|
||||
) as mock_get_image:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_ATTACH_FILE: {
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.ATTACH_FILE: {
|
||||
"media_content_id": "media-source://image/image.test",
|
||||
"media_content_type": "image/png",
|
||||
},
|
||||
@@ -479,10 +470,10 @@ async def test_ntfy_publish_upload_tts_source(
|
||||
) as mock_get_media_source_audio:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_PUBLISH,
|
||||
NtfyService.PUBLISH,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_ATTACH_FILE: {
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.ATTACH_FILE: {
|
||||
"media_content_id": "media-source://tts/demo?message=Test&language=en",
|
||||
"media_content_type": "audio/mp3",
|
||||
},
|
||||
@@ -510,10 +501,10 @@ async def test_ntfy_clear(
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CLEAR,
|
||||
NtfyService.CLEAR,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -547,10 +538,10 @@ async def test_clear_exception(
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_CLEAR,
|
||||
NtfyService.CLEAR,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -573,10 +564,10 @@ async def test_ntfy_delete(
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_DELETE,
|
||||
NtfyService.DELETE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
@@ -610,10 +601,10 @@ async def test_delete_exception(
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_DELETE,
|
||||
NtfyService.DELETE,
|
||||
{
|
||||
ATTR_ENTITY_ID: "notify.mytopic",
|
||||
ATTR_SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
CommonServiceArgument.ENTITY_ID: "notify.mytopic",
|
||||
NtfyServiceArgument.SEQUENCE_ID: "Mc3otamDNcpJ",
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user