Skip to content

waiter() function #3

Description

@qurm

Hi,

I came across this project while looking for a fully Python-based SMA inverter tool, that would be easier to maintain & modify than the various C language sbfspot projects. It looks like a well structured code base - thanks for your efforts!

I have spent some hours understanding and commenting, but there's one area that puzzles me still. Can you explain the decorator function below, and how it works with the various tx & rx functions & the @waiter decorator? What is the purpose of creating the various _waitcond attributes and the waitvar ?

def waiter(fn):
    """ Adds wait conditions to itself, used with connection.wait() to wait for packets
    :param fn: like rx_raw, rx_outer, rx_ppp from the connection class
    :return: waitfn()
    """
    def waitfn(self, *args):
        fn(self, *args)
        if hasattr(self, '__waitcond_' + fn.__name__):
            wc = getattr(self, '__waitcond_' + fn.__name__)
            if wc is None:
                self.waitvar = args
            else:
                self.waitvar = wc(*args)
    return waitfn

Thanks, Andy

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions