mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add voluptuous to ecobee, speedtest.net, fast.com, actiontec, forecast.io (#2872)
* add voluptuous * fixes for comments * str to cv.string
This commit is contained in:
parent
fa3d83118a
commit
635e5c8eba
@ -10,11 +10,12 @@ import telnetlib
|
|||||||
import threading
|
import threading
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.components.device_tracker import DOMAIN
|
from homeassistant.components.device_tracker import (DOMAIN, PLATFORM_SCHEMA)
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.helpers import validate_config
|
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago.
|
# Return cached results if last scan was less then this time ago.
|
||||||
@ -28,14 +29,16 @@ _LEASES_REGEX = re.compile(
|
|||||||
r'\svalid\sfor:\s(?P<timevalid>(-?\d+))' +
|
r'\svalid\sfor:\s(?P<timevalid>(-?\d+))' +
|
||||||
r'\ssec')
|
r'\ssec')
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
vol.Required(CONF_USERNAME): cv.string
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def get_scanner(hass, config):
|
def get_scanner(hass, config):
|
||||||
"""Validate the configuration and return an Actiontec scanner."""
|
"""Validate the configuration and return an Actiontec scanner."""
|
||||||
if not validate_config(config,
|
|
||||||
{DOMAIN: [CONF_HOST, CONF_USERNAME, CONF_PASSWORD]},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
scanner = ActiontecDeviceScanner(config[DOMAIN])
|
scanner = ActiontecDeviceScanner(config[DOMAIN])
|
||||||
return scanner if scanner.success_init else None
|
return scanner if scanner.success_init else None
|
||||||
|
|
||||||
|
@ -7,7 +7,9 @@ https://home-assistant.io/components/ecobee/
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
@ -15,12 +17,19 @@ from homeassistant.util import Throttle
|
|||||||
|
|
||||||
DOMAIN = "ecobee"
|
DOMAIN = "ecobee"
|
||||||
NETWORK = None
|
NETWORK = None
|
||||||
HOLD_TEMP = 'hold_temp'
|
CONF_HOLD_TEMP = 'hold_temp'
|
||||||
|
|
||||||
REQUIREMENTS = [
|
REQUIREMENTS = [
|
||||||
'https://github.com/nkgilley/python-ecobee-api/archive/'
|
'https://github.com/nkgilley/python-ecobee-api/archive/'
|
||||||
'4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6']
|
'4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6']
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
|
DOMAIN: vol.Schema({
|
||||||
|
vol.Optional(CONF_API_KEY): cv.string,
|
||||||
|
vol.Optional(CONF_HOLD_TEMP, default=False): cv.boolean
|
||||||
|
})
|
||||||
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
ECOBEE_CONFIG_FILE = 'ecobee.conf'
|
||||||
@ -67,7 +76,7 @@ def setup_ecobee(hass, network, config):
|
|||||||
configurator = get_component('configurator')
|
configurator = get_component('configurator')
|
||||||
configurator.request_done(_CONFIGURING.pop('ecobee'))
|
configurator.request_done(_CONFIGURING.pop('ecobee'))
|
||||||
|
|
||||||
hold_temp = config[DOMAIN].get(HOLD_TEMP, False)
|
hold_temp = config[DOMAIN].get(CONF_HOLD_TEMP)
|
||||||
|
|
||||||
discovery.load_platform(hass, 'climate', DOMAIN,
|
discovery.load_platform(hass, 'climate', DOMAIN,
|
||||||
{'hold_temp': hold_temp}, config)
|
{'hold_temp': hold_temp}, config)
|
||||||
|
@ -5,10 +5,12 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/sensor.fastdotcom/
|
https://home-assistant.io/components/sensor.fastdotcom/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components import recorder
|
from homeassistant.components import recorder
|
||||||
from homeassistant.components.sensor import DOMAIN
|
from homeassistant.components.sensor import (DOMAIN, PLATFORM_SCHEMA)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.event import track_time_change
|
from homeassistant.helpers.event import track_time_change
|
||||||
|
|
||||||
@ -22,6 +24,17 @@ CONF_MINUTE = 'minute'
|
|||||||
CONF_HOUR = 'hour'
|
CONF_HOUR = 'hour'
|
||||||
CONF_DAY = 'day'
|
CONF_DAY = 'day'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Optional(CONF_SECOND, default=[0]):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(0, 59))]),
|
||||||
|
vol.Optional(CONF_MINUTE, default=[0]):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(0, 59))]),
|
||||||
|
vol.Optional(CONF_HOUR):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(0, 23))]),
|
||||||
|
vol.Optional(CONF_DAY):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(1, 31))]),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Fast.com sensor."""
|
"""Setup the Fast.com sensor."""
|
||||||
@ -43,10 +56,10 @@ class SpeedtestSensor(Entity):
|
|||||||
|
|
||||||
def __init__(self, speedtest_data):
|
def __init__(self, speedtest_data):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._name = 'Fast.com Speedtest'
|
self._name = 'Fast.com Download'
|
||||||
self.speedtest_client = speedtest_data
|
self.speedtest_client = speedtest_data
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unit_of_measurement = 'Mbps'
|
self._unit_of_measurement = 'Mbit/s'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -94,10 +107,10 @@ class SpeedtestData(object):
|
|||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.data = None
|
self.data = None
|
||||||
track_time_change(hass, self.update,
|
track_time_change(hass, self.update,
|
||||||
second=config.get(CONF_SECOND, 0),
|
second=config.get(CONF_SECOND),
|
||||||
minute=config.get(CONF_MINUTE, 0),
|
minute=config.get(CONF_MINUTE),
|
||||||
hour=config.get(CONF_HOUR, None),
|
hour=config.get(CONF_HOUR),
|
||||||
day=config.get(CONF_DAY, None))
|
day=config.get(CONF_DAY))
|
||||||
|
|
||||||
def update(self, now):
|
def update(self, now):
|
||||||
"""Get the latest data from fast.com."""
|
"""Get the latest data from fast.com."""
|
||||||
|
@ -6,12 +6,14 @@ https://home-assistant.io/components/sensor.forecast/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import voluptuous as vol
|
||||||
from requests.exceptions import ConnectionError as ConnectError, \
|
from requests.exceptions import ConnectionError as ConnectError, \
|
||||||
HTTPError, Timeout
|
HTTPError, Timeout
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.const import (CONF_API_KEY, CONF_NAME,
|
||||||
|
CONF_MONITORED_CONDITIONS)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
@ -56,6 +58,16 @@ SENSOR_TYPES = {
|
|||||||
'mm', 'in', 'mm', 'mm', 'mm'],
|
'mm', 'in', 'mm', 'mm', 'mm'],
|
||||||
}
|
}
|
||||||
DEFAULT_NAME = "Forecast.io"
|
DEFAULT_NAME = "Forecast.io"
|
||||||
|
CONF_UNITS = 'units'
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_MONITORED_CONDITIONS):
|
||||||
|
vol.All(cv.ensure_list, [vol.In(list(SENSOR_TYPES))]),
|
||||||
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
|
vol.Optional(CONF_UNITS): vol.In(['auto', 'si', 'us', 'ca', 'uk', 'uk2'])
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago.
|
# Return cached results if last scan was less then this time ago.
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
|
||||||
@ -67,12 +79,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if None in (hass.config.latitude, hass.config.longitude):
|
if None in (hass.config.latitude, hass.config.longitude):
|
||||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
||||||
return False
|
return False
|
||||||
elif not validate_config({DOMAIN: config},
|
|
||||||
{DOMAIN: [CONF_API_KEY]}, _LOGGER):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if 'units' in config:
|
if CONF_UNITS in config:
|
||||||
units = config['units']
|
units = config[CONF_UNITS]
|
||||||
elif hass.config.units.is_metric:
|
elif hass.config.units.is_metric:
|
||||||
units = 'si'
|
units = 'si'
|
||||||
else:
|
else:
|
||||||
@ -89,15 +98,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
_LOGGER.error(error)
|
_LOGGER.error(error)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
name = config.get('name', DEFAULT_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
# Initialize and add all of the sensors.
|
# Initialize and add all of the sensors.
|
||||||
sensors = []
|
sensors = []
|
||||||
for variable in config['monitored_conditions']:
|
for variable in config[CONF_MONITORED_CONDITIONS]:
|
||||||
if variable in SENSOR_TYPES:
|
sensors.append(ForeCastSensor(forecast_data, variable, name))
|
||||||
sensors.append(ForeCastSensor(forecast_data, variable, name))
|
|
||||||
else:
|
|
||||||
_LOGGER.error('Sensor type: "%s" does not exist', variable)
|
|
||||||
|
|
||||||
add_devices(sensors)
|
add_devices(sensors)
|
||||||
|
|
||||||
|
@ -8,10 +8,13 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from subprocess import check_output, CalledProcessError
|
from subprocess import check_output, CalledProcessError
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components import recorder
|
from homeassistant.components import recorder
|
||||||
from homeassistant.components.sensor import DOMAIN
|
from homeassistant.components.sensor import (DOMAIN, PLATFORM_SCHEMA)
|
||||||
|
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.event import track_time_change
|
from homeassistant.helpers.event import track_time_change
|
||||||
|
|
||||||
@ -22,7 +25,6 @@ _SPEEDTEST_REGEX = re.compile(r'Ping:\s(\d+\.\d+)\sms[\r\n]+'
|
|||||||
r'Download:\s(\d+\.\d+)\sMbit/s[\r\n]+'
|
r'Download:\s(\d+\.\d+)\sMbit/s[\r\n]+'
|
||||||
r'Upload:\s(\d+\.\d+)\sMbit/s[\r\n]+')
|
r'Upload:\s(\d+\.\d+)\sMbit/s[\r\n]+')
|
||||||
|
|
||||||
CONF_MONITORED_CONDITIONS = 'monitored_conditions'
|
|
||||||
CONF_SECOND = 'second'
|
CONF_SECOND = 'second'
|
||||||
CONF_MINUTE = 'minute'
|
CONF_MINUTE = 'minute'
|
||||||
CONF_HOUR = 'hour'
|
CONF_HOUR = 'hour'
|
||||||
@ -33,6 +35,19 @@ SENSOR_TYPES = {
|
|||||||
'upload': ['Upload', 'Mbit/s'],
|
'upload': ['Upload', 'Mbit/s'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_MONITORED_CONDITIONS):
|
||||||
|
vol.All(cv.ensure_list, [vol.In(list(SENSOR_TYPES.keys()))]),
|
||||||
|
vol.Optional(CONF_SECOND, default=[0]):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(0, 59))]),
|
||||||
|
vol.Optional(CONF_MINUTE, default=[0]):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(0, 59))]),
|
||||||
|
vol.Optional(CONF_HOUR):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(0, 23))]),
|
||||||
|
vol.Optional(CONF_DAY):
|
||||||
|
vol.All(cv.ensure_list, [vol.All(vol.Coerce(int), vol.Range(1, 31))]),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Speedtest sensor."""
|
"""Setup the Speedtest sensor."""
|
||||||
@ -117,10 +132,10 @@ class SpeedtestData(object):
|
|||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.data = None
|
self.data = None
|
||||||
track_time_change(hass, self.update,
|
track_time_change(hass, self.update,
|
||||||
second=config.get(CONF_SECOND, 0),
|
second=config.get(CONF_SECOND),
|
||||||
minute=config.get(CONF_MINUTE, 0),
|
minute=config.get(CONF_MINUTE),
|
||||||
hour=config.get(CONF_HOUR, None),
|
hour=config.get(CONF_HOUR),
|
||||||
day=config.get(CONF_DAY, None))
|
day=config.get(CONF_DAY))
|
||||||
|
|
||||||
def update(self, now):
|
def update(self, now):
|
||||||
"""Get the latest data from speedtest.net."""
|
"""Get the latest data from speedtest.net."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user