esphome/esphomeyaml/components/output/__init__.py

37 lines
1.1 KiB
Python
Raw Normal View History

2018-04-07 01:23:03 +02:00
import voluptuous as vol
import esphomeyaml.config_validation as cv
2018-06-02 22:22:20 +02:00
from esphomeyaml.components.power_supply import PowerSupplyComponent
2018-05-20 12:41:52 +02:00
from esphomeyaml.const import CONF_INVERTED, CONF_MAX_POWER, CONF_POWER_SUPPLY
from esphomeyaml.helpers import add, esphomelib_ns, get_variable
2018-04-07 01:23:03 +02:00
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
2018-05-20 12:41:52 +02:00
})
2018-06-02 22:22:20 +02:00
BINARY_OUTPUT_SCHEMA = vol.Schema({
vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent),
2018-04-07 01:23:03 +02:00
vol.Optional(CONF_INVERTED): cv.boolean,
2018-05-20 12:41:52 +02:00
})
2018-04-07 01:23:03 +02:00
2018-05-20 12:41:52 +02:00
FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({
2018-05-27 14:15:24 +02:00
vol.Optional(CONF_MAX_POWER): cv.percentage,
2018-04-07 01:23:03 +02:00
})
2018-05-20 12:41:52 +02:00
output_ns = esphomelib_ns.namespace('output')
2018-04-07 01:23:03 +02:00
def setup_output_platform(obj, config, skip_power_supply=False):
if CONF_INVERTED in config:
add(obj.set_inverted(config[CONF_INVERTED]))
if not skip_power_supply and CONF_POWER_SUPPLY in config:
2018-06-02 22:22:20 +02:00
power_supply = None
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
2018-04-07 01:23:03 +02:00
add(obj.set_power_supply(power_supply))
if CONF_MAX_POWER in config:
add(obj.set_max_power(config[CONF_MAX_POWER]))
2018-05-06 15:56:12 +02:00
BUILD_FLAGS = '-DUSE_OUTPUT'