-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnotify.py
55 lines (44 loc) · 1.58 KB
/
notify.py
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
import logging
import voluptuous as vol
from homeassistant.const import ATTR_LOCATION
from homeassistant.components.notify import (
ATTR_DATA,
ATTR_MESSAGE,
ATTR_TARGET,
ATTR_TITLE,
PLATFORM_SCHEMA,
BaseNotificationService,
)
from .const import (
DOMAIN,
ATTR_PHOTO,
)
_LOGGER = logging.getLogger(__name__)
def get_service(hass, config, discovery_info=None):
"""Get the KakaoTalk notification service."""
return KakaoTalkNotificationService(hass)
class KakaoTalkNotificationService(BaseNotificationService):
def __init__(self, hass):
"""Initialize the service."""
self.hass = hass
def send_message(self, message="", **kwargs):
service_data = {}
if ATTR_TITLE in kwargs:
service_data.update({ATTR_TITLE: kwargs.get(ATTR_TITLE)})
if message:
service_data.update({ATTR_MESSAGE: message})
data = kwargs.get(ATTR_DATA)
if data is not None and ATTR_PHOTO in data:
photos = data.get(ATTR_PHOTO, None)
photos = photos if isinstance(photos, list) else [photos]
for photo_data in photos:
service_data.update(photo_data)
self.hass.services.call(DOMAIN, "send_message", service_data=service_data)
return
# Send message
_LOGGER.debug(
"KAKAOTALK NOTIFIER calling %s.send_message with %s", DOMAIN, service_data
)
return self.hass.services.call(
DOMAIN, "send_message", service_data=service_data
)