mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2024-11-22 11:00:47 +00:00
apply now sets attributes if passed nested dicts.
_cmd() helper method added
This commit is contained in:
parent
36fe77f0f0
commit
6ddfe3044e
@ -1,6 +1,9 @@
|
||||
import logging
|
||||
import time
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IRemote(metaclass=ABCMeta):
|
||||
"""
|
||||
@ -12,14 +15,23 @@ class IRemote(metaclass=ABCMeta):
|
||||
def __init__(self, remote, index=None):
|
||||
self._remote = remote
|
||||
self.index = index
|
||||
self.logger = logger.getChild(self.__class__.__name__)
|
||||
|
||||
def getter(self, param, **kwargs):
|
||||
"""Gets a parameter value"""
|
||||
return self._remote.get(f"{self.identifier}.{param}", **kwargs)
|
||||
self.logger.debug(f"getter: {self._cmd(param)}")
|
||||
return self._remote.get(self._cmd(param), **kwargs)
|
||||
|
||||
def setter(self, param, val):
|
||||
"""Sets a parameter value"""
|
||||
self._remote.set(f"{self.identifier}.{param}", val)
|
||||
self.logger.debug(f"setter: {self._cmd(param)}={val}")
|
||||
self._remote.set(self._cmd(param), val)
|
||||
|
||||
def _cmd(self, param):
|
||||
cmd = (self.identifier,)
|
||||
if param:
|
||||
cmd += (f".{param}",)
|
||||
return "".join(cmd)
|
||||
|
||||
@abstractmethod
|
||||
def identifier(self):
|
||||
@ -32,9 +44,13 @@ class IRemote(metaclass=ABCMeta):
|
||||
return (self, attr, val)
|
||||
|
||||
for attr, val in data.items():
|
||||
if hasattr(self, attr):
|
||||
target, attr, val = fget(attr, val)
|
||||
setattr(target, attr, val)
|
||||
if not isinstance(val, dict):
|
||||
if hasattr(self, attr):
|
||||
target, attr, val = fget(attr, val)
|
||||
setattr(target, attr, val)
|
||||
else:
|
||||
target = getattr(self, attr)
|
||||
target.apply(val)
|
||||
return self
|
||||
|
||||
def then_wait(self):
|
||||
|
Loading…
Reference in New Issue
Block a user