2022-06-16 14:07:12 +01:00
|
|
|
import time
|
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
|
|
|
|
|
|
|
|
class IRemote(metaclass=ABCMeta):
|
|
|
|
"""
|
|
|
|
Common interface between base class and extended (higher) classes
|
|
|
|
|
|
|
|
Provides some default implementation
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, remote, index=None):
|
|
|
|
self._remote = remote
|
|
|
|
self.index = index
|
|
|
|
|
|
|
|
def getter(self, param, **kwargs):
|
|
|
|
"""Gets a parameter value"""
|
|
|
|
return self._remote.get(f"{self.identifier}.{param}", **kwargs)
|
|
|
|
|
|
|
|
def setter(self, param, val):
|
|
|
|
"""Sets a parameter value"""
|
|
|
|
self._remote.set(f"{self.identifier}.{param}", val)
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def identifier(self):
|
|
|
|
pass
|
|
|
|
|
2022-09-03 16:28:19 +01:00
|
|
|
def apply(self, data: dict):
|
2022-07-16 21:19:10 +01:00
|
|
|
def fget(attr, val):
|
|
|
|
if attr == "mode":
|
|
|
|
return (getattr(self, attr), val, 1)
|
|
|
|
return (self, attr, val)
|
|
|
|
|
2022-06-16 14:07:12 +01:00
|
|
|
for attr, val in data.items():
|
|
|
|
if hasattr(self, attr):
|
2022-07-16 21:19:10 +01:00
|
|
|
target, attr, val = fget(attr, val)
|
|
|
|
setattr(target, attr, val)
|
2022-06-16 14:07:12 +01:00
|
|
|
return self
|
|
|
|
|
|
|
|
def then_wait(self):
|
|
|
|
time.sleep(self._remote.DELAY)
|