Exemplo n.º 1
0
def to_code(config):
    rhs = App.make_template_cover(config[CONF_NAME])
    var = Pvariable(config[CONF_ID], rhs)

    cover.setup_cover(var, config)
    setup_component(var, config)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(
                                            cover.CoverState)):
            yield
        add(var.set_state_lambda(template_))
    if CONF_OPEN_ACTION in config:
        automation.build_automations(var.get_open_trigger(), [],
                                     config[CONF_OPEN_ACTION])
    if CONF_CLOSE_ACTION in config:
        automation.build_automations(var.get_close_trigger(), [],
                                     config[CONF_CLOSE_ACTION])
    if CONF_STOP_ACTION in config:
        automation.build_automations(var.get_stop_trigger(), [],
                                     config[CONF_STOP_ACTION])
    if CONF_OPTIMISTIC in config:
        add(var.set_optimistic(config[CONF_OPTIMISTIC]))
    if CONF_ASSUMED_STATE in config:
        add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
Exemplo n.º 2
0
def setup_filter(config):
    if CONF_OFFSET in config:
        yield OffsetFilter.new(config[CONF_OFFSET])
    elif CONF_MULTIPLY in config:
        yield MultiplyFilter.new(config[CONF_MULTIPLY])
    elif CONF_FILTER_OUT in config:
        yield FilterOutValueFilter.new(config[CONF_FILTER_OUT])
    elif CONF_FILTER_NAN in config:
        yield FilterOutNANFilter.new()
    elif CONF_SLIDING_WINDOW_MOVING_AVERAGE in config:
        conf = config[CONF_SLIDING_WINDOW_MOVING_AVERAGE]
        yield SlidingWindowMovingAverageFilter.new(conf[CONF_WINDOW_SIZE], conf[CONF_SEND_EVERY],
                                                   conf.get(CONF_SEND_FIRST_AT))
    elif CONF_EXPONENTIAL_MOVING_AVERAGE in config:
        conf = config[CONF_EXPONENTIAL_MOVING_AVERAGE]
        yield ExponentialMovingAverageFilter.new(conf[CONF_ALPHA], conf[CONF_SEND_EVERY])
    elif CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA], [(float_, 'x')],
                                      return_type=optional.template(float_)):
            yield None
        yield LambdaFilter.new(lambda_)
    elif CONF_THROTTLE in config:
        yield ThrottleFilter.new(config[CONF_THROTTLE])
    elif CONF_DELTA in config:
        yield DeltaFilter.new(config[CONF_DELTA])
    elif CONF_OR in config:
        for filters in setup_filters(config[CONF_OR]):
            yield None
        yield OrFilter.new(filters)
    elif CONF_HEARTBEAT in config:
        yield App.register_component(HeartbeatFilter.new(config[CONF_HEARTBEAT]))
    elif CONF_DEBOUNCE in config:
        yield App.register_component(DebounceFilter.new(config[CONF_DEBOUNCE]))
    elif CONF_UNIQUE in config:
        yield UniqueFilter.new()
Exemplo n.º 3
0
def to_code(config):
    rhs = App.make_template_switch(config[CONF_NAME])
    template = Pvariable(config[CONF_ID], rhs)

    switch.setup_switch(template, config)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(bool_)):
            yield
        add(template.set_state_lambda(template_))
    if CONF_TURN_OFF_ACTION in config:
        automation.build_automations(template.get_turn_off_trigger(), [],
                                     config[CONF_TURN_OFF_ACTION])
    if CONF_TURN_ON_ACTION in config:
        automation.build_automations(template.get_turn_on_trigger(), [],
                                     config[CONF_TURN_ON_ACTION])
    if CONF_OPTIMISTIC in config:
        add(template.set_optimistic(config[CONF_OPTIMISTIC]))
    if CONF_ASSUMED_STATE in config:
        add(template.set_assumed_state(config[CONF_ASSUMED_STATE]))

    if CONF_RESTORE_STATE in config:
        add(template.set_restore_state(config[CONF_RESTORE_STATE]))

    setup_component(template, config)
Exemplo n.º 4
0
def to_code(config):
    rhs = App.make_template_binary_sensor(config[CONF_NAME])
    var = Pvariable(config[CONF_ID], rhs)
    binary_sensor.setup_binary_sensor(var, config)
    setup_component(var, config)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(bool_)):
            yield
        add(var.set_template(template_))
Exemplo n.º 5
0
def to_code(config):
    rhs = App.make_template_text_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL))
    template = Pvariable(config[CONF_ID], rhs)
    text_sensor.setup_text_sensor(template, config)
    setup_component(template, config)

    if CONF_LAMBDA in config:
        for template_ in process_lambda(config[CONF_LAMBDA], [],
                                        return_type=optional.template(std_string)):
            yield
        add(template.set_template(template_))
Exemplo n.º 6
0
def setup_filter(config):
    if CONF_INVERT in config:
        yield InvertFilter.new()
    elif CONF_DELAYED_OFF in config:
        yield App.register_component(DelayedOffFilter.new(config[CONF_DELAYED_OFF]))
    elif CONF_DELAYED_ON in config:
        yield App.register_component(DelayedOnFilter.new(config[CONF_DELAYED_ON]))
    elif CONF_LAMBDA in config:
        for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')],
                                      return_type=optional.template(bool_)):
            yield None
        yield LambdaFilter.new(lambda_)