Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Signal Messenger integration #28537

Merged
merged 19 commits into from Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Expand Up @@ -600,6 +600,8 @@ omit =
homeassistant/components/shodan/sensor.py
homeassistant/components/sht31/sensor.py
homeassistant/components/sigfox/sensor.py
homeassistant/components/signalmessenger/__init__.py
homeassistant/components/signalmessenger/notify.py
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
homeassistant/components/simplepush/notify.py
homeassistant/components/simplisafe/__init__.py
homeassistant/components/simplisafe/alarm_control_panel.py
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -260,6 +260,7 @@ homeassistant/components/seventeentrack/* @bachya
homeassistant/components/shell_command/* @home-assistant/core
homeassistant/components/shiftr/* @fabaff
homeassistant/components/shodan/* @fabaff
homeassistant/components/signal_messenger/* @bbernhard
homeassistant/components/simplisafe/* @bachya
homeassistant/components/sinch/* @bendikrb
homeassistant/components/slide/* @ualex73
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/signal_messenger/__init__.py
@@ -0,0 +1 @@
"""The signalmessenger component."""
10 changes: 10 additions & 0 deletions homeassistant/components/signal_messenger/manifest.json
@@ -0,0 +1,10 @@
{
"domain": "signal_messenger",
"name": "signal_messenger",
"documentation": "https://www.home-assistant.io/integrations/signal_messenger",
"dependencies": [],
"codeowners": ["@bbernhard"],
"requirements": [
"pysignalclirestapi==0.1.4"
]
}
71 changes: 71 additions & 0 deletions homeassistant/components/signal_messenger/notify.py
@@ -0,0 +1,71 @@
"""Signal Messenger for notify component."""
import logging

from pysignalclirestapi import SignalCliRestApi, SignalCliRestApiError
import voluptuous as vol

from homeassistant.components.notify import (
ATTR_DATA,
PLATFORM_SCHEMA,
BaseNotificationService,
)
import homeassistant.helpers.config_validation as cv

_LOGGER = logging.getLogger(__name__)

CONF_SENDER_NR = "number"
CONF_RECP_NR = "recipients"
CONF_SIGNAL_CLI_REST_API = "url"
ATTR_FILENAME = "attachment"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_SENDER_NR): cv.string,
vol.Required(CONF_SIGNAL_CLI_REST_API): cv.string,
vol.Required(CONF_RECP_NR): vol.All(cv.ensure_list, [cv.string]),
}
)


def get_service(hass, config, discovery_info=None):
"""Get the SignalMessenger notification service."""

sender_nr = config[CONF_SENDER_NR]
recp_nrs = config[CONF_RECP_NR]
signal_cli_rest_api_url = config[CONF_SIGNAL_CLI_REST_API]

signal_cli_rest_api = SignalCliRestApi(
signal_cli_rest_api_url, sender_nr, api_version=1
)

return SignalNotificationService(recp_nrs, signal_cli_rest_api)


class SignalNotificationService(BaseNotificationService):
"""Implement the notification service for SignalMessenger."""

def __init__(self, recp_nrs, signal_cli_rest_api):
"""Initialize the service."""

self._recp_nrs = recp_nrs
self._signal_cli_rest_api = signal_cli_rest_api

def send_message(self, message="", **kwargs):
"""Send a message to a one or more recipients.

Additionally a file can be attached.
"""

_LOGGER.debug("Sending signal message")

data = kwargs.get(ATTR_DATA)

filename = None
if data is not None and ATTR_FILENAME in data:
filename = data[ATTR_FILENAME]

try:
self._signal_cli_rest_api.send_message(message, self._recp_nrs, filename)
except SignalCliRestApiError as ex:
_LOGGER.error("%s", ex)
raise ex
3 changes: 3 additions & 0 deletions requirements_all.txt
Expand Up @@ -1446,6 +1446,9 @@ pysesame2==1.0.1
# homeassistant.components.goalfeed
pysher==1.0.1

# homeassistant.components.signal_messenger
pysignalclirestapi==0.1.4

# homeassistant.components.sma
pysma==0.3.4

Expand Down