mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
Add Goalfeed platform (#11098)
* add goalfeed * use pysher. begin auth * auth! * update params * cleanup * update library and gen requirements * unused imports * case-sensitive * crazy train * docstrings and some other fixes * remove logging * unused imports * import in setup * move import * Update based on notes * add timeout * It's only a component * Update docstrings
This commit is contained in:
parent
3c869c6ed6
commit
62d4f23833
@ -377,6 +377,7 @@ omit =
|
|||||||
homeassistant/components/fan/xiaomi_miio.py
|
homeassistant/components/fan/xiaomi_miio.py
|
||||||
homeassistant/components/feedreader.py
|
homeassistant/components/feedreader.py
|
||||||
homeassistant/components/foursquare.py
|
homeassistant/components/foursquare.py
|
||||||
|
homeassistant/components/goalfeed.py
|
||||||
homeassistant/components/ifttt.py
|
homeassistant/components/ifttt.py
|
||||||
homeassistant/components/image_processing/dlib_face_detect.py
|
homeassistant/components/image_processing/dlib_face_detect.py
|
||||||
homeassistant/components/image_processing/dlib_face_identify.py
|
homeassistant/components/image_processing/dlib_face_identify.py
|
||||||
|
62
homeassistant/components/goalfeed.py
Normal file
62
homeassistant/components/goalfeed.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
"""
|
||||||
|
Component for the Goalfeed service.
|
||||||
|
|
||||||
|
For more details about this platform, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/goalfeed/
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
|
|
||||||
|
REQUIREMENTS = ['pysher==0.2.0']
|
||||||
|
|
||||||
|
DOMAIN = 'goalfeed'
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
|
DOMAIN: vol.Schema({
|
||||||
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
})
|
||||||
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
GOALFEED_HOST = 'feed.goalfeed.ca'
|
||||||
|
GOALFEED_AUTH_ENDPOINT = 'https://goalfeed.ca/feed/auth'
|
||||||
|
GOALFEED_APP_ID = 'bfd4ed98c1ff22c04074'
|
||||||
|
|
||||||
|
|
||||||
|
def setup(hass, config):
|
||||||
|
"""Set up the Goalfeed component."""
|
||||||
|
import pysher
|
||||||
|
conf = config[DOMAIN]
|
||||||
|
username = conf.get(CONF_USERNAME)
|
||||||
|
password = conf.get(CONF_PASSWORD)
|
||||||
|
|
||||||
|
def goal_handler(data):
|
||||||
|
"""Handle goal events."""
|
||||||
|
goal = json.loads(json.loads(data))
|
||||||
|
|
||||||
|
hass.bus.fire('goal', event_data=goal)
|
||||||
|
|
||||||
|
def connect_handler(data):
|
||||||
|
"""Handle connection."""
|
||||||
|
post_data = {
|
||||||
|
'username': username,
|
||||||
|
'password': password,
|
||||||
|
'connection_info': data}
|
||||||
|
resp = requests.post(GOALFEED_AUTH_ENDPOINT, post_data,
|
||||||
|
timeout=30).json()
|
||||||
|
|
||||||
|
channel = pusher.subscribe('private-goals', resp['auth'])
|
||||||
|
channel.bind('goalfeed_goal', goal_handler)
|
||||||
|
|
||||||
|
pusher = pysher.Pusher(GOALFEED_APP_ID, secure=False, port=8080,
|
||||||
|
custom_host=GOALFEED_HOST, timeout=30)
|
||||||
|
|
||||||
|
pusher.connection.bind('pusher:connection_established', connect_handler)
|
||||||
|
pusher.connect()
|
||||||
|
|
||||||
|
return True
|
@ -851,6 +851,9 @@ pyserial==3.1.1
|
|||||||
# homeassistant.components.lock.sesame
|
# homeassistant.components.lock.sesame
|
||||||
pysesame==0.1.0
|
pysesame==0.1.0
|
||||||
|
|
||||||
|
# homeassistant.components.goalfeed
|
||||||
|
pysher==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.sma
|
# homeassistant.components.sensor.sma
|
||||||
pysma==0.1.3
|
pysma==0.1.3
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user