2022-04-05 20:05:55 +01:00
|
|
|
import abc
|
2022-08-07 23:55:51 +01:00
|
|
|
|
|
|
|
from .errors import XAirRemoteError
|
2022-04-05 20:05:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IDCA(abc.ABC):
|
|
|
|
"""Abstract Base Class for DCA groups"""
|
|
|
|
|
|
|
|
def __init__(self, remote, index: int):
|
|
|
|
self._remote = remote
|
|
|
|
self.index = index + 1
|
|
|
|
|
|
|
|
def getter(self, param: str) -> tuple:
|
2024-02-03 13:03:49 +00:00
|
|
|
return self._remote.query(f"{self.address}/{param}")
|
2022-04-05 20:05:55 +01:00
|
|
|
|
|
|
|
def setter(self, param: str, val: int):
|
|
|
|
self._remote.send(f"{self.address}/{param}", val)
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
def address(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class DCA(IDCA):
|
|
|
|
"""Concrete class for DCA groups"""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def address(self) -> str:
|
|
|
|
return f"/dca/{self.index}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def on(self) -> bool:
|
|
|
|
return self.getter("on")[0] == 1
|
|
|
|
|
|
|
|
@on.setter
|
|
|
|
def on(self, val: bool):
|
|
|
|
self.setter("on", 1 if val else 0)
|
|
|
|
|
2022-11-10 12:10:01 +00:00
|
|
|
@property
|
|
|
|
def mute(self) -> bool:
|
|
|
|
return not self.on
|
|
|
|
|
|
|
|
@mute.setter
|
|
|
|
def mute(self, val: bool):
|
|
|
|
self.on = not val
|
|
|
|
|
2022-04-05 20:05:55 +01:00
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
|
|
|
return self.getter("config/name")[0]
|
|
|
|
|
|
|
|
@name.setter
|
|
|
|
def name(self, val: str):
|
|
|
|
self.setter("config/name")[0]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def color(self) -> int:
|
|
|
|
return self.getter("config/color")[0]
|
|
|
|
|
|
|
|
@color.setter
|
|
|
|
def color(self, val: int):
|
|
|
|
self.setter("config/color", val)
|