mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2025-01-18 18:40:47 +00:00
add command class
added command class added action prop to meta module
This commit is contained in:
parent
2257ce0e4c
commit
6098c34e15
49
vbancmd/command.py
Normal file
49
vbancmd/command.py
Normal file
@ -0,0 +1,49 @@
|
||||
import abc
|
||||
from .errors import VMCMDErrors
|
||||
from .meta import action_prop
|
||||
|
||||
class ICommand(abc.ABC):
|
||||
""" Command Base Class """
|
||||
def __init__(self, remote):
|
||||
self._remote = remote
|
||||
|
||||
def setter(self, param, val):
|
||||
""" Sends a string request RT packet. """
|
||||
self._remote.set_rt(f'{self.identifier}', param, val)
|
||||
|
||||
@abc.abstractmethod
|
||||
def identifier(self):
|
||||
pass
|
||||
|
||||
|
||||
class Command(ICommand):
|
||||
""" Command Concrete Class """
|
||||
@classmethod
|
||||
def make(cls, remote):
|
||||
"""
|
||||
Factory function for command class.
|
||||
|
||||
Returns a Command class of a kind.
|
||||
"""
|
||||
CMD_cls = type(f'Command{remote.kind.name}', (cls,), {
|
||||
**{param: action_prop(param)
|
||||
for param in ['show', 'shutdown', 'restart']},
|
||||
'hide': action_prop('show', val=0),
|
||||
})
|
||||
return CMD_cls(remote)
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
return 'Command'
|
||||
|
||||
def set_showvbanchat(self, val: bool):
|
||||
if not isinstance(val, bool) and val not in (0,1):
|
||||
raise VMCMDErrors('showvbanchat is a boolean parameter')
|
||||
self.setter('DialogShow.VBANCHAT', 1 if val else 0)
|
||||
showvbanchat = property(fset=set_showvbanchat)
|
||||
|
||||
def set_lock(self, val: bool):
|
||||
if not isinstance(val, bool) and val not in (0,1):
|
||||
raise VMCMDErrors('lock is a boolean parameter')
|
||||
self.setter('lock', 1 if val else 0)
|
||||
lock = property(fset=set_lock)
|
@ -76,3 +76,9 @@ def bus_mode_prop(param):
|
||||
raise VMCMDErrors(f'mode.{param} is a boolean parameter')
|
||||
self.setter(f'mode.{param}', 1 if val else 0)
|
||||
return property(fget, fset)
|
||||
|
||||
def action_prop(param, val=1):
|
||||
""" A param that performs an action """
|
||||
def fdo(self):
|
||||
self.setter(param, val)
|
||||
return fdo
|
||||
|
@ -16,6 +16,7 @@ from .dataclass import (
|
||||
)
|
||||
from .strip import InputStrip
|
||||
from .bus import OutputBus
|
||||
from .command import Command
|
||||
|
||||
class VbanCmd(abc.ABC):
|
||||
def __init__(self, **kwargs):
|
||||
@ -247,6 +248,7 @@ def _make_remote(kind: NamedTuple) -> VbanCmd:
|
||||
self.bus = \
|
||||
tuple(OutputBus.make((i < self.phys_out), self, i)
|
||||
for i in range(self.phys_out + self.virt_out))
|
||||
self.command = Command.make(self)
|
||||
|
||||
return type(f'VbanCmd{kind.name}', (VbanCmd,), {
|
||||
'__init__': init,
|
||||
|
Loading…
Reference in New Issue
Block a user