Some fixes for yr config validation. (#1809)

The setup_platform function is trying to get CONF_LATITUDE and CONF_LONGITUDE,
but the validation schema was not accepting these.

Also moved CONF_MONITORED_CONDITIONS and CONF_ELEVATION to homeassistant.const
because they are used in other places.
This commit is contained in:
Jan Harkes 2016-04-12 00:44:39 -04:00 committed by Paulus Schoutsen
parent 241735c924
commit 656e187729
3 changed files with 12 additions and 8 deletions

View file

@ -9,7 +9,10 @@ import requests
import voluptuous as vol import voluptuous as vol
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE from homeassistant.const import (
CONF_PLATFORM, CONF_LATITUDE, CONF_LONGITUDE, CONF_ELEVATION,
CONF_MONITORED_CONDITIONS
)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from homeassistant.util import location from homeassistant.util import location
@ -19,8 +22,6 @@ _LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['xmltodict'] REQUIREMENTS = ['xmltodict']
CONF_MONITORED_CONDITIONS = 'monitored_conditions'
# Sensor types are defined like so: # Sensor types are defined like so:
SENSOR_TYPES = { SENSOR_TYPES = {
'symbol': ['Symbol', None], 'symbol': ['Symbol', None],
@ -40,10 +41,12 @@ SENSOR_TYPES = {
} }
PLATFORM_SCHEMA = vol.Schema({ PLATFORM_SCHEMA = vol.Schema({
vol.Required('platform'): 'yr', vol.Required(CONF_PLATFORM): 'yr',
vol.Optional(CONF_MONITORED_CONDITIONS, default=[]): vol.Optional(CONF_MONITORED_CONDITIONS, default=[]):
[vol.In(SENSOR_TYPES.keys())], [vol.In(SENSOR_TYPES.keys())],
vol.Optional('elevation'): cv.positive_int, vol.Optional(CONF_LATITUDE): cv.latitude,
vol.Optional(CONF_LONGITUDE): cv.longitude,
vol.Optional(CONF_ELEVATION): cv.positive_int,
}) })
@ -51,7 +54,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Yr.no sensor.""" """Setup the Yr.no sensor."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
elevation = config.get('elevation') elevation = config.get(CONF_ELEVATION)
if None in (latitude, longitude): if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config") _LOGGER.error("Latitude or longitude not set in Home Assistant config")

View file

@ -13,13 +13,12 @@ from homeassistant.helpers.event import (
track_point_in_utc_time, track_utc_time_change) track_point_in_utc_time, track_utc_time_change)
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from homeassistant.util import location as location_util from homeassistant.util import location as location_util
from homeassistant.const import CONF_ELEVATION
REQUIREMENTS = ['astral==1.0'] REQUIREMENTS = ['astral==1.0']
DOMAIN = "sun" DOMAIN = "sun"
ENTITY_ID = "sun.sun" ENTITY_ID = "sun.sun"
CONF_ELEVATION = 'elevation'
STATE_ABOVE_HORIZON = "above_horizon" STATE_ABOVE_HORIZON = "above_horizon"
STATE_BELOW_HORIZON = "below_horizon" STATE_BELOW_HORIZON = "below_horizon"

View file

@ -16,6 +16,7 @@ DEVICE_DEFAULT_NAME = "Unnamed Device"
CONF_ICON = "icon" CONF_ICON = "icon"
CONF_LATITUDE = "latitude" CONF_LATITUDE = "latitude"
CONF_LONGITUDE = "longitude" CONF_LONGITUDE = "longitude"
CONF_ELEVATION = "elevation"
CONF_TEMPERATURE_UNIT = "temperature_unit" CONF_TEMPERATURE_UNIT = "temperature_unit"
CONF_NAME = "name" CONF_NAME = "name"
CONF_TIME_ZONE = "time_zone" CONF_TIME_ZONE = "time_zone"
@ -30,6 +31,7 @@ CONF_PASSWORD = "password"
CONF_API_KEY = "api_key" CONF_API_KEY = "api_key"
CONF_ACCESS_TOKEN = "access_token" CONF_ACCESS_TOKEN = "access_token"
CONF_FILENAME = "filename" CONF_FILENAME = "filename"
CONF_MONITORED_CONDITIONS = 'monitored_conditions'
CONF_OPTIMISTIC = 'optimistic' CONF_OPTIMISTIC = 'optimistic'
CONF_SCAN_INTERVAL = "scan_interval" CONF_SCAN_INTERVAL = "scan_interval"
CONF_VALUE_TEMPLATE = "value_template" CONF_VALUE_TEMPLATE = "value_template"