mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2025-01-18 18:40:47 +00:00
now using sendtext to apply a profile
now using sendtext to apply a profile
This commit is contained in:
parent
e8aa762c70
commit
79abec7531
@ -17,3 +17,24 @@ def cache(func):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
return wrapper
|
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
|
||||||
|
@ -18,6 +18,7 @@ from .dataclass import (
|
|||||||
from .strip import InputStrip
|
from .strip import InputStrip
|
||||||
from .bus import OutputBus
|
from .bus import OutputBus
|
||||||
from .command import Command
|
from .command import Command
|
||||||
|
from .util import script
|
||||||
|
|
||||||
|
|
||||||
class VbanCmd(abc.ABC):
|
class VbanCmd(abc.ABC):
|
||||||
@ -29,7 +30,6 @@ class VbanCmd(abc.ABC):
|
|||||||
self._channel = kwargs["channel"]
|
self._channel = kwargs["channel"]
|
||||||
self._delay = kwargs["delay"]
|
self._delay = kwargs["delay"]
|
||||||
self._sync = kwargs["sync"]
|
self._sync = kwargs["sync"]
|
||||||
self._ratelimit = kwargs["ratelimit"]
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
self._bps_opts = [
|
self._bps_opts = [
|
||||||
0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250,
|
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
|
count = int.from_bytes(self._text_header.framecounter, "little") + 1
|
||||||
self._text_header.framecounter = count.to_bytes(4, "little")
|
self._text_header.framecounter = count.to_bytes(4, "little")
|
||||||
self.cache[f"{id_}.{param}"] = val
|
self.cache[f"{id_}.{param}"] = val
|
||||||
sleep(self._delay)
|
if self._sync or self.in_apply:
|
||||||
if self._sync:
|
|
||||||
sleep(self._delay)
|
sleep(self._delay)
|
||||||
# if self.in_apply:
|
|
||||||
# sleep(self._ratelimit)
|
|
||||||
|
|
||||||
|
@script
|
||||||
def sendtext(self, cmd):
|
def sendtext(self, cmd):
|
||||||
"""Sends a multiple parameter string over a network."""
|
"""Sends a multiple parameter string over a network."""
|
||||||
self.set_rt(cmd)
|
self.set_rt(cmd)
|
||||||
@ -253,7 +251,6 @@ class VbanCmd(abc.ABC):
|
|||||||
else:
|
else:
|
||||||
raise ValueError(obj)
|
raise ValueError(obj)
|
||||||
target.apply(submapping)
|
target.apply(submapping)
|
||||||
# sleep(self._ratelimit)
|
|
||||||
self.in_apply = False
|
self.in_apply = False
|
||||||
|
|
||||||
def apply_profile(self, name: str):
|
def apply_profile(self, name: str):
|
||||||
@ -268,7 +265,7 @@ class VbanCmd(abc.ABC):
|
|||||||
else:
|
else:
|
||||||
base[key] = profile[key]
|
base[key] = profile[key]
|
||||||
profile = base
|
profile = base
|
||||||
self.apply(profile)
|
self.sendtext(profile)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise VMCMDErrors(f"Unknown profile: {self.kind.id}/{name}")
|
raise VMCMDErrors(f"Unknown profile: {self.kind.id}/{name}")
|
||||||
|
|
||||||
@ -320,7 +317,6 @@ def _make_remote(kind: NamedTuple) -> VbanCmd:
|
|||||||
"channel": 0,
|
"channel": 0,
|
||||||
"delay": 0.001,
|
"delay": 0.001,
|
||||||
"sync": False,
|
"sync": False,
|
||||||
"ratelimit": 0.025,
|
|
||||||
}
|
}
|
||||||
kwargs = defaultkwargs | kwargs
|
kwargs = defaultkwargs | kwargs
|
||||||
VbanCmd.__init__(self, **kwargs)
|
VbanCmd.__init__(self, **kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user