2023-07-21 12:49:01 +01:00
|
|
|
from enum import IntEnum
|
|
|
|
|
2022-06-16 14:07:12 +01:00
|
|
|
from .iremote import IRemote
|
|
|
|
|
2023-07-21 12:49:01 +01:00
|
|
|
ButtonModes = IntEnum(
|
|
|
|
"ButtonModes",
|
|
|
|
"state stateonly trigger",
|
|
|
|
start=1,
|
|
|
|
)
|
|
|
|
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
class Adapter(IRemote):
|
|
|
|
"""Adapter to the common interface."""
|
|
|
|
|
2022-06-21 23:21:55 +01:00
|
|
|
def getter(self, mode):
|
2023-07-21 12:49:01 +01:00
|
|
|
self.logger.debug(f"getter: button[{self.index}].{ButtonModes(mode).name}")
|
2022-06-21 23:21:55 +01:00
|
|
|
return self._remote.get_buttonstatus(self.index, mode)
|
2022-06-16 14:07:12 +01:00
|
|
|
|
2023-07-21 12:49:01 +01:00
|
|
|
def setter(self, mode, val):
|
|
|
|
self.logger.debug(
|
|
|
|
f"setter: button[{self.index}].{ButtonModes(mode).name}={val}"
|
|
|
|
)
|
2022-06-21 23:21:55 +01:00
|
|
|
self._remote.set_buttonstatus(self.index, val, mode)
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
|
2023-07-23 07:56:09 +01:00
|
|
|
class MacroButtonColorMixin(IRemote):
|
|
|
|
@property
|
|
|
|
def identifier(self):
|
|
|
|
return f"command.button[{self.index}]"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def color(self) -> int:
|
|
|
|
return int(IRemote.getter(self, "color"))
|
|
|
|
|
|
|
|
@color.setter
|
|
|
|
def color(self, val: int):
|
|
|
|
IRemote.setter(self, "color", val)
|
|
|
|
|
|
|
|
|
|
|
|
class MacroButton(Adapter, MacroButtonColorMixin):
|
2022-06-16 14:07:12 +01:00
|
|
|
"""Defines concrete implementation for macrobutton"""
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{type(self).__name__}{self._remote.kind}{self.index}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self) -> bool:
|
2023-07-21 12:49:01 +01:00
|
|
|
return self.getter(ButtonModes.state) == 1
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
@state.setter
|
2023-07-20 11:11:34 +01:00
|
|
|
def state(self, val: bool):
|
2023-07-21 12:49:01 +01:00
|
|
|
self.setter(ButtonModes.state, 1 if val else 0)
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def stateonly(self) -> bool:
|
2023-07-21 12:49:01 +01:00
|
|
|
return self.getter(ButtonModes.stateonly) == 1
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
@stateonly.setter
|
2023-07-20 11:11:34 +01:00
|
|
|
def stateonly(self, val: bool):
|
2023-07-21 12:49:01 +01:00
|
|
|
self.setter(ButtonModes.stateonly, 1 if val else 0)
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def trigger(self) -> bool:
|
2023-07-21 12:49:01 +01:00
|
|
|
return self.getter(ButtonModes.trigger) == 1
|
2022-06-16 14:07:12 +01:00
|
|
|
|
|
|
|
@trigger.setter
|
2023-07-20 11:11:34 +01:00
|
|
|
def trigger(self, val: bool):
|
2023-07-21 12:49:01 +01:00
|
|
|
self.setter(ButtonModes.trigger, 1 if val else 0)
|