Exemple #1
0
import voluptuous as vol

from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY
import esphomeyaml.config_validation as cv
from esphomeyaml.components.power_supply import PowerSupplyComponent
from esphomeyaml.const import CONF_INVERTED, CONF_MAX_POWER, CONF_POWER_SUPPLY, CONF_ID, CONF_LEVEL
from esphomeyaml.helpers import add, esphomelib_ns, get_variable, TemplateArguments, Pvariable, \
    templatable, bool_

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

BINARY_OUTPUT_SCHEMA = vol.Schema({
    vol.Optional(CONF_POWER_SUPPLY):
    cv.use_variable_id(PowerSupplyComponent),
    vol.Optional(CONF_INVERTED):
    cv.boolean,
})

BINARY_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    BINARY_OUTPUT_SCHEMA.schema)

FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({
    vol.Optional(CONF_MAX_POWER):
    cv.percentage,
})

FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    FLOAT_OUTPUT_SCHEMA.schema)

output_ns = esphomelib_ns.namespace('output')
TurnOffAction = output_ns.TurnOffAction
Exemple #2
0
import esphomeyaml.config_validation as cv
from esphomeyaml.components import output
from esphomeyaml.components.pca9685 import PCA9685OutputComponent
from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY
from esphomeyaml.helpers import Pvariable, get_variable

DEPENDENCIES = ['pca9685']

Channel = PCA9685OutputComponent.Channel

PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_ID): cv.declare_variable_id(Channel),
    vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int),
                                        vol.Range(min=0, max=15)),
    cv.GenerateID(CONF_PCA9685_ID): cv.use_variable_id(PCA9685OutputComponent),
})


def to_code(config):
    power_supply = None
    if CONF_POWER_SUPPLY in config:
        for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
            yield
    pca9685 = None
    for pca9685 in get_variable(config[CONF_PCA9685_ID]):
        yield
    rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply)
    out = Pvariable(config[CONF_ID], rhs)
    output.setup_output_platform(out, config, skip_power_supply=True)
Exemple #3
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.components import fan, output
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT
from esphomeyaml.helpers import App, add, get_variable, variable, setup_component

PLATFORM_SCHEMA = cv.nameable(
    fan.FAN_PLATFORM_SCHEMA.extend({
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(fan.MakeFan),
        vol.Required(CONF_OUTPUT):
        cv.use_variable_id(output.BinaryOutput),
        vol.Optional(CONF_OSCILLATION_OUTPUT):
        cv.use_variable_id(output.BinaryOutput),
    }).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    for output_ in get_variable(config[CONF_OUTPUT]):
        yield

    rhs = App.make_fan(config[CONF_NAME])
    fan_struct = variable(config[CONF_MAKE_ID], rhs)
    add(fan_struct.Poutput.set_binary(output_))
    if CONF_OSCILLATION_OUTPUT in config:
        for oscillation_output in get_variable(
                config[CONF_OSCILLATION_OUTPUT]):
            yield
        add(fan_struct.Poutput.set_oscillation(oscillation_output))
Exemple #4
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.components import fan
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OSCILLATION_OUTPUT, CONF_OUTPUT
from esphomeyaml.helpers import App, add, get_variable, variable

PLATFORM_SCHEMA = fan.PLATFORM_SCHEMA.extend({
    cv.GenerateID(CONF_MAKE_ID):
    cv.declare_variable_id(fan.MakeFan),
    vol.Required(CONF_OUTPUT):
    cv.use_variable_id(None),
    vol.Optional(CONF_OSCILLATION_OUTPUT):
    cv.use_variable_id(None),
}).extend(fan.FAN_SCHEMA.schema)


def to_code(config):
    output = None
    for output in get_variable(config[CONF_OUTPUT]):
        yield

    rhs = App.make_fan(config[CONF_NAME])
    fan_struct = variable(config[CONF_MAKE_ID], rhs)
    add(fan_struct.Poutput.set_binary(output))
    if CONF_OSCILLATION_OUTPUT in config:
        oscillation_output = None
        for oscillation_output in get_variable(
                config[CONF_OSCILLATION_OUTPUT]):
            yield
        add(fan_struct.Poutput.set_oscillation(oscillation_output))
import esphomeyaml.config_validation as cv
from esphomeyaml.components import sensor
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
    make_address_array
from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_MAKE_ID, \
    CONF_NAME, CONF_TEMPERATURE
from esphomeyaml.helpers import Pvariable, esphomelib_ns, get_variable

DEPENDENCIES = ['esp32_ble_tracker']

XiaomiDevice = esphomelib_ns.XiaomiDevice

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(XiaomiDevice),
    cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker),
    vol.Required(CONF_MAC_ADDRESS): cv.mac_address,
    vol.Optional(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA),
    vol.Optional(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA),
    vol.Optional(CONF_BATTERY_LEVEL): cv.nameable(sensor.SENSOR_SCHEMA),
})


def to_code(config):
    hub = None
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
        yield
    rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
    dev = Pvariable(config[CONF_MAKE_ID], rhs)
    if CONF_TEMPERATURE in config:
        conf = config[CONF_TEMPERATURE]
Exemple #6
0
BUILD_FLAGS = '-DUSE_API'


def lib_deps(config):
    if CORE.is_esp32:
        return '[email protected]'
    if CORE.is_esp8266:
        return '[email protected]'
    raise NotImplementedError


CONF_HOMEASSISTANT_SERVICE = 'homeassistant.service'
HOMEASSISTANT_SERVIC_ACTION_SCHEMA = vol.Schema({
    cv.GenerateID():
    cv.use_variable_id(APIServer),
    vol.Required(CONF_SERVICE):
    cv.string,
    vol.Optional(CONF_DATA):
    vol.Schema({
        cv.string: cv.string,
    }),
    vol.Optional(CONF_DATA_TEMPLATE):
    vol.Schema({
        cv.string: cv.string,
    }),
    vol.Optional(CONF_VARIABLES):
    vol.Schema({
        cv.string: cv.lambda_,
    }),
})
    }),
    vol.Optional(CONF_RAW): vol.Any(validate_raw_data, vol.Schema({
        vol.Required(CONF_DATA): validate_raw_data,
        vol.Optional(CONF_CARRIER_FREQUENCY): vol.All(cv.frequency, vol.Coerce(int)),
    })),
    vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_B): RC_SWITCH_TYPE_B_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_C): RC_SWITCH_TYPE_C_SCHEMA,
    vol.Optional(CONF_RC_SWITCH_TYPE_D): RC_SWITCH_TYPE_D_SCHEMA,

    vol.Optional(CONF_REPEAT): vol.Any(cv.positive_not_null_int, vol.Schema({
        vol.Required(CONF_TIMES): cv.positive_not_null_int,
        vol.Required(CONF_WAIT_TIME): cv.positive_time_period_microseconds,
    })),
    cv.GenerateID(CONF_REMOTE_TRANSMITTER_ID): cv.use_variable_id(RemoteTransmitterComponent),
    cv.GenerateID(CONF_TRANSMITTER_ID): cv.declare_variable_id(RemoteTransmitter),
    vol.Optional(CONF_INVERTED): cv.invalid("Remote Transmitters do not support inverted mode!"),
}), cv.has_exactly_one_key(*REMOTE_KEYS))


def transmitter_base(full_config):
    name = full_config[CONF_NAME]
    key, config = next((k, v) for k, v in full_config.items() if k in REMOTE_KEYS)

    if key == CONF_LG:
        return LGTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS])
    elif key == CONF_NEC:
        return NECTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
    elif key == CONF_PANASONIC:
        return PanasonicTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
Exemple #8
0

BUILD_FLAGS = '-DUSE_API'


def lib_deps(config):
    if CORE.is_esp32:
        return '[email protected]'
    if CORE.is_esp8266:
        return '[email protected]'
    raise NotImplementedError


CONF_HOMEASSISTANT_SERVICE = 'homeassistant.service'
LOGGER_LOG_ACTION_SCHEMA = vol.Schema({
    cv.GenerateID(): cv.use_variable_id(APIServer),
    vol.Required(CONF_SERVICE): cv.string,
    vol.Optional(CONF_DATA): vol.Schema({
        cv.string: cv.string,
    }),
    vol.Optional(CONF_DATA_TEMPLATE): vol.Schema({
        cv.string: cv.string,
    }),
    vol.Optional(CONF_VARIABLES): vol.Schema({
        cv.string: cv.lambda_,
    }),
})


@ACTION_REGISTRY.register(CONF_HOMEASSISTANT_SERVICE, LOGGER_LOG_ACTION_SCHEMA)
def homeassistant_service_to_code(config, action_id, arg_type, template_arg):
Exemple #9
0
    CORE.add_job(setup_sensor_core_, sensor_var, mqtt_var, config)


def register_sensor(var, config):
    sensor_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
    rhs = App.register_sensor(sensor_var)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
    CORE.add_job(setup_sensor_core_, sensor_var, mqtt_var, config)


BUILD_FLAGS = '-DUSE_SENSOR'

CONF_SENSOR_IN_RANGE = 'sensor.in_range'
SENSOR_IN_RANGE_CONDITION_SCHEMA = vol.All(
    {
        vol.Required(CONF_ID): cv.use_variable_id(Sensor),
        vol.Optional(CONF_ABOVE): cv.float_,
        vol.Optional(CONF_BELOW): cv.float_,
    }, cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW))


@CONDITION_REGISTRY.register(CONF_SENSOR_IN_RANGE,
                             SENSOR_IN_RANGE_CONDITION_SCHEMA)
def sensor_in_range_to_code(config, condition_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_sensor_in_range_condition(template_arg)
    type = SensorInRangeCondition.template(arg_type)
    cond = Pvariable(condition_id, rhs, type=type)

    if CONF_ABOVE in config:
Exemple #10
0
 cv.declare_variable_id(None),
 vol.Optional(CONF_DELAY):
 cv.templatable(cv.positive_time_period_milliseconds),
 vol.Optional(CONF_MQTT_PUBLISH):
 vol.Schema(
     {
         vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic),
         vol.Required(CONF_PAYLOAD): cv.templatable(
             cv.mqtt_payload),
         vol.Optional(CONF_QOS): cv.templatable(cv.mqtt_qos),
         vol.Optional(CONF_RETAIN): cv.templatable(cv.boolean),
     }),
 vol.Optional(CONF_LIGHT_TOGGLE):
 maybe_simple_id({
     vol.Required(CONF_ID):
     cv.use_variable_id(None),
     vol.Optional(CONF_TRANSITION_LENGTH):
     cv.templatable(cv.positive_time_period_milliseconds),
 }),
 vol.Optional(CONF_LIGHT_TURN_OFF):
 maybe_simple_id({
     vol.Required(CONF_ID):
     cv.use_variable_id(None),
     vol.Optional(CONF_TRANSITION_LENGTH):
     cv.templatable(cv.positive_time_period_milliseconds),
 }),
 vol.Optional(CONF_LIGHT_TURN_ON):
 maybe_simple_id({
     vol.Required(CONF_ID):
     cv.use_variable_id(None),
     vol.Exclusive(CONF_TRANSITION_LENGTH, 'transformer'):
Exemple #11
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.components import light, output
from esphomeyaml.const import CONF_BLUE, CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, \
    CONF_GREEN, CONF_MAKE_ID, CONF_NAME, CONF_RED, CONF_EFFECTS
from esphomeyaml.helpers import App, get_variable, variable, setup_component

PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
    vol.Required(CONF_RED): cv.use_variable_id(output.FloatOutput),
    vol.Required(CONF_GREEN): cv.use_variable_id(output.FloatOutput),
    vol.Required(CONF_BLUE): cv.use_variable_id(output.FloatOutput),
    vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float,
    vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds,
    vol.Optional(CONF_EFFECTS): light.validate_effects(light.RGB_EFFECTS),
}).extend(cv.COMPONENT_SCHEMA.schema))


def to_code(config):
    for red in get_variable(config[CONF_RED]):
        yield
    for green in get_variable(config[CONF_GREEN]):
        yield
    for blue in get_variable(config[CONF_BLUE]):
        yield
    rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue)
    light_struct = variable(config[CONF_MAKE_ID], rhs)
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
    setup_component(light_struct.Pstate, config)
Exemple #12
0
CONFIG_SCHEMA = automation.validate_automation({
    vol.Required(CONF_ID):
    cv.declare_variable_id(Script),
})


def to_code(config):
    for conf in config:
        trigger = Pvariable(conf[CONF_ID], Script.new())
        automation.build_automation(trigger, NoArg, conf)


CONF_SCRIPT_EXECUTE = 'script.execute'
SCRIPT_EXECUTE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(Script),
})


@ACTION_REGISTRY.register(CONF_SCRIPT_EXECUTE, SCRIPT_EXECUTE_ACTION_SCHEMA)
def script_execute_action_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_execute_action(template_arg)
    type = ScriptExecuteAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_SCRIPT_STOP = 'script.stop'
SCRIPT_STOP_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
Exemple #13
0

@CONDITION_REGISTRY.register(CONF_LAMBDA, LAMBDA_CONDITION_SCHEMA)
def lambda_condition_to_code(config, condition_id, arg_type, template_arg):
    for lambda_ in process_lambda(config, [(arg_type, 'x')],
                                  return_type=bool_):
        yield
    rhs = LambdaCondition.new(template_arg, lambda_)
    type = LambdaCondition.template(template_arg)
    yield Pvariable(condition_id, rhs, type=type)


CONF_COMPONENT_UPDATE = 'component.update'
COMPONENT_UPDATE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(PollingComponent),
})


@ACTION_REGISTRY.register(CONF_COMPONENT_UPDATE,
                          COMPONENT_UPDATE_ACTION_SCHEMA)
def component_update_action_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = UpdateComponentAction.new(template_arg, var)
    type = UpdateComponentAction.template(template_arg)
    yield Pvariable(action_id, rhs, type=type)


def build_action(full_config, arg_type):
    action_id = full_config[CONF_ACTION_ID]
Exemple #14
0
def shorthand_input_pin(value):
    value = input_pin(value)
    return {CONF_NUMBER: value}


def shorthand_input_pullup_pin(value):
    value = input_pullup_pin(value)
    return {CONF_NUMBER: value}


I2CDevice = esphomelib_ns.class_('I2CDevice')
PCF8574Component = io_ns.class_('PCF8574Component', Component, I2CDevice)

PCF8574_OUTPUT_PIN_SCHEMA = vol.Schema({
    vol.Required(CONF_PCF8574):
    cv.use_variable_id(PCF8574Component),
    vol.Required(CONF_NUMBER):
    vol.Coerce(int),
    vol.Optional(CONF_MODE):
    cv.one_of("OUTPUT", upper=True),
    vol.Optional(CONF_INVERTED, default=False):
    cv.boolean,
})

PCF8574_INPUT_PIN_SCHEMA = PCF8574_OUTPUT_PIN_SCHEMA.extend({
    vol.Optional(CONF_MODE):
    cv.one_of("INPUT", "INPUT_PULLUP", upper=True),
})


def internal_gpio_output_pin_schema(value):
Exemple #15
0
from esphomeyaml.components.pca9685 import PCA9685OutputComponent
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY
from esphomeyaml.cpp_generator import Pvariable, get_variable

DEPENDENCIES = ['pca9685']

Channel = PCA9685OutputComponent.class_('Channel', output.FloatOutput)

PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
    vol.Required(CONF_ID):
    cv.declare_variable_id(Channel),
    vol.Required(CONF_CHANNEL):
    vol.All(vol.Coerce(int), vol.Range(min=0, max=15)),
    cv.GenerateID(CONF_PCA9685_ID):
    cv.use_variable_id(PCA9685OutputComponent),
})


def to_code(config):
    power_supply = None
    if CONF_POWER_SUPPLY in config:
        for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
            yield
    for pca9685 in get_variable(config[CONF_PCA9685_ID]):
        yield
    rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply)
    out = Pvariable(config[CONF_ID], rhs)
    output.setup_output_platform(out, config, skip_power_supply=True)

Exemple #16
0
    setup_mqtt_component(mqtt_var, config)


def setup_light(light_obj, mqtt_obj, config):
    light_var = Pvariable(config[CONF_ID], light_obj, has_side_effects=False)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
    add_job(setup_light_core_, light_var, mqtt_var, config)


BUILD_FLAGS = '-DUSE_LIGHT'


CONF_LIGHT_TOGGLE = 'light.toggle'
LIGHT_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID): cv.use_variable_id(None),
    vol.Optional(CONF_TRANSITION_LENGTH): cv.templatable(cv.positive_time_period_milliseconds),
})


@ACTION_REGISTRY.register(CONF_LIGHT_TOGGLE, LIGHT_TOGGLE_ACTION_SCHEMA)
def light_toggle_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_toggle_action(template_arg)
    type = ToggleAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    if CONF_TRANSITION_LENGTH in config:
        for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32):
            yield None
Exemple #17
0
from esphomeyaml.components import esp32_ble_tracker, sensor
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
    make_address_array
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_MAKE_ID, \
    CONF_NAME, CONF_TEMPERATURE
from esphomeyaml.cpp_generator import get_variable, Pvariable

DEPENDENCIES = ['esp32_ble_tracker']

PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
    cv.GenerateID(CONF_MAKE_ID):
    cv.declare_variable_id(esp32_ble_tracker.XiaomiDevice),
    cv.GenerateID(CONF_ESP32_BLE_ID):
    cv.use_variable_id(ESP32BLETracker),
    vol.Required(CONF_MAC_ADDRESS):
    cv.mac_address,
    vol.Optional(CONF_TEMPERATURE):
    cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
    vol.Optional(CONF_HUMIDITY):
    cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
    vol.Optional(CONF_BATTERY_LEVEL):
    cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
})


def to_code(config):
    for hub in get_variable(config[CONF_ESP32_BLE_ID]):
        yield
    rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
Exemple #18
0
MODELS = {
    'SSD1306_128X32': display.display_ns.SSD1306_MODEL_128_32,
    'SSD1306_128X64': display.display_ns.SSD1306_MODEL_128_64,
    'SSD1306_96X16': display.display_ns.SSD1306_MODEL_96_16,
    'SH1106_128X32': display.display_ns.SH1106_MODEL_128_32,
    'SH1106_128X64': display.display_ns.SH1106_MODEL_128_64,
    'SH1106_96X16': display.display_ns.SH1106_MODEL_96_16,
}

SSD1306_MODEL = vol.All(vol.Upper, vol.Replace(' ', '_'), cv.one_of(*MODELS))

PLATFORM_SCHEMA = display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
    cv.GenerateID():
    cv.declare_variable_id(SPISSD1306),
    cv.GenerateID(CONF_SPI_ID):
    cv.use_variable_id(SPIComponent),
    vol.Required(CONF_CS_PIN):
    pins.gpio_output_pin_schema,
    vol.Required(CONF_DC_PIN):
    pins.gpio_output_pin_schema,
    vol.Required(CONF_MODEL):
    SSD1306_MODEL,
    vol.Optional(CONF_RESET_PIN):
    pins.gpio_output_pin_schema,
    vol.Optional(CONF_EXTERNAL_VCC):
    cv.boolean,
})


def to_code(config):
    for spi in get_variable(config[CONF_SPI_ID]):
Exemple #19
0
        for pin in conf[CONF_PINS]:
            mask |= 1 << pin[CONF_NUMBER]
        struct = StructInitializer(
            Ext1Wakeup, ('mask', mask),
            ('wakeup_mode', EXT1_WAKEUP_MODES[conf[CONF_MODE]]))
        add(deep_sleep.set_ext1_wakeup(struct))

    setup_component(deep_sleep, config)


BUILD_FLAGS = '-DUSE_DEEP_SLEEP'

CONF_DEEP_SLEEP_ENTER = 'deep_sleep.enter'
DEEP_SLEEP_ENTER_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(DeepSleepComponent),
})


@ACTION_REGISTRY.register(CONF_DEEP_SLEEP_ENTER,
                          DEEP_SLEEP_ENTER_ACTION_SCHEMA)
def deep_sleep_enter_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_enter_deep_sleep_action(template_arg)
    type = EnterDeepSleepAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_DEEP_SLEEP_PREVENT = 'deep_sleep.prevent'
Exemple #20
0
        add(stepper_var.set_acceleration(config[CONF_ACCELERATION]))
    if CONF_DECELERATION in config:
        add(stepper_var.set_deceleration(config[CONF_DECELERATION]))
    if CONF_MAX_SPEED in config:
        add(stepper_var.set_max_speed(config[CONF_MAX_SPEED]))


def setup_stepper(stepper_var, config):
    add_job(setup_stepper_core_, stepper_var, config)


BUILD_FLAGS = '-DUSE_STEPPER'

CONF_STEPPER_SET_TARGET = 'stepper.set_target'
STEPPER_SET_TARGET_ACTION_SCHEMA = vol.Schema({
    vol.Required(CONF_ID): cv.use_variable_id(Stepper),
    vol.Required(CONF_TARGET): cv.templatable(cv.int_),
})


@ACTION_REGISTRY.register(CONF_STEPPER_SET_TARGET, STEPPER_SET_TARGET_ACTION_SCHEMA)
def stepper_set_target_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_set_target_action(template_arg)
    type = SetTargetAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_TARGET], arg_type, int32):
        yield None
    add(action.set_target(template_))
Exemple #21
0

def validate_mux(value):
    value = cv.string(value).upper()
    value = value.replace(' ', '_')
    return cv.one_of(*MUX)(value)


PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        vol.Required(CONF_MULTIPLEXER):
        validate_mux,
        vol.Required(CONF_GAIN):
        validate_gain,
        cv.GenerateID(CONF_ADS1115_ID):
        cv.use_variable_id(ADS1115Component),
        vol.Optional(CONF_UPDATE_INTERVAL):
        cv.positive_time_period_milliseconds,
    }))


def to_code(config):
    hub = None
    for hub in get_variable(config[CONF_ADS1115_ID]):
        yield

    mux = MUX[config[CONF_MULTIPLEXER]]
    gain = GAIN[config[CONF_GAIN]]
    rhs = hub.get_sensor(config[CONF_NAME], mux, gain,
                         config.get(CONF_UPDATE_INTERVAL))
    sensor.register_sensor(rhs, config)
Exemple #22
0
from esphomeyaml.components import light, output
from esphomeyaml.components.light.rgbww import validate_cold_white_colder, \
    validate_color_temperature
from esphomeyaml.const import CONF_COLD_WHITE, CONF_COLD_WHITE_COLOR_TEMPERATURE, \
    CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, CONF_MAKE_ID, \
    CONF_NAME, CONF_WARM_WHITE, CONF_WARM_WHITE_COLOR_TEMPERATURE
from esphomeyaml.cpp_generator import get_variable, variable
from esphomeyaml.cpp_helpers import setup_component
from esphomeyaml.cpp_types import App

PLATFORM_SCHEMA = cv.nameable(
    light.LIGHT_PLATFORM_SCHEMA.extend({
        cv.GenerateID(CONF_MAKE_ID):
        cv.declare_variable_id(light.MakeLight),
        vol.Required(CONF_COLD_WHITE):
        cv.use_variable_id(output.FloatOutput),
        vol.Required(CONF_WARM_WHITE):
        cv.use_variable_id(output.FloatOutput),
        vol.Required(CONF_COLD_WHITE_COLOR_TEMPERATURE):
        validate_color_temperature,
        vol.Required(CONF_WARM_WHITE_COLOR_TEMPERATURE):
        validate_color_temperature,
        vol.Optional(CONF_GAMMA_CORRECT):
        cv.positive_float,
        vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH):
        cv.positive_time_period_milliseconds,
        vol.Optional(CONF_EFFECTS):
        light.validate_effects(light.MONOCHROMATIC_EFFECTS),
    }).extend(cv.COMPONENT_SCHEMA.schema), validate_cold_white_colder)

Exemple #23
0
    setup_switch_core_(switch_var, mqtt_var, config)


def register_switch(var, config):
    switch_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
    rhs = App.register_switch(switch_var)
    mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True)
    setup_switch_core_(switch_var, mqtt_var, config)


BUILD_FLAGS = '-DUSE_SWITCH'

CONF_SWITCH_TOGGLE = 'switch.toggle'
SWITCH_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(Switch),
})


@ACTION_REGISTRY.register(CONF_SWITCH_TOGGLE, SWITCH_TOGGLE_ACTION_SCHEMA)
def switch_toggle_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_toggle_action(template_arg)
    type = ToggleAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_SWITCH_TURN_OFF = 'switch.turn_off'
SWITCH_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
Exemple #24
0
    CONF_RESOLUTION
from esphomeyaml.helpers import HexIntLiteral, get_variable

DallasTemperatureSensor = sensor.sensor_ns.class_(
    'DallasTemperatureSensor', sensor.EmptyPollingParentSensor)

PLATFORM_SCHEMA = cv.nameable(
    sensor.SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(DallasTemperatureSensor),
        vol.Exclusive(CONF_ADDRESS, 'dallas'):
        cv.hex_int,
        vol.Exclusive(CONF_INDEX, 'dallas'):
        cv.positive_int,
        cv.GenerateID(CONF_DALLAS_ID):
        cv.use_variable_id(DallasComponent),
        vol.Optional(CONF_RESOLUTION):
        vol.All(vol.Coerce(int), vol.Range(min=9, max=12)),
    }), cv.has_at_least_one_key(CONF_ADDRESS, CONF_INDEX))


def to_code(config):
    for hub in get_variable(config[CONF_DALLAS_ID]):
        yield
    if CONF_ADDRESS in config:
        address = HexIntLiteral(config[CONF_ADDRESS])
        rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address,
                                         config.get(CONF_RESOLUTION))
    else:
        rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX],
                                       config.get(CONF_RESOLUTION))
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.components import light
from esphomeyaml.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, CONF_MAKE_ID, \
    CONF_NAME, CONF_OUTPUT
from esphomeyaml.helpers import App, get_variable, variable

PLATFORM_SCHEMA = cv.nameable(light.LIGHT_PLATFORM_SCHEMA.extend({
    cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight),
    vol.Required(CONF_OUTPUT): cv.use_variable_id(None),
    vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float,
    vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds,
}))


def to_code(config):
    output = None
    for output in get_variable(config[CONF_OUTPUT]):
        yield
    rhs = App.make_monochromatic_light(config[CONF_NAME], output)
    light_struct = variable(config[CONF_MAKE_ID], rhs)
    light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config)
Exemple #26
0

def validate_pmsx003_sensors(value):
    for key, types in SENSORS_TO_TYPE.iteritems():
        if key in value and value[CONF_TYPE] not in types:
            raise vol.Invalid(u"{} does not have {} sensor!".format(
                value[CONF_TYPE], key))
    return value


PLATFORM_SCHEMA = vol.All(
    sensor.PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(PMSX003Component),
        cv.GenerateID(CONF_UART_ID):
        cv.use_variable_id(UARTComponent),
        vol.Required(CONF_TYPE):
        vol.All(vol.Upper, cv.one_of(*PMSX003_TYPES)),
        vol.Optional(CONF_PM_1_0):
        cv.nameable(sensor.SENSOR_SCHEMA),
        vol.Optional(CONF_PM_2_5):
        cv.nameable(sensor.SENSOR_SCHEMA),
        vol.Optional(CONF_PM_10_0):
        cv.nameable(sensor.SENSOR_SCHEMA),
        vol.Optional(CONF_TEMPERATURE):
        cv.nameable(sensor.SENSOR_SCHEMA),
        vol.Optional(CONF_HUMIDITY):
        cv.nameable(sensor.SENSOR_SCHEMA),
        vol.Optional(CONF_FORMALDEHYDE):
        cv.nameable(sensor.SENSOR_SCHEMA),
    }), cv.has_at_least_one_key(*SENSORS_TO_TYPE))
Exemple #27
0
import esphomeyaml.config_validation as cv
from esphomeyaml.components import binary_sensor, uart
from esphomeyaml.const import CONF_ID, CONF_UART_ID
from esphomeyaml.helpers import App, Pvariable, get_variable, setup_component, Component

DEPENDENCIES = ['uart']

RDM6300Component = binary_sensor.binary_sensor_ns.class_(
    'RDM6300Component', Component, uart.UARTDevice)

CONFIG_SCHEMA = vol.All(cv.ensure_list_not_empty, [
    vol.Schema({
        cv.GenerateID():
        cv.declare_variable_id(RDM6300Component),
        cv.GenerateID(CONF_UART_ID):
        cv.use_variable_id(uart.UARTComponent),
    }).extend(cv.COMPONENT_SCHEMA.schema)
])


def to_code(config):
    for conf in config:
        for uart_ in get_variable(conf[CONF_UART_ID]):
            yield
        rhs = App.make_rdm6300_component(uart_)
        var = Pvariable(conf[CONF_ID], rhs)
        setup_component(var, conf)


BUILD_FLAGS = '-DUSE_RDM6300'
Exemple #28
0
                              "long.")
        try:
            x = int(x, 16)
        except ValueError:
            raise vol.Invalid("Valid characters for parts of a UID are 0123456789ABCDEF.")
        if x < 0 or x > 255:
            raise vol.Invalid("Valid values for UID parts (separated by '-') are 00 to FF")
    return value


PN532BinarySensor = binary_sensor.binary_sensor_ns.class_('PN532BinarySensor',
                                                          binary_sensor.BinarySensor)

PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
    cv.GenerateID(): cv.declare_variable_id(PN532BinarySensor),
    vol.Required(CONF_UID): validate_uid,
    cv.GenerateID(CONF_PN532_ID): cv.use_variable_id(PN532Component)
}))


def to_code(config):
    for hub in get_variable(config[CONF_PN532_ID]):
        yield
    addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')]
    rhs = hub.make_tag(config[CONF_NAME], ArrayInitializer(*addr, multiline=False))
    binary_sensor.register_binary_sensor(rhs, config)


def to_hass_config(data, config):
    return binary_sensor.core_to_hass_config(data, config)
Exemple #29
0
import voluptuous as vol

import esphomeyaml.config_validation as cv
from esphomeyaml.components.power_supply import PowerSupplyComponent
from esphomeyaml.const import CONF_INVERTED, CONF_MAX_POWER, CONF_POWER_SUPPLY
from esphomeyaml.helpers import add, esphomelib_ns, get_variable

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({})

BINARY_OUTPUT_SCHEMA = vol.Schema({
    vol.Optional(CONF_POWER_SUPPLY):
    cv.use_variable_id(PowerSupplyComponent),
    vol.Optional(CONF_INVERTED):
    cv.boolean,
})

BINARY_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    BINARY_OUTPUT_SCHEMA.schema)

FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({
    vol.Optional(CONF_MAX_POWER):
    cv.percentage,
})

FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    FLOAT_OUTPUT_SCHEMA.schema)

output_ns = esphomelib_ns.namespace('output')


def setup_output_platform_(obj, config, skip_power_supply=False):
Exemple #30
0
from esphomeyaml.const import CONF_NAME, CONF_UID
from esphomeyaml.helpers import get_variable

DEPENDENCIES = ['rdm6300']

CONF_RDM6300_ID = 'rdm6300_id'

RDM6300BinarySensor = binary_sensor.binary_sensor_ns.class_(
    'RDM6300BinarySensor', binary_sensor.BinarySensor)

PLATFORM_SCHEMA = cv.nameable(
    binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
        cv.GenerateID():
        cv.declare_variable_id(RDM6300BinarySensor),
        vol.Required(CONF_UID):
        cv.uint32_t,
        cv.GenerateID(CONF_RDM6300_ID):
        cv.use_variable_id(rdm6300.RDM6300Component)
    }))


def to_code(config):
    for hub in get_variable(config[CONF_RDM6300_ID]):
        yield
    rhs = hub.make_card(config[CONF_NAME], config[CONF_UID])
    binary_sensor.register_binary_sensor(rhs, config)


def to_hass_config(data, config):
    return binary_sensor.core_to_hass_config(data, config)