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

Use voluptuous for Foursquare #3106

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Changes from all 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
53 changes: 31 additions & 22 deletions homeassistant/components/foursquare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,51 @@
import logging
import os
import json
import requests

import requests
import voluptuous as vol

from homeassistant.const import CONF_ACCESS_TOKEN
from homeassistant.config import load_yaml_config_file
import homeassistant.helpers.config_validation as cv
from homeassistant.components.http import HomeAssistantView

DOMAIN = "foursquare"
_LOGGER = logging.getLogger(__name__)

CONF_PUSH_SECRET = 'push_secret'

SERVICE_CHECKIN = "checkin"
DEPENDENCIES = ['http']
DOMAIN = 'foursquare'

EVENT_PUSH = "foursquare.push"
EVENT_CHECKIN = "foursquare.checkin"
EVENT_CHECKIN = 'foursquare.checkin'
EVENT_PUSH = 'foursquare.push'

SERVICE_CHECKIN = 'checkin'

CHECKIN_SERVICE_SCHEMA = vol.Schema({
vol.Required("venueId"): cv.string,
vol.Optional("eventId"): cv.string,
vol.Optional("shout"): cv.string,
vol.Optional("mentions"): cv.string,
vol.Optional("broadcast"): cv.string,
vol.Optional("ll"): cv.string,
vol.Optional("llAcc"): cv.string,
vol.Optional("alt"): cv.string,
vol.Optional("altAcc"): cv.string,
vol.Optional('alt'): cv.string,
vol.Optional('altAcc'): cv.string,
vol.Optional('broadcast'): cv.string,
vol.Optional('eventId'): cv.string,
vol.Optional('ll'): cv.string,
vol.Optional('llAcc'): cv.string,
vol.Optional('mentions'): cv.string,
vol.Optional('shout'): cv.string,
vol.Required('venueId'): cv.string,
})

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ["http"]
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Required(CONF_PUSH_SECRET): cv.string,
}),
}, extra=vol.ALLOW_EXTRA)


def setup(hass, config):
"""Setup the Foursquare component."""
descriptions = load_yaml_config_file(
os.path.join(os.path.dirname(__file__), "services.yaml"))
os.path.join(os.path.dirname(__file__), 'services.yaml'))

config = config[DOMAIN]

Expand All @@ -51,7 +60,7 @@ def checkin_user(call):
url = ("https://api.foursquare.com/v2/checkins/add"
"?oauth_token={}"
"&v=20160802"
"&m=swarm").format(config["access_token"])
"&m=swarm").format(config[CONF_ACCESS_TOKEN])
response = requests.post(url, data=call.data, timeout=10)

if response.status_code not in (200, 201):
Expand All @@ -62,12 +71,12 @@ def checkin_user(call):
hass.bus.fire(EVENT_CHECKIN, response.text)

# Register our service with Home Assistant.
hass.services.register(DOMAIN, "checkin", checkin_user,
hass.services.register(DOMAIN, 'checkin', checkin_user,
descriptions[DOMAIN][SERVICE_CHECKIN],
schema=CHECKIN_SERVICE_SCHEMA)

hass.wsgi.register_view(FoursquarePushReceiver(hass,
config["push_secret"]))
hass.wsgi.register_view(FoursquarePushReceiver(
hass, config[CONF_PUSH_SECRET]))

return True

Expand Down