add ButtonModes IntEnum to macrobutton

debug log getter,setter for macrobutton
This commit is contained in:
onyx-and-iris 2023-07-21 12:49:01 +01:00
parent bdf8dc489a
commit 7841dfe10f

View File

@ -1,5 +1,13 @@
from enum import IntEnum
from .iremote import IRemote
ButtonModes = IntEnum(
"ButtonModes",
"state stateonly trigger",
start=1,
)
class Adapter(IRemote):
"""Adapter to the common interface."""
@ -8,9 +16,13 @@ class Adapter(IRemote):
pass
def getter(self, mode):
self.logger.debug(f"getter: button[{self.index}].{ButtonModes(mode).name}")
return self._remote.get_buttonstatus(self.index, mode)
def setter(self, val, mode):
def setter(self, mode, val):
self.logger.debug(
f"setter: button[{self.index}].{ButtonModes(mode).name}={val}"
)
self._remote.set_buttonstatus(self.index, val, mode)
@ -22,24 +34,24 @@ class MacroButton(Adapter):
@property
def state(self) -> bool:
return self.getter(1) == 1
return self.getter(ButtonModes.state) == 1
@state.setter
def state(self, val: bool):
self.setter(1 if val else 0, 1)
self.setter(ButtonModes.state, 1 if val else 0)
@property
def stateonly(self) -> bool:
return self.getter(2) == 1
return self.getter(ButtonModes.stateonly) == 1
@stateonly.setter
def stateonly(self, val: bool):
self.setter(1 if val else 0, 2)
self.setter(ButtonModes.stateonly, 1 if val else 0)
@property
def trigger(self) -> bool:
return self.getter(3) == 1
return self.getter(ButtonModes.trigger) == 1
@trigger.setter
def trigger(self, val: bool):
self.setter(1 if val else 0, 3)
self.setter(ButtonModes.trigger, 1 if val else 0)