fixes bug with apply() if called from higher class

This commit is contained in:
onyx-and-iris 2023-07-05 19:20:57 +01:00
parent 2c8e4cc87c
commit 1ad0347478
4 changed files with 18 additions and 18 deletions

View File

@ -11,7 +11,7 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x]
## [2.1.1] - 2023-07-05
## [2.1.2] - 2023-07-05
### Added
@ -21,6 +21,12 @@ This is useful if you are only interested in sending commands out to voicemeeter
By default outbound is False.
- sendtext logging added in base class.
### Fixed
- Bug in apply() if invoked from a higher class (not base class)
## [2.0.0] - 2023-06-25
This update introduces some breaking changes:

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "vban-cmd"
version = "2.1.1"
version = "2.1.2"
description = "Python interface for the VBAN RT Packet Service (Sendtext)"
authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT"

View File

@ -102,7 +102,7 @@ class IRemote(metaclass=ABCMeta):
def setter(self, param, val):
"""Sends a string request RT packet."""
self.logger.debug(f"setter: {self._cmd(param)}={val}")
self._remote._set_rt(self.identifier, param, val)
self._remote._set_rt(self._cmd(param), val)
def _cmd(self, param):
cmd = (self.identifier,)
@ -141,10 +141,10 @@ class IRemote(metaclass=ABCMeta):
else:
target = getattr(self, attr)
target.apply(val)
self._remote.sendtext(self._remote._script)
return self
def then_wait(self):
self.logger.debug(self._remote._script)
self._remote.sendtext(self._remote._script)
self._remote._script = str()
time.sleep(self._remote.DELAY)

View File

@ -48,6 +48,7 @@ class VbanCmd(metaclass=ABCMeta):
self.cache = {}
self._pdirty = False
self._ldirty = False
self._script = str()
@abstractmethod
def __str__(self):
@ -101,34 +102,28 @@ class VbanCmd(metaclass=ABCMeta):
self.logger.info(f"{type(self).__name__}: Successfully logged into {self}")
def _set_rt(
self,
id_: str,
param: Optional[str] = None,
val: Optional[Union[int, float]] = None,
):
def _set_rt(self, cmd: str, val: Union[str, float]):
"""Sends a string request command over a network."""
cmd = f"{id_}={val};" if not param else f"{id_}.{param}={val};"
self.socks[Socket.request].sendto(
self.packet_request.header + cmd.encode(),
self.packet_request.header + f"{cmd}={val};".encode(),
(socket.gethostbyname(self.ip), self.port),
)
self.packet_request.framecounter = (
int.from_bytes(self.packet_request.framecounter, "little") + 1
).to_bytes(4, "little")
if param:
self.cache[f"{id_}.{param}"] = val
self.cache[cmd] = val
@script
def sendtext(self, cmd):
def sendtext(self, script):
"""Sends a multiple parameter string over a network."""
self.socks[Socket.request].sendto(
self.packet_request.header + cmd.encode(),
self.packet_request.header + script.encode(),
(socket.gethostbyname(self.ip), self.port),
)
self.packet_request.framecounter = (
int.from_bytes(self.packet_request.framecounter, "little") + 1
).to_bytes(4, "little")
self.logger.debug(f"sendtext: [{self.ip}:{self.port}] {script}")
time.sleep(self.DELAY)
@property
@ -185,7 +180,6 @@ class VbanCmd(metaclass=ABCMeta):
else:
raise ValueError(obj)
self._script = str()
[param(key).apply(datum).then_wait() for key, datum in data.items()]
def apply_config(self, name):