From 79abec75315c93c5d8e6c5589af93c438e502ea9 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Wed, 27 Apr 2022 14:50:48 +0100 Subject: [PATCH] now using sendtext to apply a profile now using sendtext to apply a profile --- vbancmd/util.py | 21 +++++++++++++++++++++ vbancmd/vbancmd.py | 12 ++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/vbancmd/util.py b/vbancmd/util.py index beab434..0b43f4c 100644 --- a/vbancmd/util.py +++ b/vbancmd/util.py @@ -17,3 +17,24 @@ def cache(func): return res return wrapper + + +def script(func): + """Convert dictionary to script""" + + def wrapper(*args): + remote, script = args + if isinstance(script, dict): + params = "" + for key, val in script.items(): + obj, m2, *rem = key.split("-") + index = int(m2) if m2.isnumeric() else int(*rem) + params += ";".join( + f"{obj}{f'.{m2}stream' if not m2.isnumeric() else ''}[{index}].{k}={int(v) if isinstance(v, bool) else v}" + for k, v in val.items() + ) + params += ";" + script = params + return func(remote, script) + + return wrapper diff --git a/vbancmd/vbancmd.py b/vbancmd/vbancmd.py index c67d283..11471d2 100644 --- a/vbancmd/vbancmd.py +++ b/vbancmd/vbancmd.py @@ -18,6 +18,7 @@ from .dataclass import ( from .strip import InputStrip from .bus import OutputBus from .command import Command +from .util import script class VbanCmd(abc.ABC): @@ -29,7 +30,6 @@ class VbanCmd(abc.ABC): self._channel = kwargs["channel"] self._delay = kwargs["delay"] self._sync = kwargs["sync"] - self._ratelimit = kwargs["ratelimit"] # fmt: off self._bps_opts = [ 0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250, @@ -203,12 +203,10 @@ class VbanCmd(abc.ABC): count = int.from_bytes(self._text_header.framecounter, "little") + 1 self._text_header.framecounter = count.to_bytes(4, "little") self.cache[f"{id_}.{param}"] = val - sleep(self._delay) - if self._sync: + if self._sync or self.in_apply: sleep(self._delay) - # if self.in_apply: - # sleep(self._ratelimit) + @script def sendtext(self, cmd): """Sends a multiple parameter string over a network.""" self.set_rt(cmd) @@ -253,7 +251,6 @@ class VbanCmd(abc.ABC): else: raise ValueError(obj) target.apply(submapping) - # sleep(self._ratelimit) self.in_apply = False def apply_profile(self, name: str): @@ -268,7 +265,7 @@ class VbanCmd(abc.ABC): else: base[key] = profile[key] profile = base - self.apply(profile) + self.sendtext(profile) except KeyError: raise VMCMDErrors(f"Unknown profile: {self.kind.id}/{name}") @@ -320,7 +317,6 @@ def _make_remote(kind: NamedTuple) -> VbanCmd: "channel": 0, "delay": 0.001, "sync": False, - "ratelimit": 0.025, } kwargs = defaultkwargs | kwargs VbanCmd.__init__(self, **kwargs)