mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2024-11-15 17:10:46 +00:00
add a delimiter end of request string in _set_rt
fixes bug if more than a single command in request packet. removed [{self.index}] from apply string. (duplicates)
This commit is contained in:
parent
197f81aa73
commit
ee3a871d23
@ -91,6 +91,8 @@ class IRemote(metaclass=ABCMeta):
|
||||
cmd = f"{self.identifier}.{param}"
|
||||
if cmd in self._remote.cache:
|
||||
return self._remote.cache.pop(cmd)
|
||||
if self._remote.sync:
|
||||
self._remote.clear_dirty()
|
||||
|
||||
def setter(self, param, val):
|
||||
"""Sends a string request RT packet."""
|
||||
@ -120,8 +122,8 @@ class IRemote(metaclass=ABCMeta):
|
||||
if isinstance(val, bool):
|
||||
val = 1 if val else 0
|
||||
|
||||
self._remote.cache[f"{self.identifier}[{self.index}].{attr}"] = val
|
||||
script += f"{self.identifier}[{self.index}].{attr}={val};"
|
||||
self._remote.cache[f"{self.identifier}.{attr}"] = val
|
||||
script += f"{self.identifier}.{attr}={val};"
|
||||
|
||||
self._remote.sendtext(script)
|
||||
return self
|
||||
|
@ -10,6 +10,8 @@ def cache_bool(func, param):
|
||||
cmd = f"{self.identifier}.{param}"
|
||||
if cmd in self._remote.cache:
|
||||
return self._remote.cache.pop(cmd) == 1
|
||||
if self._remote.sync:
|
||||
self._remote.clear_dirty()
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
@ -23,6 +25,8 @@ def cache_string(func, param):
|
||||
cmd = f"{self.identifier}.{param}"
|
||||
if cmd in self._remote.cache:
|
||||
return self._remote.cache.pop(cmd)
|
||||
if self._remote.sync:
|
||||
self._remote.clear_dirty()
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
@ -49,6 +49,7 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
self.subject = Subject()
|
||||
self.cache = {}
|
||||
self.event = Event(self.subs)
|
||||
self._pdirty = False
|
||||
|
||||
@abstractmethod
|
||||
def __str__(self):
|
||||
@ -85,7 +86,7 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
val: Optional[Union[int, float]] = None,
|
||||
):
|
||||
"""Sends a string request command over a network."""
|
||||
cmd = id_ if not param else f"{id_}.{param}={val}"
|
||||
cmd = id_ if not param else f"{id_}.{param}={val};"
|
||||
self.socks[Socket.request].sendto(
|
||||
self.packet_request.header + cmd.encode(),
|
||||
(socket.gethostbyname(self.ip), self.port),
|
||||
@ -94,8 +95,6 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
self.packet_request.framecounter = count.to_bytes(4, "little")
|
||||
if param:
|
||||
self.cache[f"{id_}.{param}"] = val
|
||||
if self.sync:
|
||||
time.sleep(0.02)
|
||||
|
||||
@script
|
||||
def sendtext(self, cmd):
|
||||
@ -129,7 +128,7 @@ class VbanCmd(metaclass=ABCMeta):
|
||||
|
||||
def clear_dirty(self):
|
||||
while self.pdirty:
|
||||
pass
|
||||
time.sleep(self.DELAY)
|
||||
|
||||
def _get_levels(self, packet) -> Iterable:
|
||||
"""
|
||||
|
@ -27,7 +27,7 @@ class Subscriber(threading.Thread):
|
||||
count = int.from_bytes(self.packet.framecounter, "little") + 1
|
||||
self.packet.framecounter = count.to_bytes(4, "little")
|
||||
time.sleep(10)
|
||||
except socket.gaierror as e:
|
||||
except socket.gaierror:
|
||||
err_msg = f"Unable to resolve hostname {self._remote.ip}"
|
||||
print(err_msg)
|
||||
raise VBANCMDError(err_msg)
|
||||
@ -55,9 +55,8 @@ class Updater(threading.Thread):
|
||||
self._remote.cache["strip_level"],
|
||||
self._remote.cache["bus_level"],
|
||||
) = self._remote._get_levels(self._remote.public_packet)
|
||||
self._remote._strip_comp = [False] * (
|
||||
2 * self._remote.kind.phys_in + 8 * self._remote.kind.virt_in
|
||||
)
|
||||
p_in, v_in = self._remote.kind.ins
|
||||
self._remote._strip_comp = [False] * (2 * p_in + 8 * v_in)
|
||||
self._remote._bus_comp = [False] * (self._remote.kind.num_bus * 8)
|
||||
|
||||
def _fetch_rt_packet(self) -> Optional[VbanRtPacket]:
|
||||
@ -93,7 +92,7 @@ class Updater(threading.Thread):
|
||||
_stripLabelUTF8c60=data[452:932],
|
||||
_busLabelUTF8c60=data[932:1412],
|
||||
)
|
||||
except TimeoutError as e:
|
||||
except TimeoutError:
|
||||
err_msg = f"Unable to establish connection with {self._remote.ip}"
|
||||
print(err_msg)
|
||||
raise VBANCMDError(err_msg)
|
||||
@ -110,27 +109,28 @@ class Updater(threading.Thread):
|
||||
|
||||
return fget()
|
||||
|
||||
def _update_comps(self, _pp):
|
||||
self._remote._strip_comp = _pp._strip_comp
|
||||
self._remote._bus_comp = _pp._bus_comp
|
||||
|
||||
def update(self):
|
||||
while self._remote.running:
|
||||
start = time.time()
|
||||
_pp = self._get_rt()
|
||||
self._remote._pdirty = _pp.pdirty(self._remote.public_packet)
|
||||
self._remote._ldirty = _pp.ldirty(
|
||||
pdirty = _pp.pdirty(self._remote.public_packet)
|
||||
ldirty = _pp.ldirty(
|
||||
self._remote.cache["strip_level"], self._remote.cache["bus_level"]
|
||||
)
|
||||
|
||||
if self._remote.pdirty or self._remote.ldirty:
|
||||
if pdirty or ldirty:
|
||||
self.logger.debug("dirty state, updating public packet")
|
||||
self._remote._public_packet = _pp
|
||||
self._remote._pdirty = pdirty
|
||||
self._remote._ldirty = ldirty
|
||||
|
||||
if self._remote.event.pdirty and self._remote.pdirty:
|
||||
self._remote.subject.notify("pdirty")
|
||||
if self._remote.event.ldirty and self._remote.ldirty:
|
||||
self._update_comps(_pp)
|
||||
self._remote._strip_comp, self._remote._bus_comp = (
|
||||
_pp._strip_comp,
|
||||
_pp._bus_comp,
|
||||
)
|
||||
self._remote.cache["strip_level"], self._remote.cache["bus_level"] = (
|
||||
_pp.inputlevels,
|
||||
_pp.outputlevels,
|
||||
|
Loading…
Reference in New Issue
Block a user