Пример #1
0
 def new_func(config, action_id, template_arg, args):
     transmitter = yield cg.get_variable(config[CONF_TRANSMITTER_ID])
     var = cg.new_Pvariable(action_id, template_arg)
     cg.add(var.set_parent(transmitter))
     if CONF_REPEAT in config:
         conf = config[CONF_REPEAT]
         template_ = yield cg.templatable(conf[CONF_TIMES], args, cg.uint32)
         cg.add(var.set_send_times(template_))
         template_ = yield cg.templatable(conf[CONF_WAIT_TIME], args, cg.uint32)
         cg.add(var.set_send_wait(template_))
     yield coroutine(func)(var, config, args)
     yield var
Пример #2
0
def wrap_to_code(name, comp):
    coro = coroutine(comp.to_code)

    @functools.wraps(comp.to_code)
    @coroutine_with_priority(coro.priority)
    def wrapped(conf):
        cg.add(cg.LineComment(f"{name}:"))
        if comp.config_schema is not None:
            conf_str = yaml_util.dump(conf)
            conf_str = conf_str.replace('//', '')
            cg.add(cg.LineComment(indent(conf_str)))
        yield coro(conf)

    return wrapped
Пример #3
0
def wrap_to_code(name, comp):
    coro = coroutine(comp.to_code)

    @functools.wraps(comp.to_code)
    async def wrapped(conf):
        cg.add(cg.LineComment(f"{name}:"))
        if comp.config_schema is not None:
            conf_str = yaml_util.dump(conf)
            conf_str = conf_str.replace("//", "")
            cg.add(cg.LineComment(indent(conf_str)))
        await coro(conf)

    if hasattr(coro, "priority"):
        wrapped.priority = coro.priority
    return wrapped
Пример #4
0
def wrap_to_code(name, comp):
    coro = coroutine(comp.to_code)

    @functools.wraps(comp.to_code)
    @coroutine_with_priority(coro.priority)
    def wrapped(conf):
        cg.add(cg.LineComment(u"{}:".format(name)))
        if comp.config_schema is not None:
            conf_str = yaml_util.dump(conf)
            if IS_PY2:
                conf_str = conf_str.decode('utf-8')
            cg.add(cg.LineComment(indent(conf_str)))
        yield coro(conf)

    return wrapped
def gpio_pin_expression(conf):
    """Generate an expression for the given pin option.

    This is a coroutine, you must await it with a 'yield' expression!
    """
    if conf is None:
        return
    from esphome import pins
    for key, (func, _) in pins.PIN_SCHEMA_REGISTRY.items():
        if key in conf:
            yield coroutine(func)(conf)
            return

    number = conf[CONF_NUMBER]
    mode = conf[CONF_MODE]
    inverted = conf.get(CONF_INVERTED)
    yield GPIOPin.new(number, RawExpression(mode), inverted)
Пример #6
0
 def coroutine_fun(self):
     from esphome.core import coroutine
     return coroutine(self.fun)
Пример #7
0
 def new_func(config, dumper_id):
     var = cg.new_Pvariable(dumper_id)
     yield coroutine(func)(var, config)
     yield var
Пример #8
0
 def new_func(config):
     var = cg.new_Pvariable(config[CONF_TRIGGER_ID])
     yield register_listener(var, config)
     yield coroutine(func)(var, config)
     yield automation.build_automation(var, [(data_type, 'x')], config)
     yield var