How to use the yeelight.decorator.FunctionMaker.create function in yeelight

To help you get started, we’ve selected a few yeelight examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skorokithakis / python-yeelight / yeelight / decorator.py View on Github external
def decorate(func, caller):
    """
    decorate(func, caller) decorates a function using a caller.
    """
    evaldict = dict(_call_=caller, _func_=func)
    fun = FunctionMaker.create(func, "return _call_(_func_, %(shortsignature)s)", evaldict, __wrapped__=func)
    if hasattr(func, "__qualname__"):
        fun.__qualname__ = func.__qualname__
    return fun
github skorokithakis / python-yeelight / yeelight / decorator.py View on Github external
name = caller.__name__.lower()
        doc = "decorator(%s) converts functions/generators into " "factories of %s objects" % (
            caller.__name__,
            caller.__name__,
        )
    elif inspect.isfunction(caller):
        if caller.__name__ == "":
            name = "_lambda_"
        else:
            name = caller.__name__
        doc = caller.__doc__
    else:  # assume caller is an object with a __call__ method
        name = caller.__class__.__name__.lower()
        doc = caller.__call__.__doc__
    evaldict = dict(_call_=caller, _decorate_=decorate)
    return FunctionMaker.create(
        "%s(func)" % name,
        "return _decorate_(func, _call_)",
        evaldict,
        doc=doc,
        module=caller.__module__,
        __wrapped__=caller,
    )
github skorokithakis / python-yeelight / yeelight / decorator.py View on Github external
f = typemap[types]
            except KeyError:
                pass
            else:
                return f(*args, **kw)
            combinations = itertools.product(*ancestors(*types))
            next(combinations)  # the first one has been already tried
            for types_ in combinations:
                f = typemap.get(types_)
                if f is not None:
                    return f(*args, **kw)

            # else call the default implementation
            return func(*args, **kw)

        return FunctionMaker.create(
            func,
            "return _f_(%s, %%(shortsignature)s)" % dispatch_str,
            dict(_f_=_dispatch),
            register=register,
            default=func,
            typemap=typemap,
            vancestors=vancestors,
            ancestors=ancestors,
            dispatch_info=dispatch_info,
            __wrapped__=func,
        )
github skorokithakis / python-yeelight / yeelight / decorator.py View on Github external
def __call__(self, func):
        """Context manager decorator"""
        return FunctionMaker.create(
            func, "with _self_: return _func_(%(shortsignature)s)", dict(_self_=self, _func_=func), __wrapped__=func
        )