1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
"""Example scripts for sending notifications."""
import asyncio
import logging
from notifications_android_tv import ConnectError, Notifications
from notifications_android_tv.exceptions import NotificationException
from notifications_android_tv.notifier import NotificationParams
_LOGGER = logging.getLogger(__name__)
HOST = "<host>"
ICON = "<icon path or url>"
IMAGE = "<image path or url>"
async def main() -> None:
"""Run the example script."""
notifier = Notifications(HOST)
# validate connection
try:
await notifier.async_connect()
except ConnectError as err:
_LOGGER.error(err)
return
# # Send a basic notification with message only
await notifier.async_send("This is a simple notification message")
# For constructing paramters from string values as documented
# in Home Assistant https://www.home-assistant.io/integrations/nfandroidtv
try:
notification_params = NotificationParams.from_dict(
{
"duration": "10",
"color": "red",
"fontsize": "small",
"position": "bottom-right",
"transparency": "25%",
"interrupt": 0,
"icon": {"path": ICON},
"image": {"url": IMAGE},
}
)
except ValueError as err:
_LOGGER.error(err)
return
try:
await notifier.async_send(
"This is a notification message",
title="Notification Title",
params=notification_params,
)
except NotificationException as err:
_LOGGER.error(err)
if __name__ == "__main__":
asyncio.run(main())
|