diff --git a/.coveragerc b/.coveragerc index e4b73df1a8f..3529e7413ca 100644 --- a/.coveragerc +++ b/.coveragerc @@ -377,6 +377,7 @@ omit = homeassistant/components/fan/xiaomi_miio.py homeassistant/components/feedreader.py homeassistant/components/foursquare.py + homeassistant/components/goalfeed.py homeassistant/components/ifttt.py homeassistant/components/image_processing/dlib_face_detect.py homeassistant/components/image_processing/dlib_face_identify.py diff --git a/homeassistant/components/goalfeed.py b/homeassistant/components/goalfeed.py new file mode 100644 index 00000000000..d31a0b5b51a --- /dev/null +++ b/homeassistant/components/goalfeed.py @@ -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 diff --git a/requirements_all.txt b/requirements_all.txt index 9b4d6ba5461..0528871c05b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -851,6 +851,9 @@ pyserial==3.1.1 # homeassistant.components.lock.sesame pysesame==0.1.0 +# homeassistant.components.goalfeed +pysher==0.2.0 + # homeassistant.components.sensor.sma pysma==0.1.3