twilio component (#6348)
* twilio component * add http dependency to twilio * fire->async_fire
This commit is contained in:
parent
fbd0bf77c7
commit
b53bc24a63
5 changed files with 65 additions and 28 deletions
|
@ -85,6 +85,10 @@ omit =
|
|||
|
||||
homeassistant/components/*/thinkingcleaner.py
|
||||
|
||||
homeassistant/components/twilio.py
|
||||
homeassistant/components/notify/twilio_sms.py
|
||||
homeassistant/components/notify/twilio_call.py
|
||||
|
||||
homeassistant/components/vera.py
|
||||
homeassistant/components/*/vera.py
|
||||
|
||||
|
@ -291,8 +295,6 @@ omit =
|
|||
homeassistant/components/notify/syslog.py
|
||||
homeassistant/components/notify/telegram.py
|
||||
homeassistant/components/notify/telstra.py
|
||||
homeassistant/components/notify/twilio_sms.py
|
||||
homeassistant/components/notify/twilio_call.py
|
||||
homeassistant/components/notify/twitter.py
|
||||
homeassistant/components/notify/xmpp.py
|
||||
homeassistant/components/nuimo_controller.py
|
||||
|
|
|
@ -9,21 +9,18 @@ import urllib
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.twilio import DATA_TWILIO
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ["twilio==5.7.0"]
|
||||
DEPENDENCIES = ["twilio"]
|
||||
|
||||
|
||||
CONF_ACCOUNT_SID = "account_sid"
|
||||
CONF_AUTH_TOKEN = "auth_token"
|
||||
CONF_FROM_NUMBER = "from_number"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ACCOUNT_SID): cv.string,
|
||||
vol.Required(CONF_AUTH_TOKEN): cv.string,
|
||||
vol.Required(CONF_FROM_NUMBER):
|
||||
vol.All(cv.string, vol.Match(r"^\+?[1-9]\d{1,14}$")),
|
||||
})
|
||||
|
@ -31,13 +28,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
def get_service(hass, config, discovery_info=None):
|
||||
"""Get the Twilio Call notification service."""
|
||||
# pylint: disable=import-error
|
||||
from twilio.rest import TwilioRestClient
|
||||
|
||||
twilio_client = TwilioRestClient(config[CONF_ACCOUNT_SID],
|
||||
config[CONF_AUTH_TOKEN])
|
||||
|
||||
return TwilioCallNotificationService(twilio_client,
|
||||
return TwilioCallNotificationService(hass.data[DATA_TWILIO],
|
||||
config[CONF_FROM_NUMBER])
|
||||
|
||||
|
||||
|
|
|
@ -8,21 +8,18 @@ import logging
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.twilio import DATA_TWILIO
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
REQUIREMENTS = ["twilio==5.7.0"]
|
||||
DEPENDENCIES = ["twilio"]
|
||||
|
||||
|
||||
CONF_ACCOUNT_SID = "account_sid"
|
||||
CONF_AUTH_TOKEN = "auth_token"
|
||||
CONF_FROM_NUMBER = "from_number"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ACCOUNT_SID): cv.string,
|
||||
vol.Required(CONF_AUTH_TOKEN): cv.string,
|
||||
vol.Required(CONF_FROM_NUMBER):
|
||||
vol.All(cv.string, vol.Match(r"^\+?[1-9]\d{1,14}$")),
|
||||
})
|
||||
|
@ -30,13 +27,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
def get_service(hass, config, discovery_info=None):
|
||||
"""Get the Twilio SMS notification service."""
|
||||
# pylint: disable=import-error
|
||||
from twilio.rest import TwilioRestClient
|
||||
|
||||
twilio_client = TwilioRestClient(config[CONF_ACCOUNT_SID],
|
||||
config[CONF_AUTH_TOKEN])
|
||||
|
||||
return TwilioSMSNotificationService(twilio_client,
|
||||
return TwilioSMSNotificationService(hass.data[DATA_TWILIO],
|
||||
config[CONF_FROM_NUMBER])
|
||||
|
||||
|
||||
|
|
54
homeassistant/components/twilio.py
Normal file
54
homeassistant/components/twilio.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""
|
||||
Support for Twilio.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/twilio/
|
||||
"""
|
||||
import voluptuous as vol
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
|
||||
DEPENDENCIES = ['http']
|
||||
REQUIREMENTS = ['twilio==5.7.0']
|
||||
|
||||
DOMAIN = 'twilio'
|
||||
DATA_TWILIO = DOMAIN
|
||||
API_PATH = '/api/{}'.format(DOMAIN)
|
||||
RECEIVED_DATA = '{}_data_received'.format(DOMAIN)
|
||||
|
||||
CONF_ACCOUNT_SID = 'account_sid'
|
||||
CONF_AUTH_TOKEN = 'auth_token'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_ACCOUNT_SID): cv.string,
|
||||
vol.Required(CONF_AUTH_TOKEN): cv.string
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
"""Set up the Twilio component."""
|
||||
from twilio.rest import TwilioRestClient
|
||||
conf = config[DOMAIN]
|
||||
hass.data[DATA_TWILIO] = TwilioRestClient(conf.get(CONF_ACCOUNT_SID),
|
||||
conf.get(CONF_AUTH_TOKEN))
|
||||
hass.http.register_view(TwilioReceiveDataView())
|
||||
return True
|
||||
|
||||
|
||||
class TwilioReceiveDataView(HomeAssistantView):
|
||||
"""Handle data from Twilio inbound messages and calls."""
|
||||
|
||||
url = API_PATH
|
||||
name = 'api:{}'.format(DOMAIN)
|
||||
|
||||
@callback
|
||||
def post(self, request): # pylint: disable=no-self-use
|
||||
"""Handle Twilio data post."""
|
||||
from twilio.twiml import Response
|
||||
hass = request.app['hass']
|
||||
data = yield from request.post()
|
||||
hass.bus.async_fire(RECEIVED_DATA, dict(data))
|
||||
return Response().toxml()
|
|
@ -717,8 +717,7 @@ tikteck==0.4
|
|||
# homeassistant.components.switch.transmission
|
||||
transmissionrpc==0.11
|
||||
|
||||
# homeassistant.components.notify.twilio_call
|
||||
# homeassistant.components.notify.twilio_sms
|
||||
# homeassistant.components.twilio
|
||||
twilio==5.7.0
|
||||
|
||||
# homeassistant.components.sensor.uber
|
||||
|
|
Loading…
Add table
Reference in a new issue