mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
Multi Conf
This commit is contained in:
parent
4e5677f5dd
commit
fb1013e885
@ -9,7 +9,7 @@ import random
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from esphomeyaml import const, core, core_config, mqtt, platformio_api, wizard, writer, yaml_util
|
from esphomeyaml import const, core, core_config, mqtt, platformio_api, wizard, writer, yaml_util
|
||||||
from esphomeyaml.config import get_component, iter_components, read_config
|
from esphomeyaml.config import get_component, iter_components, read_config, strip_default_ids
|
||||||
from esphomeyaml.const import CONF_BAUD_RATE, CONF_DOMAIN, CONF_ESPHOMEYAML, \
|
from esphomeyaml.const import CONF_BAUD_RATE, CONF_DOMAIN, CONF_ESPHOMEYAML, \
|
||||||
CONF_HOSTNAME, CONF_LOGGER, CONF_MANUAL_IP, CONF_NAME, CONF_STATIC_IP, CONF_USE_CUSTOM_CODE, \
|
CONF_HOSTNAME, CONF_LOGGER, CONF_MANUAL_IP, CONF_NAME, CONF_STATIC_IP, CONF_USE_CUSTOM_CODE, \
|
||||||
CONF_WIFI
|
CONF_WIFI
|
||||||
@ -240,25 +240,6 @@ def command_wizard(args):
|
|||||||
return wizard.wizard(args.configuration)
|
return wizard.wizard(args.configuration)
|
||||||
|
|
||||||
|
|
||||||
def strip_default_ids(config):
|
|
||||||
value = config
|
|
||||||
if isinstance(config, list):
|
|
||||||
value = type(config)()
|
|
||||||
for x in config:
|
|
||||||
if isinstance(x, core.ID) and not x.is_manual:
|
|
||||||
continue
|
|
||||||
value.append(strip_default_ids(x))
|
|
||||||
return value
|
|
||||||
elif isinstance(config, dict):
|
|
||||||
value = type(config)()
|
|
||||||
for k, v in config.iteritems():
|
|
||||||
if isinstance(v, core.ID) and not v.is_manual:
|
|
||||||
continue
|
|
||||||
value[k] = strip_default_ids(v)
|
|
||||||
return value
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
def command_config(args, config):
|
def command_config(args, config):
|
||||||
_LOGGER.info("Configuration is valid!")
|
_LOGGER.info("Configuration is valid!")
|
||||||
if not args.verbose:
|
if not args.verbose:
|
||||||
@ -475,7 +456,7 @@ def run_esphomeyaml(argv):
|
|||||||
|
|
||||||
CORE.config_path = args.configuration
|
CORE.config_path = args.configuration
|
||||||
|
|
||||||
config = read_config()
|
config = read_config(args.verbose)
|
||||||
if config is None:
|
if config is None:
|
||||||
return 1
|
return 1
|
||||||
CORE.config = config
|
CORE.config = config
|
||||||
|
@ -8,22 +8,20 @@ from esphomeyaml.cpp_helpers import setup_component
|
|||||||
from esphomeyaml.cpp_types import App, Component
|
from esphomeyaml.cpp_types import App, Component
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
ADS1115Component = sensor.sensor_ns.class_('ADS1115Component', Component, i2c.I2CDevice)
|
ADS1115Component = sensor.sensor_ns.class_('ADS1115Component', Component, i2c.I2CDevice)
|
||||||
|
|
||||||
ADS1115_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(ADS1115Component),
|
cv.GenerateID(): cv.declare_variable_id(ADS1115Component),
|
||||||
vol.Required(CONF_ADDRESS): cv.i2c_address,
|
vol.Required(CONF_ADDRESS): cv.i2c_address,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [ADS1115_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
rhs = App.make_ads1115_component(config[CONF_ADDRESS])
|
||||||
rhs = App.make_ads1115_component(conf[CONF_ADDRESS])
|
var = Pvariable(config[CONF_ID], rhs)
|
||||||
var = Pvariable(conf[CONF_ID], rhs)
|
setup_component(var, config)
|
||||||
setup_component(var, conf)
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_ADS1115_SENSOR'
|
BUILD_FLAGS = '-DUSE_ADS1115_SENSOR'
|
||||||
|
@ -7,8 +7,9 @@ from esphomeyaml.cpp_helpers import setup_component
|
|||||||
from esphomeyaml.cpp_types import Component, ComponentPtr, esphomelib_ns, std_vector
|
from esphomeyaml.cpp_types import Component, ComponentPtr, esphomelib_ns, std_vector
|
||||||
|
|
||||||
CustomComponentConstructor = esphomelib_ns.class_('CustomComponentConstructor')
|
CustomComponentConstructor = esphomelib_ns.class_('CustomComponentConstructor')
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
CUSTOM_COMPONENT_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(CustomComponentConstructor),
|
cv.GenerateID(): cv.declare_variable_id(CustomComponentConstructor),
|
||||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||||
vol.Optional(CONF_COMPONENTS): vol.All(cv.ensure_list, [vol.Schema({
|
vol.Optional(CONF_COMPONENTS): vol.All(cv.ensure_list, [vol.Schema({
|
||||||
@ -16,18 +17,15 @@ CUSTOM_COMPONENT_SCHEMA = vol.Schema({
|
|||||||
}).extend(cv.COMPONENT_SCHEMA.schema)]),
|
}).extend(cv.COMPONENT_SCHEMA.schema)]),
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [CUSTOM_COMPONENT_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||||
for template_ in process_lambda(conf[CONF_LAMBDA], [],
|
|
||||||
return_type=std_vector.template(ComponentPtr)):
|
return_type=std_vector.template(ComponentPtr)):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
rhs = CustomComponentConstructor(template_)
|
rhs = CustomComponentConstructor(template_)
|
||||||
custom = variable(conf[CONF_ID], rhs)
|
custom = variable(config[CONF_ID], rhs)
|
||||||
for i, comp in enumerate(conf.get(CONF_COMPONENTS, [])):
|
for i, comp in enumerate(config.get(CONF_COMPONENTS, [])):
|
||||||
setup_component(custom.get_component(i), comp)
|
setup_component(custom.get_component(i), comp)
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,19 +9,19 @@ from esphomeyaml.cpp_helpers import setup_component
|
|||||||
from esphomeyaml.cpp_types import App, PollingComponent
|
from esphomeyaml.cpp_types import App, PollingComponent
|
||||||
|
|
||||||
DallasComponent = sensor.sensor_ns.class_('DallasComponent', PollingComponent)
|
DallasComponent = sensor.sensor_ns.class_('DallasComponent', PollingComponent)
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(DallasComponent),
|
cv.GenerateID(): cv.declare_variable_id(DallasComponent),
|
||||||
vol.Required(CONF_PIN): pins.input_pullup_pin,
|
vol.Required(CONF_PIN): pins.input_pullup_pin,
|
||||||
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
|
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
rhs = App.make_dallas_component(config[CONF_PIN], config.get(CONF_UPDATE_INTERVAL))
|
||||||
rhs = App.make_dallas_component(conf[CONF_PIN], conf.get(CONF_UPDATE_INTERVAL))
|
var = Pvariable(config[CONF_ID], rhs)
|
||||||
var = Pvariable(conf[CONF_ID], rhs)
|
setup_component(var, config)
|
||||||
setup_component(var, conf)
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_DALLAS_SENSOR'
|
BUILD_FLAGS = '-DUSE_DALLAS_SENSOR'
|
||||||
|
@ -10,6 +10,7 @@ from esphomeyaml.cpp_generator import ArrayInitializer, MockObj, Pvariable, RawE
|
|||||||
from esphomeyaml.cpp_types import App
|
from esphomeyaml.cpp_types import App
|
||||||
|
|
||||||
DEPENDENCIES = ['display']
|
DEPENDENCIES = ['display']
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
Font = display.display_ns.class_('Font')
|
Font = display.display_ns.class_('Font')
|
||||||
Glyph = display.display_ns.class_('Glyph')
|
Glyph = display.display_ns.class_('Glyph')
|
||||||
@ -76,16 +77,15 @@ FONT_SCHEMA = vol.Schema({
|
|||||||
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
|
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(validate_pillow_installed, cv.ensure_list, [FONT_SCHEMA])
|
CONFIG_SCHEMA = vol.All(validate_pillow_installed, FONT_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
from PIL import ImageFont
|
from PIL import ImageFont
|
||||||
|
|
||||||
for conf in config:
|
path = CORE.relative_path(config[CONF_FILE])
|
||||||
path = CORE.relative_path(conf[CONF_FILE])
|
|
||||||
try:
|
try:
|
||||||
font = ImageFont.truetype(path, conf[CONF_SIZE])
|
font = ImageFont.truetype(path, config[CONF_SIZE])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise core.EsphomeyamlError(u"Could not load truetype file {}: {}".format(path, e))
|
raise core.EsphomeyamlError(u"Could not load truetype file {}: {}".format(path, e))
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ def to_code(config):
|
|||||||
|
|
||||||
glyph_args = {}
|
glyph_args = {}
|
||||||
data = []
|
data = []
|
||||||
for glyph in conf[CONF_GLYPHS]:
|
for glyph in config[CONF_GLYPHS]:
|
||||||
mask = font.getmask(glyph, mode='1')
|
mask = font.getmask(glyph, mode='1')
|
||||||
_, (offset_x, offset_y) = font.font.getsize(glyph)
|
_, (offset_x, offset_y) = font.font.getsize(glyph)
|
||||||
width, height = mask.size
|
width, height = mask.size
|
||||||
@ -108,14 +108,14 @@ def to_code(config):
|
|||||||
glyph_args[glyph] = (len(data), offset_x, offset_y, width, height)
|
glyph_args[glyph] = (len(data), offset_x, offset_y, width, height)
|
||||||
data += glyph_data
|
data += glyph_data
|
||||||
|
|
||||||
raw_data = MockObj(conf[CONF_RAW_DATA_ID])
|
raw_data = MockObj(config[CONF_RAW_DATA_ID])
|
||||||
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
||||||
raw_data, len(data),
|
raw_data, len(data),
|
||||||
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
||||||
|
|
||||||
glyphs = []
|
glyphs = []
|
||||||
for glyph in conf[CONF_GLYPHS]:
|
for glyph in config[CONF_GLYPHS]:
|
||||||
glyphs.append(Glyph(glyph, raw_data, *glyph_args[glyph]))
|
glyphs.append(Glyph(glyph, raw_data, *glyph_args[glyph]))
|
||||||
|
|
||||||
rhs = App.make_font(ArrayInitializer(*glyphs), ascent, ascent + descent)
|
rhs = App.make_font(ArrayInitializer(*glyphs), ascent, ascent + descent)
|
||||||
Pvariable(conf[CONF_ID], rhs)
|
Pvariable(config[CONF_ID], rhs)
|
||||||
|
@ -8,29 +8,28 @@ from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
|||||||
|
|
||||||
GlobalVariableComponent = esphomelib_ns.class_('GlobalVariableComponent', Component)
|
GlobalVariableComponent = esphomelib_ns.class_('GlobalVariableComponent', Component)
|
||||||
|
|
||||||
GLOBAL_VAR_SCHEMA = vol.Schema({
|
MULTI_CONF = True
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_ID): cv.declare_variable_id(GlobalVariableComponent),
|
vol.Required(CONF_ID): cv.declare_variable_id(GlobalVariableComponent),
|
||||||
vol.Required(CONF_TYPE): cv.string_strict,
|
vol.Required(CONF_TYPE): cv.string_strict,
|
||||||
vol.Optional(CONF_INITIAL_VALUE): cv.string_strict,
|
vol.Optional(CONF_INITIAL_VALUE): cv.string_strict,
|
||||||
vol.Optional(CONF_RESTORE_VALUE): cv.boolean,
|
vol.Optional(CONF_RESTORE_VALUE): cv.boolean,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [GLOBAL_VAR_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
type_ = RawExpression(config[CONF_TYPE])
|
||||||
type_ = RawExpression(conf[CONF_TYPE])
|
|
||||||
template_args = TemplateArguments(type_)
|
template_args = TemplateArguments(type_)
|
||||||
res_type = GlobalVariableComponent.template(template_args)
|
res_type = GlobalVariableComponent.template(template_args)
|
||||||
initial_value = None
|
initial_value = None
|
||||||
if CONF_INITIAL_VALUE in conf:
|
if CONF_INITIAL_VALUE in config:
|
||||||
initial_value = RawExpression(conf[CONF_INITIAL_VALUE])
|
initial_value = RawExpression(config[CONF_INITIAL_VALUE])
|
||||||
rhs = App.Pmake_global_variable(template_args, initial_value)
|
rhs = App.Pmake_global_variable(template_args, initial_value)
|
||||||
glob = Pvariable(conf[CONF_ID], rhs, type=res_type)
|
glob = Pvariable(config[CONF_ID], rhs, type=res_type)
|
||||||
|
|
||||||
if conf.get(CONF_RESTORE_VALUE, False):
|
if config.get(CONF_RESTORE_VALUE, False):
|
||||||
hash_ = hash(conf[CONF_ID].id) % 2**32
|
hash_ = hash(config[CONF_ID].id) % 2**32
|
||||||
add(glob.set_restore_value(hash_))
|
add(glob.set_restore_value(hash_))
|
||||||
|
|
||||||
setup_component(glob, conf)
|
setup_component(glob, config)
|
||||||
|
@ -14,6 +14,7 @@ from esphomeyaml.cpp_types import App
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['display']
|
DEPENDENCIES = ['display']
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
Image_ = display.display_ns.class_('Image')
|
Image_ = display.display_ns.class_('Image')
|
||||||
|
|
||||||
@ -26,21 +27,20 @@ IMAGE_SCHEMA = vol.Schema({
|
|||||||
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
|
cv.GenerateID(CONF_RAW_DATA_ID): cv.declare_variable_id(None),
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(font.validate_pillow_installed, cv.ensure_list, [IMAGE_SCHEMA])
|
CONFIG_SCHEMA = vol.All(font.validate_pillow_installed, IMAGE_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
for conf in config:
|
path = CORE.relative_path(config[CONF_FILE])
|
||||||
path = CORE.relative_path(conf[CONF_FILE])
|
|
||||||
try:
|
try:
|
||||||
image = Image.open(path)
|
image = Image.open(path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise core.EsphomeyamlError(u"Could not load image file {}: {}".format(path, e))
|
raise core.EsphomeyamlError(u"Could not load image file {}: {}".format(path, e))
|
||||||
|
|
||||||
if CONF_RESIZE in conf:
|
if CONF_RESIZE in config:
|
||||||
image.thumbnail(conf[CONF_RESIZE])
|
image.thumbnail(config[CONF_RESIZE])
|
||||||
|
|
||||||
image = image.convert('1', dither=Image.NONE)
|
image = image.convert('1', dither=Image.NONE)
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
@ -56,10 +56,10 @@ def to_code(config):
|
|||||||
pos = x + y * width8
|
pos = x + y * width8
|
||||||
data[pos // 8] |= 0x80 >> (pos % 8)
|
data[pos // 8] |= 0x80 >> (pos % 8)
|
||||||
|
|
||||||
raw_data = MockObj(conf[CONF_RAW_DATA_ID])
|
raw_data = MockObj(config[CONF_RAW_DATA_ID])
|
||||||
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
add(RawExpression('static const uint8_t {}[{}] PROGMEM = {}'.format(
|
||||||
raw_data, len(data),
|
raw_data, len(data),
|
||||||
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
ArrayInitializer(*[HexInt(x) for x in data], multiline=False))))
|
||||||
|
|
||||||
rhs = App.make_image(raw_data, width, height)
|
rhs = App.make_image(raw_data, width, height)
|
||||||
Pvariable(conf[CONF_ID], rhs)
|
Pvariable(config[CONF_ID], rhs)
|
||||||
|
@ -10,8 +10,9 @@ from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
|||||||
from esphomeyaml.cpp_types import App, Component
|
from esphomeyaml.cpp_types import App, Component
|
||||||
|
|
||||||
MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component)
|
MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component)
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
MY9231_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent),
|
cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent),
|
||||||
vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema,
|
||||||
vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
||||||
@ -23,26 +24,23 @@ MY9231_SCHEMA = vol.Schema({
|
|||||||
vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool),
|
vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool),
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [MY9231_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for di in gpio_output_pin_expression(config[CONF_DATA_PIN]):
|
||||||
for di in gpio_output_pin_expression(conf[CONF_DATA_PIN]):
|
|
||||||
yield
|
yield
|
||||||
for dcki in gpio_output_pin_expression(conf[CONF_CLOCK_PIN]):
|
for dcki in gpio_output_pin_expression(config[CONF_CLOCK_PIN]):
|
||||||
yield
|
yield
|
||||||
rhs = App.make_my9231_component(di, dcki)
|
rhs = App.make_my9231_component(di, dcki)
|
||||||
my9231 = Pvariable(conf[CONF_ID], rhs)
|
my9231 = Pvariable(config[CONF_ID], rhs)
|
||||||
if CONF_NUM_CHANNELS in conf:
|
if CONF_NUM_CHANNELS in config:
|
||||||
add(my9231.set_num_channels(conf[CONF_NUM_CHANNELS]))
|
add(my9231.set_num_channels(config[CONF_NUM_CHANNELS]))
|
||||||
if CONF_NUM_CHIPS in conf:
|
if CONF_NUM_CHIPS in config:
|
||||||
add(my9231.set_num_chips(conf[CONF_NUM_CHIPS]))
|
add(my9231.set_num_chips(config[CONF_NUM_CHIPS]))
|
||||||
if CONF_BIT_DEPTH in conf:
|
if CONF_BIT_DEPTH in config:
|
||||||
add(my9231.set_bit_depth(conf[CONF_BIT_DEPTH]))
|
add(my9231.set_bit_depth(config[CONF_BIT_DEPTH]))
|
||||||
if CONF_UPDATE_ON_BOOT in conf:
|
if CONF_UPDATE_ON_BOOT in config:
|
||||||
add(my9231.set_update(conf[CONF_UPDATE_ON_BOOT]))
|
add(my9231.set_update(config[CONF_UPDATE_ON_BOOT]))
|
||||||
setup_component(my9231, conf)
|
setup_component(my9231, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
||||||
|
@ -2,38 +2,31 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from esphomeyaml.components import i2c, output
|
from esphomeyaml.components import i2c, output
|
||||||
import esphomeyaml.config_validation as cv
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml.const import CONF_ADDRESS, CONF_FREQUENCY, CONF_ID, CONF_PHASE_BALANCER
|
from esphomeyaml.const import CONF_ADDRESS, CONF_FREQUENCY, CONF_ID
|
||||||
from esphomeyaml.cpp_generator import Pvariable, add
|
from esphomeyaml.cpp_generator import Pvariable, add
|
||||||
from esphomeyaml.cpp_helpers import setup_component
|
from esphomeyaml.cpp_helpers import setup_component
|
||||||
from esphomeyaml.cpp_types import App, Component
|
from esphomeyaml.cpp_types import App, Component
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
PCA9685OutputComponent = output.output_ns.class_('PCA9685OutputComponent',
|
PCA9685OutputComponent = output.output_ns.class_('PCA9685OutputComponent',
|
||||||
Component, i2c.I2CDevice)
|
Component, i2c.I2CDevice)
|
||||||
|
|
||||||
PHASE_BALANCER_MESSAGE = ("The phase_balancer option has been removed in version 1.5.0. "
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
"esphomelib will now automatically choose a suitable phase balancer.")
|
|
||||||
|
|
||||||
PCA9685_SCHEMA = vol.Schema({
|
|
||||||
cv.GenerateID(): cv.declare_variable_id(PCA9685OutputComponent),
|
cv.GenerateID(): cv.declare_variable_id(PCA9685OutputComponent),
|
||||||
vol.Required(CONF_FREQUENCY): vol.All(cv.frequency,
|
vol.Required(CONF_FREQUENCY): vol.All(cv.frequency,
|
||||||
vol.Range(min=23.84, max=1525.88)),
|
vol.Range(min=23.84, max=1525.88)),
|
||||||
vol.Optional(CONF_ADDRESS): cv.i2c_address,
|
vol.Optional(CONF_ADDRESS): cv.i2c_address,
|
||||||
|
|
||||||
vol.Optional(CONF_PHASE_BALANCER): cv.invalid(PHASE_BALANCER_MESSAGE),
|
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [PCA9685_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
rhs = App.make_pca9685_component(config.get(CONF_FREQUENCY))
|
||||||
rhs = App.make_pca9685_component(conf.get(CONF_FREQUENCY))
|
pca9685 = Pvariable(config[CONF_ID], rhs)
|
||||||
pca9685 = Pvariable(conf[CONF_ID], rhs)
|
if CONF_ADDRESS in config:
|
||||||
if CONF_ADDRESS in conf:
|
add(pca9685.set_address(config[CONF_ADDRESS]))
|
||||||
add(pca9685.set_address(conf[CONF_ADDRESS]))
|
setup_component(pca9685, config)
|
||||||
setup_component(pca9685, conf)
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_PCA9685_OUTPUT'
|
BUILD_FLAGS = '-DUSE_PCA9685_OUTPUT'
|
||||||
|
@ -8,6 +8,7 @@ from esphomeyaml.cpp_helpers import setup_component
|
|||||||
from esphomeyaml.cpp_types import App, GPIOInputPin, GPIOOutputPin, io_ns
|
from esphomeyaml.cpp_types import App, GPIOInputPin, GPIOOutputPin, io_ns
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
PCF8574GPIOMode = io_ns.enum('PCF8574GPIOMode')
|
PCF8574GPIOMode = io_ns.enum('PCF8574GPIOMode')
|
||||||
PCF8675_GPIO_MODES = {
|
PCF8675_GPIO_MODES = {
|
||||||
@ -19,20 +20,17 @@ PCF8675_GPIO_MODES = {
|
|||||||
PCF8574GPIOInputPin = io_ns.class_('PCF8574GPIOInputPin', GPIOInputPin)
|
PCF8574GPIOInputPin = io_ns.class_('PCF8574GPIOInputPin', GPIOInputPin)
|
||||||
PCF8574GPIOOutputPin = io_ns.class_('PCF8574GPIOOutputPin', GPIOOutputPin)
|
PCF8574GPIOOutputPin = io_ns.class_('PCF8574GPIOOutputPin', GPIOOutputPin)
|
||||||
|
|
||||||
PCF8574_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_ID): cv.declare_variable_id(pins.PCF8574Component),
|
vol.Required(CONF_ID): cv.declare_variable_id(pins.PCF8574Component),
|
||||||
vol.Optional(CONF_ADDRESS, default=0x21): cv.i2c_address,
|
vol.Optional(CONF_ADDRESS, default=0x21): cv.i2c_address,
|
||||||
vol.Optional(CONF_PCF8575, default=False): cv.boolean,
|
vol.Optional(CONF_PCF8575, default=False): cv.boolean,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [PCF8574_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
rhs = App.make_pcf8574_component(config[CONF_ADDRESS], config[CONF_PCF8575])
|
||||||
rhs = App.make_pcf8574_component(conf[CONF_ADDRESS], conf[CONF_PCF8575])
|
var = Pvariable(config[CONF_ID], rhs)
|
||||||
var = Pvariable(conf[CONF_ID], rhs)
|
setup_component(var, config)
|
||||||
setup_component(var, conf)
|
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_PCF8574'
|
BUILD_FLAGS = '-DUSE_PCF8574'
|
||||||
|
@ -11,12 +11,13 @@ from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
|||||||
from esphomeyaml.cpp_types import App, PollingComponent, Trigger, std_string
|
from esphomeyaml.cpp_types import App, PollingComponent, Trigger, std_string
|
||||||
|
|
||||||
DEPENDENCIES = ['spi']
|
DEPENDENCIES = ['spi']
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
PN532Component = binary_sensor.binary_sensor_ns.class_('PN532Component', PollingComponent,
|
PN532Component = binary_sensor.binary_sensor_ns.class_('PN532Component', PollingComponent,
|
||||||
spi.SPIDevice)
|
spi.SPIDevice)
|
||||||
PN532Trigger = binary_sensor.binary_sensor_ns.class_('PN532Trigger', Trigger.template(std_string))
|
PN532Trigger = binary_sensor.binary_sensor_ns.class_('PN532Trigger', Trigger.template(std_string))
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(PN532Component),
|
cv.GenerateID(): cv.declare_variable_id(PN532Component),
|
||||||
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
||||||
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
||||||
@ -24,23 +25,22 @@ CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
|||||||
vol.Optional(CONF_ON_TAG): automation.validate_automation({
|
vol.Optional(CONF_ON_TAG): automation.validate_automation({
|
||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger),
|
||||||
}),
|
}),
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for spi_ in get_variable(config[CONF_SPI_ID]):
|
||||||
for spi_ in get_variable(conf[CONF_SPI_ID]):
|
|
||||||
yield
|
yield
|
||||||
for cs in gpio_output_pin_expression(conf[CONF_CS_PIN]):
|
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
|
||||||
yield
|
yield
|
||||||
rhs = App.make_pn532_component(spi_, cs, conf.get(CONF_UPDATE_INTERVAL))
|
rhs = App.make_pn532_component(spi_, cs, config.get(CONF_UPDATE_INTERVAL))
|
||||||
pn532 = Pvariable(conf[CONF_ID], rhs)
|
pn532 = Pvariable(config[CONF_ID], rhs)
|
||||||
|
|
||||||
for conf_ in conf.get(CONF_ON_TAG, []):
|
for conf_ in config.get(CONF_ON_TAG, []):
|
||||||
trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger())
|
trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger())
|
||||||
automation.build_automation(trigger, std_string, conf_)
|
automation.build_automation(trigger, std_string, conf_)
|
||||||
|
|
||||||
setup_component(pn532, conf)
|
setup_component(pn532, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_PN532'
|
BUILD_FLAGS = '-DUSE_PN532'
|
||||||
|
@ -9,29 +9,28 @@ from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
|||||||
|
|
||||||
PowerSupplyComponent = esphomelib_ns.class_('PowerSupplyComponent', Component)
|
PowerSupplyComponent = esphomelib_ns.class_('PowerSupplyComponent', Component)
|
||||||
|
|
||||||
POWER_SUPPLY_SCHEMA = vol.Schema({
|
MULTI_CONF = True
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_ID): cv.declare_variable_id(PowerSupplyComponent),
|
vol.Required(CONF_ID): cv.declare_variable_id(PowerSupplyComponent),
|
||||||
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||||
vol.Optional(CONF_ENABLE_TIME): cv.positive_time_period_milliseconds,
|
vol.Optional(CONF_ENABLE_TIME): cv.positive_time_period_milliseconds,
|
||||||
vol.Optional(CONF_KEEP_ON_TIME): cv.positive_time_period_milliseconds,
|
vol.Optional(CONF_KEEP_ON_TIME): cv.positive_time_period_milliseconds,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [POWER_SUPPLY_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for pin in gpio_output_pin_expression(config[CONF_PIN]):
|
||||||
for pin in gpio_output_pin_expression(conf[CONF_PIN]):
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
rhs = App.make_power_supply(pin)
|
rhs = App.make_power_supply(pin)
|
||||||
psu = Pvariable(conf[CONF_ID], rhs)
|
psu = Pvariable(config[CONF_ID], rhs)
|
||||||
if CONF_ENABLE_TIME in conf:
|
if CONF_ENABLE_TIME in config:
|
||||||
add(psu.set_enable_time(conf[CONF_ENABLE_TIME]))
|
add(psu.set_enable_time(config[CONF_ENABLE_TIME]))
|
||||||
if CONF_KEEP_ON_TIME in conf:
|
if CONF_KEEP_ON_TIME in config:
|
||||||
add(psu.set_keep_on_time(conf[CONF_KEEP_ON_TIME]))
|
add(psu.set_keep_on_time(config[CONF_KEEP_ON_TIME]))
|
||||||
|
|
||||||
setup_component(psu, conf)
|
setup_component(psu, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_OUTPUT'
|
BUILD_FLAGS = '-DUSE_OUTPUT'
|
||||||
|
@ -12,19 +12,18 @@ DEPENDENCIES = ['uart']
|
|||||||
RDM6300Component = binary_sensor.binary_sensor_ns.class_('RDM6300Component', Component,
|
RDM6300Component = binary_sensor.binary_sensor_ns.class_('RDM6300Component', Component,
|
||||||
uart.UARTDevice)
|
uart.UARTDevice)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list_not_empty, [vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(RDM6300Component),
|
cv.GenerateID(): cv.declare_variable_id(RDM6300Component),
|
||||||
cv.GenerateID(CONF_UART_ID): cv.use_variable_id(uart.UARTComponent),
|
cv.GenerateID(CONF_UART_ID): cv.use_variable_id(uart.UARTComponent),
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for uart_ in get_variable(config[CONF_UART_ID]):
|
||||||
for uart_ in get_variable(conf[CONF_UART_ID]):
|
|
||||||
yield
|
yield
|
||||||
rhs = App.make_rdm6300_component(uart_)
|
rhs = App.make_rdm6300_component(uart_)
|
||||||
var = Pvariable(conf[CONF_ID], rhs)
|
var = Pvariable(config[CONF_ID], rhs)
|
||||||
setup_component(var, conf)
|
setup_component(var, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_RDM6300'
|
BUILD_FLAGS = '-DUSE_RDM6300'
|
||||||
|
@ -9,6 +9,7 @@ from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
|||||||
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
||||||
|
|
||||||
remote_ns = esphomelib_ns.namespace('remote')
|
remote_ns = esphomelib_ns.namespace('remote')
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
RemoteControlComponentBase = remote_ns.class_('RemoteControlComponentBase')
|
RemoteControlComponentBase = remote_ns.class_('RemoteControlComponentBase')
|
||||||
RemoteReceiverComponent = remote_ns.class_('RemoteReceiverComponent',
|
RemoteReceiverComponent = remote_ns.class_('RemoteReceiverComponent',
|
||||||
@ -36,7 +37,7 @@ def validate_dumpers_all(value):
|
|||||||
raise vol.Invalid("Not valid dumpers")
|
raise vol.Invalid("Not valid dumpers")
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(RemoteReceiverComponent),
|
cv.GenerateID(): cv.declare_variable_id(RemoteReceiverComponent),
|
||||||
vol.Required(CONF_PIN): pins.gpio_input_pin_schema,
|
vol.Required(CONF_PIN): pins.gpio_input_pin_schema,
|
||||||
vol.Optional(CONF_DUMP, default=[]):
|
vol.Optional(CONF_DUMP, default=[]):
|
||||||
@ -46,28 +47,27 @@ CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
|||||||
vol.Optional(CONF_BUFFER_SIZE): cv.validate_bytes,
|
vol.Optional(CONF_BUFFER_SIZE): cv.validate_bytes,
|
||||||
vol.Optional(CONF_FILTER): cv.positive_time_period_microseconds,
|
vol.Optional(CONF_FILTER): cv.positive_time_period_microseconds,
|
||||||
vol.Optional(CONF_IDLE): cv.positive_time_period_microseconds,
|
vol.Optional(CONF_IDLE): cv.positive_time_period_microseconds,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for pin in gpio_input_pin_expression(config[CONF_PIN]):
|
||||||
for pin in gpio_input_pin_expression(conf[CONF_PIN]):
|
|
||||||
yield
|
yield
|
||||||
rhs = App.make_remote_receiver_component(pin)
|
rhs = App.make_remote_receiver_component(pin)
|
||||||
receiver = Pvariable(conf[CONF_ID], rhs)
|
receiver = Pvariable(config[CONF_ID], rhs)
|
||||||
|
|
||||||
for dumper in conf[CONF_DUMP]:
|
for dumper in config[CONF_DUMP]:
|
||||||
add(receiver.add_dumper(DUMPERS[dumper].new()))
|
add(receiver.add_dumper(DUMPERS[dumper].new()))
|
||||||
if CONF_TOLERANCE in conf:
|
if CONF_TOLERANCE in config:
|
||||||
add(receiver.set_tolerance(conf[CONF_TOLERANCE]))
|
add(receiver.set_tolerance(config[CONF_TOLERANCE]))
|
||||||
if CONF_BUFFER_SIZE in conf:
|
if CONF_BUFFER_SIZE in config:
|
||||||
add(receiver.set_buffer_size(conf[CONF_BUFFER_SIZE]))
|
add(receiver.set_buffer_size(config[CONF_BUFFER_SIZE]))
|
||||||
if CONF_FILTER in conf:
|
if CONF_FILTER in config:
|
||||||
add(receiver.set_filter_us(conf[CONF_FILTER]))
|
add(receiver.set_filter_us(config[CONF_FILTER]))
|
||||||
if CONF_IDLE in conf:
|
if CONF_IDLE in config:
|
||||||
add(receiver.set_idle_us(conf[CONF_IDLE]))
|
add(receiver.set_idle_us(config[CONF_IDLE]))
|
||||||
|
|
||||||
setup_component(receiver, conf)
|
setup_component(receiver, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER'
|
BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER'
|
||||||
|
@ -16,6 +16,8 @@ RemoteTransmitterComponent = remote_ns.class_('RemoteTransmitterComponent',
|
|||||||
RCSwitchProtocol = remote_ns.class_('RCSwitchProtocol')
|
RCSwitchProtocol = remote_ns.class_('RCSwitchProtocol')
|
||||||
rc_switch_protocols = remote_ns.rc_switch_protocols
|
rc_switch_protocols = remote_ns.rc_switch_protocols
|
||||||
|
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
|
|
||||||
def validate_rc_switch_code(value):
|
def validate_rc_switch_code(value):
|
||||||
if not isinstance(value, (str, unicode)):
|
if not isinstance(value, (str, unicode)):
|
||||||
@ -76,12 +78,12 @@ RC_SWITCH_TYPE_D_SCHEMA = vol.Schema({
|
|||||||
vol.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA,
|
vol.Optional(CONF_PROTOCOL, default=1): RC_SWITCH_PROTOCOL_SCHEMA,
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(RemoteTransmitterComponent),
|
cv.GenerateID(): cv.declare_variable_id(RemoteTransmitterComponent),
|
||||||
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||||
vol.Optional(CONF_CARRIER_DUTY_PERCENT): vol.All(cv.percentage_int,
|
vol.Optional(CONF_CARRIER_DUTY_PERCENT): vol.All(cv.percentage_int,
|
||||||
vol.Range(min=1, max=100)),
|
vol.Range(min=1, max=100)),
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)])
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
|
|
||||||
def build_rc_switch_protocol(config):
|
def build_rc_switch_protocol(config):
|
||||||
@ -103,16 +105,15 @@ def binary_code(value):
|
|||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for pin in gpio_output_pin_expression(config[CONF_PIN]):
|
||||||
for pin in gpio_output_pin_expression(conf[CONF_PIN]):
|
|
||||||
yield
|
yield
|
||||||
rhs = App.make_remote_transmitter_component(pin)
|
rhs = App.make_remote_transmitter_component(pin)
|
||||||
transmitter = Pvariable(conf[CONF_ID], rhs)
|
transmitter = Pvariable(config[CONF_ID], rhs)
|
||||||
|
|
||||||
if CONF_CARRIER_DUTY_PERCENT in conf:
|
if CONF_CARRIER_DUTY_PERCENT in config:
|
||||||
add(transmitter.set_carrier_duty_percent(conf[CONF_CARRIER_DUTY_PERCENT]))
|
add(transmitter.set_carrier_duty_percent(config[CONF_CARRIER_DUTY_PERCENT]))
|
||||||
|
|
||||||
setup_component(transmitter, conf)
|
setup_component(transmitter, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_REMOTE_TRANSMITTER'
|
BUILD_FLAGS = '-DUSE_REMOTE_TRANSMITTER'
|
||||||
|
@ -10,33 +10,31 @@ from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
|||||||
|
|
||||||
SPIComponent = esphomelib_ns.class_('SPIComponent', Component)
|
SPIComponent = esphomelib_ns.class_('SPIComponent', Component)
|
||||||
SPIDevice = esphomelib_ns.class_('SPIDevice')
|
SPIDevice = esphomelib_ns.class_('SPIDevice')
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
SPI_SCHEMA = vol.All(vol.Schema({
|
CONFIG_SCHEMA = vol.All(vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(SPIComponent),
|
cv.GenerateID(): cv.declare_variable_id(SPIComponent),
|
||||||
vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
|
||||||
vol.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema,
|
vol.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema,
|
||||||
vol.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema,
|
vol.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema,
|
||||||
}), cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN))
|
}), cv.has_at_least_one_key(CONF_MISO_PIN, CONF_MOSI_PIN))
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [SPI_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
for clk in gpio_output_pin_expression(config[CONF_CLK_PIN]):
|
||||||
for clk in gpio_output_pin_expression(conf[CONF_CLK_PIN]):
|
|
||||||
yield
|
yield
|
||||||
rhs = App.init_spi(clk)
|
rhs = App.init_spi(clk)
|
||||||
spi = Pvariable(conf[CONF_ID], rhs)
|
spi = Pvariable(config[CONF_ID], rhs)
|
||||||
if CONF_MISO_PIN in conf:
|
if CONF_MISO_PIN in config:
|
||||||
for miso in gpio_input_pin_expression(conf[CONF_MISO_PIN]):
|
for miso in gpio_input_pin_expression(config[CONF_MISO_PIN]):
|
||||||
yield
|
yield
|
||||||
add(spi.set_miso(miso))
|
add(spi.set_miso(miso))
|
||||||
if CONF_MOSI_PIN in conf:
|
if CONF_MOSI_PIN in config:
|
||||||
for mosi in gpio_input_pin_expression(conf[CONF_MOSI_PIN]):
|
for mosi in gpio_input_pin_expression(config[CONF_MOSI_PIN]):
|
||||||
yield
|
yield
|
||||||
add(spi.set_mosi(mosi))
|
add(spi.set_mosi(mosi))
|
||||||
|
|
||||||
setup_component(spi, conf)
|
setup_component(spi, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_SPI'
|
BUILD_FLAGS = '-DUSE_SPI'
|
||||||
|
@ -9,25 +9,23 @@ from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
|||||||
|
|
||||||
UARTComponent = esphomelib_ns.class_('UARTComponent', Component)
|
UARTComponent = esphomelib_ns.class_('UARTComponent', Component)
|
||||||
UARTDevice = esphomelib_ns.class_('UARTDevice')
|
UARTDevice = esphomelib_ns.class_('UARTDevice')
|
||||||
|
MULTI_CONF = True
|
||||||
|
|
||||||
UART_SCHEMA = vol.All(vol.Schema({
|
CONFIG_SCHEMA = vol.All(vol.Schema({
|
||||||
cv.GenerateID(): cv.declare_variable_id(UARTComponent),
|
cv.GenerateID(): cv.declare_variable_id(UARTComponent),
|
||||||
vol.Optional(CONF_TX_PIN): pins.output_pin,
|
vol.Optional(CONF_TX_PIN): pins.output_pin,
|
||||||
vol.Optional(CONF_RX_PIN): pins.input_pin,
|
vol.Optional(CONF_RX_PIN): pins.input_pin,
|
||||||
vol.Required(CONF_BAUD_RATE): cv.positive_int,
|
vol.Required(CONF_BAUD_RATE): cv.positive_int,
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN))
|
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN))
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [UART_SCHEMA])
|
|
||||||
|
|
||||||
|
|
||||||
def to_code(config):
|
def to_code(config):
|
||||||
for conf in config:
|
tx = config.get(CONF_TX_PIN, -1)
|
||||||
tx = conf.get(CONF_TX_PIN, -1)
|
rx = config.get(CONF_RX_PIN, -1)
|
||||||
rx = conf.get(CONF_RX_PIN, -1)
|
rhs = App.init_uart(tx, rx, config[CONF_BAUD_RATE])
|
||||||
rhs = App.init_uart(tx, rx, conf[CONF_BAUD_RATE])
|
var = Pvariable(config[CONF_ID], rhs)
|
||||||
var = Pvariable(conf[CONF_ID], rhs)
|
|
||||||
|
|
||||||
setup_component(var, conf)
|
setup_component(var, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_UART'
|
BUILD_FLAGS = '-DUSE_UART'
|
||||||
|
@ -52,6 +52,10 @@ def iter_components(config):
|
|||||||
yield CONF_ESPHOMEYAML, core_config, conf
|
yield CONF_ESPHOMEYAML, core_config, conf
|
||||||
continue
|
continue
|
||||||
component = get_component(domain)
|
component = get_component(domain)
|
||||||
|
if getattr(component, 'MULTI_CONF', False):
|
||||||
|
for conf_ in conf:
|
||||||
|
yield domain, component, conf_
|
||||||
|
else:
|
||||||
yield domain, component, conf
|
yield domain, component, conf
|
||||||
if is_platform_component(component):
|
if is_platform_component(component):
|
||||||
for p_config in conf:
|
for p_config in conf:
|
||||||
@ -180,7 +184,7 @@ def do_id_pass(result): # type: (Config) -> None
|
|||||||
match = next((v[0] for v in declare_ids if v[0].id == id.id), None)
|
match = next((v[0] for v in declare_ids if v[0].id == id.id), None)
|
||||||
if match is None:
|
if match is None:
|
||||||
# No declared ID with this name
|
# No declared ID with this name
|
||||||
result.add_error("Couldn't find ID {}".format(id.id), path)
|
result.add_error("Couldn't find ID '{}'".format(id.id), path)
|
||||||
continue
|
continue
|
||||||
if not isinstance(match.type, MockObjClass) or not isinstance(id.type, MockObjClass):
|
if not isinstance(match.type, MockObjClass) or not isinstance(id.type, MockObjClass):
|
||||||
continue
|
continue
|
||||||
@ -198,7 +202,7 @@ def do_id_pass(result): # type: (Config) -> None
|
|||||||
id.id = v[0].id
|
id.id = v[0].id
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
result.add_error("Couldn't resolve ID for type {}".format(id.type), path)
|
result.add_error("Couldn't resolve ID for type '{}'".format(id.type), path)
|
||||||
|
|
||||||
|
|
||||||
def validate_config(config):
|
def validate_config(config):
|
||||||
@ -220,6 +224,7 @@ def validate_config(config):
|
|||||||
|
|
||||||
# Step 1: Load everything
|
# Step 1: Load everything
|
||||||
result.add_domain([CONF_ESPHOMEYAML], CONF_ESPHOMEYAML)
|
result.add_domain([CONF_ESPHOMEYAML], CONF_ESPHOMEYAML)
|
||||||
|
result[CONF_ESPHOMEYAML] = config[CONF_ESPHOMEYAML]
|
||||||
|
|
||||||
for domain, conf in config.iteritems():
|
for domain, conf in config.iteritems():
|
||||||
domain = str(domain)
|
domain = str(domain)
|
||||||
@ -229,13 +234,16 @@ def validate_config(config):
|
|||||||
result.add_domain([domain], domain)
|
result.add_domain([domain], domain)
|
||||||
result[domain] = conf
|
result[domain] = conf
|
||||||
if conf is None:
|
if conf is None:
|
||||||
config[domain] = conf = {}
|
result[domain] = conf = {}
|
||||||
component = get_component(domain)
|
component = get_component(domain)
|
||||||
if component is None:
|
if component is None:
|
||||||
result.add_error(u"Component not found: {}".format(domain), [domain])
|
result.add_error(u"Component not found: {}".format(domain), [domain])
|
||||||
skip_paths.append([domain])
|
skip_paths.append([domain])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not isinstance(conf, list) and getattr(component, 'MULTI_CONF', False):
|
||||||
|
result[domain] = conf = [conf]
|
||||||
|
|
||||||
success = True
|
success = True
|
||||||
dependencies = getattr(component, 'DEPENDENCIES', [])
|
dependencies = getattr(component, 'DEPENDENCIES', [])
|
||||||
for dependency in dependencies:
|
for dependency in dependencies:
|
||||||
@ -320,18 +328,27 @@ def validate_config(config):
|
|||||||
|
|
||||||
# Step 2: Validate configuration
|
# Step 2: Validate configuration
|
||||||
try:
|
try:
|
||||||
result[CONF_ESPHOMEYAML] = config[CONF_ESPHOMEYAML]
|
result[CONF_ESPHOMEYAML] = core_config.CONFIG_SCHEMA(result[CONF_ESPHOMEYAML])
|
||||||
result[CONF_ESPHOMEYAML] = core_config.CONFIG_SCHEMA(config[CONF_ESPHOMEYAML])
|
|
||||||
except vol.Invalid as ex:
|
except vol.Invalid as ex:
|
||||||
_comp_error(ex, [CONF_ESPHOMEYAML])
|
_comp_error(ex, [CONF_ESPHOMEYAML])
|
||||||
|
|
||||||
for domain, conf in config.iteritems():
|
for domain, conf in result.iteritems():
|
||||||
domain = str(domain)
|
domain = str(domain)
|
||||||
if [domain] in skip_paths:
|
if [domain] in skip_paths:
|
||||||
continue
|
continue
|
||||||
component = get_component(domain)
|
component = get_component(domain)
|
||||||
|
|
||||||
if hasattr(component, 'CONFIG_SCHEMA'):
|
if hasattr(component, 'CONFIG_SCHEMA'):
|
||||||
|
multi_conf = getattr(component, 'MULTI_CONF', False)
|
||||||
|
|
||||||
|
if multi_conf:
|
||||||
|
for i, conf_ in enumerate(conf):
|
||||||
|
try:
|
||||||
|
validated = component.CONFIG_SCHEMA(conf_)
|
||||||
|
result[domain][i] = validated
|
||||||
|
except vol.Invalid as ex:
|
||||||
|
_comp_error(ex, [domain, i])
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
validated = component.CONFIG_SCHEMA(conf)
|
validated = component.CONFIG_SCHEMA(conf)
|
||||||
result[domain] = validated
|
result[domain] = validated
|
||||||
@ -377,12 +394,14 @@ def humanize_error(config, validation_error):
|
|||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
validation_error = unicode(validation_error)
|
validation_error = unicode(validation_error)
|
||||||
m = re.match(r'^(.*)\s*for dictionary value @.*$', validation_error)
|
m = re.match(r'^(.*?)\s*(?:for dictionary value )?@ data\[.*$', validation_error)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
validation_error = m.group(1)
|
validation_error = m.group(1)
|
||||||
validation_error = validation_error.strip()
|
validation_error = validation_error.strip()
|
||||||
if not validation_error.endswith(u'.'):
|
if not validation_error.endswith(u'.'):
|
||||||
validation_error += u'.'
|
validation_error += u'.'
|
||||||
|
if offending_item_summary is None:
|
||||||
|
return validation_error
|
||||||
return u"{} Got '{}'".format(validation_error, offending_item_summary)
|
return u"{} Got '{}'".format(validation_error, offending_item_summary)
|
||||||
|
|
||||||
|
|
||||||
@ -402,7 +421,7 @@ def _format_vol_invalid(ex, config, path, domain):
|
|||||||
paren = domain
|
paren = domain
|
||||||
message += u"'{}' is a required option for [{}].".format(ex.path[-1], paren)
|
message += u"'{}' is a required option for [{}].".format(ex.path[-1], paren)
|
||||||
else:
|
else:
|
||||||
message += u'{}.'.format(humanize_error(_nested_getitem(config, path), ex))
|
message += humanize_error(_nested_getitem(config, path), ex)
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
@ -427,10 +446,10 @@ def load_config():
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def line_info(obj):
|
def line_info(obj, highlight=True):
|
||||||
"""Display line config source."""
|
"""Display line config source."""
|
||||||
if hasattr(obj, '__config_file__'):
|
if hasattr(obj, '__config_file__'):
|
||||||
return color('cyan', "[source {}:{}]"
|
return color('cyan' if highlight else 'white', "[source {}:{}]"
|
||||||
.format(obj.__config_file__, obj.__line__ or '?'))
|
.format(obj.__config_file__, obj.__line__ or '?'))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -473,7 +492,7 @@ def dump_dict(config, path, at_root=True):
|
|||||||
sep = color('red', sep)
|
sep = color('red', sep)
|
||||||
msg, _ = dump_dict(config, path_, at_root=False)
|
msg, _ = dump_dict(config, path_, at_root=False)
|
||||||
msg = indent(msg)
|
msg = indent(msg)
|
||||||
inf = line_info(config.nested_item(path_))
|
inf = line_info(config.nested_item(path_), highlight=config.is_in_error_path(path_))
|
||||||
if inf is not None:
|
if inf is not None:
|
||||||
msg = inf + u'\n' + msg
|
msg = inf + u'\n' + msg
|
||||||
elif msg:
|
elif msg:
|
||||||
@ -496,7 +515,7 @@ def dump_dict(config, path, at_root=True):
|
|||||||
st = color('red', st)
|
st = color('red', st)
|
||||||
msg, m = dump_dict(config, path_, at_root=False)
|
msg, m = dump_dict(config, path_, at_root=False)
|
||||||
|
|
||||||
inf = line_info(config.nested_item(path_))
|
inf = line_info(config.nested_item(path_), highlight=config.is_in_error_path(path_))
|
||||||
if m:
|
if m:
|
||||||
msg = u'\n' + indent(msg)
|
msg = u'\n' + indent(msg)
|
||||||
|
|
||||||
@ -531,7 +550,27 @@ def dump_dict(config, path, at_root=True):
|
|||||||
return ret, multiline
|
return ret, multiline
|
||||||
|
|
||||||
|
|
||||||
def read_config():
|
def strip_default_ids(config):
|
||||||
|
if isinstance(config, list):
|
||||||
|
to_remove = []
|
||||||
|
for i, x in enumerate(config):
|
||||||
|
x = config[i] = strip_default_ids(x)
|
||||||
|
if isinstance(x, core.ID) and not x.is_manual:
|
||||||
|
to_remove.append(x)
|
||||||
|
for x in to_remove:
|
||||||
|
config.remove(x)
|
||||||
|
elif isinstance(config, dict):
|
||||||
|
to_remove = []
|
||||||
|
for k, v in config.iteritems():
|
||||||
|
v = config[k] = strip_default_ids(v)
|
||||||
|
if isinstance(v, core.ID) and not v.is_manual:
|
||||||
|
to_remove.append(k)
|
||||||
|
for k in to_remove:
|
||||||
|
config.pop(k)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def read_config(verbose):
|
||||||
_LOGGER.info("Reading configuration...")
|
_LOGGER.info("Reading configuration...")
|
||||||
try:
|
try:
|
||||||
res = load_config()
|
res = load_config()
|
||||||
@ -539,6 +578,9 @@ def read_config():
|
|||||||
_LOGGER.error(u"Error while reading config: %s", err)
|
_LOGGER.error(u"Error while reading config: %s", err)
|
||||||
return None
|
return None
|
||||||
if res.errors:
|
if res.errors:
|
||||||
|
if not verbose:
|
||||||
|
res = strip_default_ids(res)
|
||||||
|
|
||||||
safe_print(color('bold_red', u"Failed config"))
|
safe_print(color('bold_red', u"Failed config"))
|
||||||
safe_print('')
|
safe_print('')
|
||||||
for path, domain in res.domains:
|
for path, domain in res.domains:
|
||||||
|
@ -101,7 +101,6 @@ const colorReplace = (pre, state, text) => {
|
|||||||
break;
|
break;
|
||||||
case 31:
|
case 31:
|
||||||
state.foregroundColor = "red";
|
state.foregroundColor = "red";
|
||||||
state.bold = true;
|
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
state.foregroundColor = "green";
|
state.foregroundColor = "green";
|
||||||
|
@ -171,7 +171,7 @@ def _add_reference(obj, loader, node):
|
|||||||
if isinstance(obj, (str, unicode)):
|
if isinstance(obj, (str, unicode)):
|
||||||
obj = NodeStrClass(obj)
|
obj = NodeStrClass(obj)
|
||||||
if isinstance(obj, list):
|
if isinstance(obj, list):
|
||||||
return obj
|
obj = NodeListClass(obj)
|
||||||
setattr(obj, '__config_file__', loader.name)
|
setattr(obj, '__config_file__', loader.name)
|
||||||
setattr(obj, '__line__', node.start_mark.line)
|
setattr(obj, '__line__', node.start_mark.line)
|
||||||
return obj
|
return obj
|
||||||
@ -369,7 +369,7 @@ yaml.SafeDumper.add_representer(
|
|||||||
yaml.SafeDumper.add_representer(
|
yaml.SafeDumper.add_representer(
|
||||||
NodeListClass,
|
NodeListClass,
|
||||||
lambda dumper, value:
|
lambda dumper, value:
|
||||||
dumper.represent_sequence(dumper, 'tag:yaml.org,2002:map', value)
|
dumper.represent_sequence('tag:yaml.org,2002:seq', value)
|
||||||
)
|
)
|
||||||
|
|
||||||
yaml.SafeDumper.add_representer(unicode, unicode_representer)
|
yaml.SafeDumper.add_representer(unicode, unicode_representer)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user