Beispiel #1
0
def range_condition_to_code(config, condition_id, template_arg, args):
    for conditions in build_conditions(config, template_arg, args):
        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], args, float_):
            yield
        condition.set_min(template_)
    if CONF_BELOW in config:
        for template_ in templatable(config[CONF_BELOW], args, float_):
            yield
        condition.set_max(template_)
    yield condition
Beispiel #2
0
def fan_turn_on_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_turn_on_action(template_arg)
    type = TurnOnAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    if CONF_OSCILLATING in config:
        for template_ in templatable(config[CONF_OSCILLATING], args, bool_):
            yield None
        add(action.set_oscillating(template_))
    if CONF_SPEED in config:
        for template_ in templatable(config[CONF_SPEED], args, FanSpeed):
            yield None
        if isinstance(template_, string_types):
            template_ = FAN_SPEEDS[template_]
        add(action.set_speed(template_))
    yield action
Beispiel #3
0
def delay_action_to_code(config, action_id, template_arg, args):
    rhs = App.register_component(DelayAction.new(template_arg))
    type = DelayAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config, args, uint32):
        yield
    add(action.set_delay(template_))
    yield action
Beispiel #4
0
def setup_sensor_core_(sensor_var, config):
    if CONF_INTERNAL in config:
        add(sensor_var.set_internal(config[CONF_INTERNAL]))
    if CONF_UNIT_OF_MEASUREMENT in config:
        add(
            sensor_var.set_unit_of_measurement(
                config[CONF_UNIT_OF_MEASUREMENT]))
    if CONF_ICON in config:
        add(sensor_var.set_icon(config[CONF_ICON]))
    if CONF_ACCURACY_DECIMALS in config:
        add(sensor_var.set_accuracy_decimals(config[CONF_ACCURACY_DECIMALS]))
    if CONF_FILTERS in config:
        for filters in setup_filters(config[CONF_FILTERS]):
            yield
        add(sensor_var.set_filters(filters))

    for conf in config.get(CONF_ON_VALUE, []):
        rhs = sensor_var.make_state_trigger()
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
        automation.build_automations(trigger, [(float_, 'x')], conf)
    for conf in config.get(CONF_ON_RAW_VALUE, []):
        rhs = sensor_var.make_raw_state_trigger()
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
        automation.build_automations(trigger, [(float_, 'x')], conf)
    for conf in config.get(CONF_ON_VALUE_RANGE, []):
        rhs = sensor_var.make_value_range_trigger()
        trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
        add(App.register_component(trigger))
        if CONF_ABOVE in conf:
            for template_ in templatable(conf[CONF_ABOVE], float_, float_):
                yield
            add(trigger.set_min(template_))
        if CONF_BELOW in conf:
            for template_ in templatable(conf[CONF_BELOW], float_, float_):
                yield
            add(trigger.set_max(template_))
        automation.build_automations(trigger, [(float_, 'x')], conf)

    mqtt_ = sensor_var.Pget_mqtt()
    if CONF_EXPIRE_AFTER in config:
        if config[CONF_EXPIRE_AFTER] is None:
            add(mqtt_.disable_expire_after())
        else:
            add(mqtt_.set_expire_after(config[CONF_EXPIRE_AFTER]))
    setup_mqtt_component(mqtt_, config)
Beispiel #5
0
def sensor_template_publish_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_sensor_publish_action(template_arg)
    type = SensorPublishAction.template(arg_type)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], arg_type, float_):
        yield None
    add(action.set_state(template_))
    yield action
Beispiel #6
0
def output_set_level_to_code(config, action_id, arg_type, template_arg):
    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
Beispiel #7
0
def stepper_set_target_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_set_target_action(template_arg)
    type = SetTargetAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_TARGET], args, int32):
        yield None
    add(action.set_target(template_))
    yield action
Beispiel #8
0
def stepper_report_position_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_report_position_action(template_arg)
    type = ReportPositionAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_POSITION], args, int32):
        yield None
    add(action.set_position(template_))
    yield action
Beispiel #9
0
def switch_template_publish_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_switch_publish_action(template_arg)
    type = SwitchPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], args, bool_):
        yield None
    add(action.set_state(template_))
    yield action
Beispiel #10
0
def text_sensor_template_publish_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_text_sensor_publish_action(template_arg)
    type = TextSensorPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_STATE], args, std_string):
        yield None
    add(action.set_state(template_))
    yield action
Beispiel #11
0
def servo_write_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = ServoWriteAction.new(template_arg, var)
    type = ServoWriteAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    for template_ in templatable(config[CONF_LEVEL], args, float_):
        yield None
    add(action.set_value(template_))
    yield action
Beispiel #12
0
def display_page_show_to_code(config, action_id, template_arg, args):
    type = DisplayPageShowAction.template(template_arg)
    action = Pvariable(action_id, type.new(), type=type)
    if isinstance(config[CONF_ID], core.Lambda):
        for template_ in templatable(config[CONF_ID], args, DisplayPagePtr):
            yield None
        add(action.set_page(template_))
    else:
        for var in get_variable(config[CONF_ID]):
            yield None
        add(action.set_page(var))
    yield action
Beispiel #13
0
def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_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_))

    for template_ in templatable(config[CONF_PAYLOAD], arg_type, std_string):
        yield None
    add(action.set_payload(template_))
    if CONF_QOS in config:
        for template_ in templatable(config[CONF_QOS], arg_type, uint8):
            yield
        add(action.set_qos(template_))
    if CONF_RETAIN in config:
        for template_ in templatable(config[CONF_RETAIN], arg_type, bool_):
            yield None
        add(action.set_retain(template_))
    yield action
Beispiel #14
0
def cover_template_publish_to_code(config, action_id, template_arg, args):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_cover_publish_action(template_arg)
    type = CoverPublishAction.template(template_arg)
    action = Pvariable(action_id, rhs, type=type)
    state = config[CONF_STATE]
    if isinstance(state, string_types):
        template_ = cover.COVER_STATES[state]
    else:
        for template_ in templatable(state, args, cover.CoverState):
            yield None
    add(action.set_state(template_))
    yield action
Beispiel #15
0
def mqtt_publish_json_action_to_code(config, action_id, arg_type,
                                     template_arg):
    for var in get_variable(config[CONF_ID]):
        yield None
    rhs = var.make_publish_json_action(template_arg)
    type = MQTTPublishJsonAction.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_))

    for lambda_ in process_lambda(config[CONF_PAYLOAD],
                                  [(arg_type, 'x'), (JsonObjectRef, 'root')],
                                  return_type=void):
        yield None
    add(action.set_payload(lambda_))
    if CONF_QOS in config:
        add(action.set_qos(config[CONF_QOS]))
    if CONF_RETAIN in config:
        add(action.set_retain(config[CONF_RETAIN]))
    yield action