예제 #1
0
    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_))
    yield action
예제 #2
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
        add(action.set_transition_length(template_))
예제 #3
0
        if CONF_QOS in conf:
            add(trigger.set_qos(conf[CONF_QOS]))
        if CONF_PAYLOAD in conf:
            add(trigger.set_payload(conf[CONF_PAYLOAD]))
        automation.build_automation(trigger, std_string, conf)

    for conf in config.get(CONF_ON_JSON_MESSAGE, []):
        rhs = mqtt.make_json_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
        automation.build_automation(trigger, JsonObjectConstRef, conf)


CONF_MQTT_PUBLISH = 'mqtt.publish'
MQTT_PUBLISH_ACTION_SCHEMA = 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),
})


@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH, MQTT_PUBLISH_ACTION_SCHEMA)
def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg):
    rhs = App.Pget_mqtt_client().Pmake_publish_action(template_arg)
    type = MQTTPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_TOPIC], arg_type, std_string):
예제 #4
0
ACTION_KEYS = [
    CONF_DELAY, CONF_MQTT_PUBLISH, CONF_LIGHT_TOGGLE, CONF_LIGHT_TURN_OFF,
    CONF_LIGHT_TURN_ON, CONF_SWITCH_TOGGLE, CONF_SWITCH_TURN_OFF,
    CONF_SWITCH_TURN_ON, CONF_LAMBDA, CONF_COVER_OPEN, CONF_COVER_CLOSE,
    CONF_COVER_STOP, CONF_FAN_TOGGLE, CONF_FAN_TURN_OFF, CONF_FAN_TURN_ON,
    CONF_OUTPUT_TURN_ON, CONF_OUTPUT_TURN_OFF, CONF_OUTPUT_SET_LEVEL, CONF_IF,
    CONF_DEEP_SLEEP_ENTER, CONF_DEEP_SLEEP_PREVENT
]

ACTIONS_SCHEMA = vol.All(cv.ensure_list, [
    vol.All(
        {
            cv.GenerateID(CONF_ACTION_ID):
            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),
예제 #5
0
@ACTION_REGISTRY.register(CONF_FAN_TURN_OFF, FAN_TURN_OFF_ACTION_SCHEMA)
def fan_turn_off_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_turn_off_action(template_arg)
    type = TurnOffAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_FAN_TURN_ON = 'fan.turn_on'
FAN_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID):
    cv.use_variable_id(None),
    vol.Optional(CONF_OSCILLATING):
    cv.templatable(cv.boolean),
    vol.Optional(CONF_SPEED):
    cv.templatable(validate_fan_speed),
})


@ACTION_REGISTRY.register(CONF_FAN_TURN_ON, FAN_TURN_ON_ACTION_SCHEMA)
def fan_turn_on_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_turn_on_action(template_arg)
    type = TurnOnAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    if CONF_OSCILLATING in config:
        for template_ in templatable(config[CONF_OSCILLATING], arg_type,
예제 #6
0
CONF_FAN_TURN_ON = 'fan.turn_on'

ACTION_KEYS = [
    CONF_DELAY, CONF_MQTT_PUBLISH, CONF_LIGHT_TOGGLE, CONF_LIGHT_TURN_OFF,
    CONF_LIGHT_TURN_ON, CONF_SWITCH_TOGGLE, CONF_SWITCH_TURN_OFF,
    CONF_SWITCH_TURN_ON, CONF_LAMBDA, CONF_COVER_OPEN, CONF_COVER_CLOSE,
    CONF_COVER_STOP, CONF_FAN_TOGGLE, CONF_FAN_TURN_OFF, CONF_FAN_TURN_ON
]

ACTIONS_SCHEMA = vol.All(cv.ensure_list, [
    vol.All(
        {
            cv.GenerateID(CONF_ACTION_ID):
            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):
            vol.Schema({
                vol.Required(CONF_ID):
                cv.use_variable_id(None),
                vol.Optional(CONF_TRANSITION_LENGTH):
                cv.templatable(cv.positive_time_period_milliseconds),
예제 #7
0
OR_CONDITION_SCHEMA = validate_recursive_condition


@CONDITION_REGISTRY.register(CONF_OR, OR_CONDITION_SCHEMA)
def or_condition_to_code(config, condition_id, arg_type, template_arg):
    for conditions in build_conditions(config, arg_type):
        yield
    rhs = OrCondition.new(template_arg, conditions)
    type = OrCondition.template(template_arg)
    yield Pvariable(condition_id, rhs, type=type)


RANGE_CONDITION_SCHEMA = vol.All(
    vol.Schema({
        vol.Optional(CONF_ABOVE): cv.templatable(cv.float_),
        vol.Optional(CONF_BELOW): cv.templatable(cv.float_),
    }), cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW))


@CONDITION_REGISTRY.register(CONF_RANGE, RANGE_CONDITION_SCHEMA)
def range_condition_to_code(config, condition_id, arg_type, template_arg):
    for conditions in build_conditions(config, arg_type):
        yield
    rhs = RangeCondition.new(template_arg, conditions)
    type = RangeCondition.template(template_arg)
    condition = Pvariable(condition_id, rhs, type=type)
    if CONF_ABOVE in config:
        for template_ in templatable(config[CONF_ABOVE], arg_type, float_):
            yield
        condition.set_min(template_)
예제 #8
0
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(LightState),
    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
예제 #9
0
        add(mqtt.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT]))

    for conf in config.get(CONF_ON_MESSAGE, []):
        rhs = mqtt.make_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
        automation.build_automation(trigger, std_string, conf)

    for conf in config.get(CONF_ON_JSON_MESSAGE, []):
        rhs = mqtt.make_json_message_trigger(conf[CONF_TOPIC], conf[CONF_QOS])
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
        automation.build_automation(trigger, JsonObjectConstRef, conf)


CONF_MQTT_PUBLISH = 'mqtt.publish'
MQTT_PUBLISH_ACTION_SCHEMA = 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),
})


@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH, MQTT_PUBLISH_ACTION_SCHEMA)
def mqtt_publish_action_to_code(config, action_id, arg_type):
    template_arg = TemplateArguments(arg_type)
    rhs = App.Pget_mqtt_client().Pmake_publish_action(template_arg)
    type = MQTTPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_TOPIC], arg_type, std_string):
        yield None
    add(action.set_topic(template_))
예제 #10
0
})


@ACTION_REGISTRY.register(CONF_FAN_TURN_OFF, FAN_TURN_OFF_ACTION_SCHEMA)
def fan_turn_off_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_turn_off_action(template_arg)
    type = TurnOffAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_FAN_TURN_ON = 'fan.turn_on'
FAN_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
    vol.Required(CONF_ID): cv.use_variable_id(FanState),
    vol.Optional(CONF_OSCILLATING): cv.templatable(cv.boolean),
    vol.Optional(CONF_SPEED): cv.templatable(cv.one_of(*FAN_SPEEDS, upper=True)),
})


@ACTION_REGISTRY.register(CONF_FAN_TURN_ON, FAN_TURN_ON_ACTION_SCHEMA)
def fan_turn_on_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_turn_on_action(template_arg)
    type = TurnOnAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    if CONF_OSCILLATING in config:
        for template_ in templatable(config[CONF_OSCILLATING], arg_type, bool_):
            yield None
        add(action.set_oscillating(template_))
예제 #11
0
Condition = esphomelib_ns.class_('Condition')
AndCondition = esphomelib_ns.class_('AndCondition', Condition)
OrCondition = esphomelib_ns.class_('OrCondition', Condition)
RangeCondition = esphomelib_ns.class_('RangeCondition', Condition)
LambdaCondition = esphomelib_ns.class_('LambdaCondition', Condition)

CONDITIONS_SCHEMA = vol.All(cv.ensure_list, [
    cv.templatable({
        cv.GenerateID(CONF_CONDITION_ID):
        cv.declare_variable_id(Condition),
        vol.Optional(CONF_AND):
        validate_recursive_condition,
        vol.Optional(CONF_OR):
        validate_recursive_condition,
        vol.Optional(CONF_RANGE):
        vol.All(
            vol.Schema({
                vol.Optional(CONF_ABOVE): vol.Coerce(float),
                vol.Optional(CONF_BELOW): vol.Coerce(float),
            }), cv.has_at_least_one_key(CONF_ABOVE, CONF_BELOW)),
        vol.Optional(CONF_LAMBDA):
        cv.lambda_,
    })
])


def validate_automation(extra_schema=None,
                        extra_validators=None,
                        single=False):
    schema = AUTOMATION_SCHEMA.extend(extra_schema or {})
예제 #12
0
@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_OFF, OUTPUT_TURN_OFF_ACTION)
def output_turn_off_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_turn_off_action(template_arg)
    type = TurnOffAction.template(arg_type)
    yield Pvariable(action_id, rhs, type=type)


CONF_OUTPUT_SET_LEVEL = 'output.set_level'
OUTPUT_SET_LEVEL_ACTION = vol.Schema({
    vol.Required(CONF_ID):
    cv.use_variable_id(FloatOutput),
    vol.Required(CONF_LEVEL):
    cv.templatable(cv.percentage),
})


@ACTION_REGISTRY.register(CONF_OUTPUT_SET_LEVEL, OUTPUT_SET_LEVEL_ACTION)
def output_set_level_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_level_action(template_arg)
    type = SetLevelAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_LEVEL], arg_type, float_):
        yield None
    add(action.set_level(template_))
    yield action