mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Added Stride notification component (#13221)
* Added Stride notification component * Fix trailing whitespace in Stride notify * More whitespace fixes and rogue comment for Stride notify * More whitespace fixing for Stride notify * Correcting hanging indents for Stride notify
This commit is contained in:
parent
b1079cb493
commit
99f7e2bd97
@ -519,6 +519,7 @@ omit =
|
|||||||
homeassistant/components/notify/sendgrid.py
|
homeassistant/components/notify/sendgrid.py
|
||||||
homeassistant/components/notify/simplepush.py
|
homeassistant/components/notify/simplepush.py
|
||||||
homeassistant/components/notify/slack.py
|
homeassistant/components/notify/slack.py
|
||||||
|
homeassistant/components/notify/stride.py
|
||||||
homeassistant/components/notify/smtp.py
|
homeassistant/components/notify/smtp.py
|
||||||
homeassistant/components/notify/synology_chat.py
|
homeassistant/components/notify/synology_chat.py
|
||||||
homeassistant/components/notify/syslog.py
|
homeassistant/components/notify/syslog.py
|
||||||
|
102
homeassistant/components/notify/stride.py
Normal file
102
homeassistant/components/notify/stride.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
"""
|
||||||
|
Stride platform for notify component.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/notify.stride/
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.components.notify import (
|
||||||
|
ATTR_TARGET, ATTR_DATA, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
|
from homeassistant.const import CONF_TOKEN, CONF_ROOM
|
||||||
|
|
||||||
|
REQUIREMENTS = ['pystride==0.1.7']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_PANEL = 'panel'
|
||||||
|
CONF_CLOUDID = 'cloudid'
|
||||||
|
|
||||||
|
DEFAULT_PANEL = None
|
||||||
|
|
||||||
|
VALID_PANELS = {'info', 'note', 'tip', 'warning', None}
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_CLOUDID): cv.string,
|
||||||
|
vol.Required(CONF_ROOM): cv.string,
|
||||||
|
vol.Required(CONF_TOKEN): cv.string,
|
||||||
|
vol.Optional(CONF_PANEL, default=DEFAULT_PANEL): vol.In(VALID_PANELS),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def get_service(hass, config, discovery_info=None):
|
||||||
|
"""Get the Stride notification service."""
|
||||||
|
return StrideNotificationService(
|
||||||
|
config[CONF_TOKEN], config[CONF_ROOM], config[CONF_PANEL],
|
||||||
|
config[CONF_CLOUDID])
|
||||||
|
|
||||||
|
|
||||||
|
class StrideNotificationService(BaseNotificationService):
|
||||||
|
"""Implement the notification service for Stride."""
|
||||||
|
|
||||||
|
def __init__(self, token, default_room, default_panel, cloudid):
|
||||||
|
"""Initialize the service."""
|
||||||
|
self._token = token
|
||||||
|
self._default_room = default_room
|
||||||
|
self._default_panel = default_panel
|
||||||
|
self._cloudid = cloudid
|
||||||
|
|
||||||
|
from stride import Stride
|
||||||
|
self._stride = Stride(self._cloudid, access_token=self._token)
|
||||||
|
|
||||||
|
def send_message(self, message="", **kwargs):
|
||||||
|
"""Send a message."""
|
||||||
|
panel = self._default_panel
|
||||||
|
|
||||||
|
if kwargs.get(ATTR_DATA) is not None:
|
||||||
|
data = kwargs.get(ATTR_DATA)
|
||||||
|
if ((data.get(CONF_PANEL) is not None)
|
||||||
|
and (data.get(CONF_PANEL) in VALID_PANELS)):
|
||||||
|
panel = data.get(CONF_PANEL)
|
||||||
|
|
||||||
|
message_text = {
|
||||||
|
'type': 'paragraph',
|
||||||
|
'content': [
|
||||||
|
{
|
||||||
|
'type': 'text',
|
||||||
|
'text': message
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
panel_text = message_text
|
||||||
|
if panel is not None:
|
||||||
|
panel_text = {
|
||||||
|
'type': 'panel',
|
||||||
|
'attrs':
|
||||||
|
{
|
||||||
|
'panelType': panel
|
||||||
|
},
|
||||||
|
'content':
|
||||||
|
[
|
||||||
|
message_text,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
message_doc = {
|
||||||
|
'body': {
|
||||||
|
'version': 1,
|
||||||
|
'type': 'doc',
|
||||||
|
'content':
|
||||||
|
[
|
||||||
|
panel_text,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
targets = kwargs.get(ATTR_TARGET, [self._default_room])
|
||||||
|
|
||||||
|
for target in targets:
|
||||||
|
self._stride.message_room(target, message_doc)
|
@ -891,6 +891,9 @@ pysma==0.2
|
|||||||
# homeassistant.components.switch.snmp
|
# homeassistant.components.switch.snmp
|
||||||
pysnmp==4.4.4
|
pysnmp==4.4.4
|
||||||
|
|
||||||
|
# homeassistant.components.notify.stride
|
||||||
|
pystride==0.1.7
|
||||||
|
|
||||||
# homeassistant.components.media_player.liveboxplaytv
|
# homeassistant.components.media_player.liveboxplaytv
|
||||||
pyteleloisirs==3.3
|
pyteleloisirs==3.3
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user