This commit is contained in:
Otto Winter
2018-09-23 18:58:41 +02:00
parent 74c70509c2
commit 2abbe1bca3
17 changed files with 653 additions and 219 deletions
+37 -1
View File
@@ -3,12 +3,13 @@
from __future__ import print_function
import logging
import os
import re
import uuid as uuid_
import voluptuous as vol
from esphomeyaml import core
from esphomeyaml import core, helpers
from esphomeyaml.const import CONF_AVAILABILITY, CONF_COMMAND_TOPIC, CONF_DISCOVERY, CONF_ID, \
CONF_NAME, CONF_PAYLOAD_AVAILABLE, \
CONF_PAYLOAD_NOT_AVAILABLE, CONF_PLATFORM, CONF_RETAIN, CONF_STATE_TOPIC, CONF_TOPIC, \
@@ -240,6 +241,19 @@ def has_exactly_one_key(*keys):
return validate
def has_at_most_one_key(*keys):
def validate(obj):
if not isinstance(obj, dict):
raise vol.Invalid('expected dictionary')
number = sum(k in keys for k in obj)
if number > 1:
raise vol.Invalid("Cannot specify more than one of {}.".format(', '.join(keys)))
return obj
return validate
TIME_PERIOD_ERROR = "Time period {} should be format number + unit, for example 5ms, 5s, 5min, 5h"
time_period_dict = vol.All(
@@ -598,6 +612,28 @@ def dimensions(value):
return dimensions([match.group(1), match.group(2)])
def directory(value):
value = string(value)
path = helpers.relative_path(value)
if not os.path.exists(path):
raise vol.Invalid(u"Could not find directory '{}'. Please make sure it exists.".format(
path))
if not os.path.isdir(path):
raise vol.Invalid(u"Path '{}' is not a directory.".format(path))
return value
def file_(value):
value = string(value)
path = helpers.relative_path(value)
if not os.path.exists(path):
raise vol.Invalid(u"Could not find file '{}'. Please make sure it exists.".format(
path))
if not os.path.isfile(path):
raise vol.Invalid(u"Path '{}' is not a file.".format(path))
return value
REGISTERED_IDS = set()