Add Signal Messenger integration (#28537)

* added signalmessenger integration

* allows to send a message (with an attachment) to one or more
  recipients

* added signalmessenger documentation to manifest file

* remove debug logging from signalmessenger integration

* add signalmessenger to .coveragerc

* fixed typo in signalmessenger manifes

* moved service specific code to own pypi library

* updated pysignalclirestapi dependeny in manifest.json

* added pysignalclirestapi requirement for signalmessenger component

* fixed typo in codeowners

* reworked signalmessenger integration based on code review input

* updated requirements for signalmessenger

* small code improvements in signalmessenger integration

* no need to use the get() method to access dict parameters that are
required

* small changes in signalmessenger integration

* re-ordered import statements
* removed empty "requirements" list (not needed)

* changed import order in signalmessenger integration according to PEP 8

* used isort to order includes in signalmessenger integration

* renamed signalmessenger to signal_messenger

* renamed signalmessenger to signal_messenger in CODEOWNERS file

* changed documentation url in signal_messenger integration to new name

* changed signal messenger naming in .coveragerc
This commit is contained in:
Bernhard B 2019-12-09 00:27:06 +01:00 committed by Martin Hjelmare
parent e577f047f7
commit d451e54e34
6 changed files with 88 additions and 0 deletions

View file

@ -611,6 +611,8 @@ omit =
homeassistant/components/shodan/sensor.py
homeassistant/components/sht31/sensor.py
homeassistant/components/sigfox/sensor.py
homeassistant/components/signal_messenger/__init__.py
homeassistant/components/signal_messenger/notify.py
homeassistant/components/simplepush/notify.py
homeassistant/components/simplisafe/__init__.py
homeassistant/components/simplisafe/alarm_control_panel.py

View file

@ -281,6 +281,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

View file

@ -0,0 +1 @@
"""The signalmessenger component."""

View file

@ -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"
]
}

View file

@ -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

View file

@ -1482,6 +1482,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