xair-api-python/xair_api/lr.py

64 lines
1.6 KiB
Python
Raw Normal View History

2022-04-05 20:05:55 +01:00
import abc
from typing import Optional
2022-11-16 15:51:26 +00:00
from .meta import mute_prop
from .shared import EQ, GEQ, Config, Dyn, Insert, Mix
2022-04-05 20:05:55 +01:00
class ILR(abc.ABC):
2024-02-08 17:40:49 +00:00
"""Abstract Base Class for lr"""
2022-04-05 20:05:55 +01:00
def __init__(self, remote, index: Optional[int] = None):
2022-04-05 20:05:55 +01:00
self._remote = remote
if index is not None:
self.index = index + 1
2022-04-05 20:05:55 +01:00
def getter(self, param: str):
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 LR(ILR):
2024-02-08 17:40:49 +00:00
"""Concrete class for lr"""
2022-04-05 20:05:55 +01:00
@classmethod
def make(cls, remote, index=None):
2022-04-05 20:05:55 +01:00
"""
Factory function for LR
Creates a mixin of shared subclasses, sets them as class attributes.
Returns an LR class of a kind.
"""
LR_cls = type(
f"LR{remote.kind}",
2022-04-05 20:05:55 +01:00
(cls,),
{
**{
_cls.__name__.lower(): type(
f"{_cls.__name__}{remote.kind}", (_cls, cls), {}
)(remote, index)
2022-04-05 20:05:55 +01:00
for _cls in (
Config,
Dyn,
Insert,
GEQ.make(),
EQ.make_sixband(cls, remote, index),
2022-04-05 20:05:55 +01:00
Mix,
)
},
2022-11-16 15:51:26 +00:00
"mute": mute_prop(),
2022-04-05 20:05:55 +01:00
},
)
return LR_cls(remote, index)
2022-04-05 20:05:55 +01:00
@property
def address(self) -> str:
return "/lr"