mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2024-11-15 17:10:46 +00:00
Update vbancmd.py
add ratelimit kwarg. applies only to multiset operations (apply, profile_apply).
This commit is contained in:
parent
7fb026ca1e
commit
c6b9fa6112
@ -29,6 +29,7 @@ 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,
|
||||
@ -66,6 +67,7 @@ class VbanCmd(abc.ABC):
|
||||
self.running = True
|
||||
self._pdirty = False
|
||||
self.cache = {}
|
||||
self.in_apply = False
|
||||
|
||||
def __enter__(self):
|
||||
self.login()
|
||||
@ -203,6 +205,8 @@ class VbanCmd(abc.ABC):
|
||||
self.cache[f"{id_}.{param}"] = val
|
||||
if self._sync:
|
||||
sleep(self._delay)
|
||||
if self.in_apply:
|
||||
sleep(self._ratelimit)
|
||||
|
||||
def sendtext(self, cmd):
|
||||
"""Sends a multiple parameter string over a network."""
|
||||
@ -237,6 +241,7 @@ class VbanCmd(abc.ABC):
|
||||
|
||||
def apply(self, mapping: dict):
|
||||
"""Sets all parameters of a di"""
|
||||
self.in_apply = True
|
||||
for key, submapping in mapping.items():
|
||||
obj, index = key.split("-")
|
||||
|
||||
@ -247,8 +252,8 @@ class VbanCmd(abc.ABC):
|
||||
else:
|
||||
raise ValueError(obj)
|
||||
target.apply(submapping)
|
||||
if not self._sync:
|
||||
sleep(self._delay * 30)
|
||||
sleep(self._ratelimit)
|
||||
self.in_apply = False
|
||||
|
||||
def apply_profile(self, name: str):
|
||||
try:
|
||||
@ -258,7 +263,7 @@ class VbanCmd(abc.ABC):
|
||||
del profile["extends"]
|
||||
for key in profile.keys():
|
||||
if key in base:
|
||||
base[key] |= profile[key]
|
||||
base[key] = base[key] | profile[key]
|
||||
else:
|
||||
base[key] = profile[key]
|
||||
profile = base
|
||||
@ -314,6 +319,7 @@ def _make_remote(kind: NamedTuple) -> VbanCmd:
|
||||
"channel": 0,
|
||||
"delay": 0.001,
|
||||
"sync": False,
|
||||
"ratelimit": 0.025,
|
||||
}
|
||||
kwargs = defaultkwargs | kwargs
|
||||
VbanCmd.__init__(self, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user