Esempio n. 1
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)
Esempio n. 2
0
def to_code(config):
    for output_ in get_variable(config[CONF_OUTPUT]):
        yield
    rhs = App.make_output_switch(config[CONF_NAME], output_)
    switch_ = Pvariable(config[CONF_ID], rhs)

    switch.setup_switch(switch_, config)
    setup_component(switch, config)
Esempio n. 3
0
def to_code(config):
    for uart_ in get_variable(config[CONF_UART_ID]):
        yield
    data = config[CONF_DATA]
    if isinstance(data, str):
        data = [HexInt(ord(x)) for x in data]
    rhs = App.make_uart_switch(uart_, config[CONF_NAME], data)
    var = Pvariable(config[CONF_ID], rhs)
    switch.setup_switch(var, config)
Esempio n. 4
0
def to_code(config):
    for pin in gpio_output_pin_expression(config[CONF_PIN]):
        yield
    rhs = App.make_gpio_switch(config[CONF_NAME], pin)
    gpio = Pvariable(config[CONF_ID], rhs)

    if CONF_RESTORE_MODE in config:
        add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]]))

    if CONF_INTERLOCK in config:
        interlock = []
        for it in config[CONF_INTERLOCK]:
            for lock in get_variable(it):
                yield
            interlock.append(lock)
        add(gpio.set_interlock(interlock))

    switch.setup_switch(gpio, config)
    setup_component(gpio, config)
Esempio n. 5
0
def to_code(config):
    rhs = App.make_restart_switch(config[CONF_NAME])
    restart = Pvariable(config[CONF_ID], rhs)
    switch.setup_switch(restart, config)
Esempio n. 6
0
def to_code(config):
    rhs = App.make_shutdown_switch(config[CONF_NAME])
    shutdown = Pvariable(config[CONF_ID], rhs)
    switch.setup_switch(shutdown, config)