Use voluptuous for time/date sensors (#2799)

* Use voluptuous for time/date sensors

* Extend platform

* Remove additional checks
This commit is contained in:
Fabian Affolter authored and GitHub committed 2016-08-16 21:43:56 +02:00
1 parent 1c140de0dc
commit dab5a78f88
3 files changed
+35 -25

No files matched your search

+18 -10
View File
@@ -5,12 +5,18 @@ For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.time_date/
"""
import logging
from datetime import timedelta
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_DISPLAY_OPTIONS
import homeassistant.util.dt as dt_util
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv
TIME_STR_FORMAT = "%H:%M"
_LOGGER = logging.getLogger(__name__)
OPTION_TYPES = {
'time': 'Time',
'date': 'Date',
@@ -20,7 +26,12 @@ OPTION_TYPES = {
'time_utc': 'Time (UTC)',
}
TIME_STR_FORMAT = "%H:%M"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_DISPLAY_OPTIONS, default=['time']):
vol.All(cv.ensure_list, [vol.In(OPTION_TYPES)]),
})
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None):
@@ -29,14 +40,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error("Timezone is not set in Home Assistant config")
return False
dev = []
for variable in config['display_options']:
if variable not in OPTION_TYPES:
_LOGGER.error('Option type: "%s" does not exist', variable)
else:
dev.append(TimeDateSensor(variable))
devices = []
for variable in config[CONF_DISPLAY_OPTIONS]:
devices.append(TimeDateSensor(variable))
add_devices(dev)
add_devices(devices)
# pylint: disable=too-few-public-methods