2022-03-04 14:22:29 +00:00
|
|
|
from .errors import VMCMDErrors
|
2022-03-18 07:42:25 +00:00
|
|
|
from time import sleep
|
2022-03-04 14:22:29 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def strip_bool_prop(param):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A strip bool prop."""
|
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def fget(self):
|
|
|
|
val = self.getter(param)
|
|
|
|
if val is None:
|
2022-03-26 23:00:09 +00:00
|
|
|
val = (
|
|
|
|
not int.from_bytes(self.public_packet.stripstate[self.index], "little")
|
|
|
|
& getattr(self._modes, f"_{param}")
|
|
|
|
== 0
|
|
|
|
)
|
2022-03-20 12:25:50 +00:00
|
|
|
return val
|
|
|
|
return val == 1
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def fset(self, val):
|
2022-03-26 23:00:09 +00:00
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
|
|
|
raise VMCMDErrors(f"{param} is a boolean parameter")
|
2022-03-20 12:25:50 +00:00
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
return property(fget, fset)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def bus_bool_prop(param):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A bus bool prop."""
|
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def fget(self):
|
|
|
|
val = self.getter(param)
|
|
|
|
if val is None:
|
2022-03-26 23:00:09 +00:00
|
|
|
val = (
|
|
|
|
not int.from_bytes(self.public_packet.busstate[self.index], "little")
|
|
|
|
& getattr(self._modes, f'_{param.replace(".", "_").lower()}')
|
|
|
|
== 0
|
|
|
|
)
|
2022-03-20 12:25:50 +00:00
|
|
|
return val
|
|
|
|
return val == 1
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def fset(self, val):
|
2022-03-26 23:00:09 +00:00
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
|
|
|
raise VMCMDErrors(f"{param} is a boolean parameter")
|
2022-03-20 12:25:50 +00:00
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
return property(fget, fset)
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def strip_output_prop(param):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A strip output prop."""
|
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def fget(self):
|
2022-03-20 12:25:50 +00:00
|
|
|
val = self.getter(param)
|
|
|
|
if val is None:
|
2022-03-26 23:00:09 +00:00
|
|
|
val = (
|
|
|
|
not int.from_bytes(self.public_packet.stripstate[self.index], "little")
|
|
|
|
& getattr(self._modes, f"_bus{param.lower()}")
|
|
|
|
== 0
|
|
|
|
)
|
2022-03-20 12:25:50 +00:00
|
|
|
return val
|
|
|
|
return val == 1
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
def fset(self, val):
|
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
2022-03-26 23:00:09 +00:00
|
|
|
raise VMCMDErrors(f"{param} is a boolean parameter")
|
2022-03-04 14:22:29 +00:00
|
|
|
self.setter(param, 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-04 14:22:29 +00:00
|
|
|
return property(fget, fset)
|
2022-03-17 14:08:49 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def bus_mode_prop(param):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A bus mode prop."""
|
2022-04-26 07:35:41 +01:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def fget(self):
|
2022-03-26 23:00:09 +00:00
|
|
|
val = self.getter(f"mode.{param}")
|
2022-03-20 12:25:50 +00:00
|
|
|
if val is None:
|
2022-04-26 07:35:41 +01:00
|
|
|
if param == "normal":
|
2022-04-26 21:03:02 +01:00
|
|
|
return any(
|
2022-04-26 07:35:41 +01:00
|
|
|
not int.from_bytes(
|
|
|
|
self.public_packet.busstate[self.index], "little"
|
|
|
|
)
|
|
|
|
& val
|
|
|
|
== 0
|
|
|
|
for val in self._modes.modevals
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
val = (
|
|
|
|
not int.from_bytes(
|
|
|
|
self.public_packet.busstate[self.index], "little"
|
|
|
|
)
|
|
|
|
& getattr(self._modes, f"_{param}")
|
|
|
|
== 0
|
|
|
|
)
|
2022-03-20 12:25:50 +00:00
|
|
|
return val
|
|
|
|
return val == 1
|
2022-04-26 07:35:41 +01:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
def fset(self, val):
|
|
|
|
if not isinstance(val, bool) and val not in (0, 1):
|
2022-03-26 23:00:09 +00:00
|
|
|
raise VMCMDErrors(f"mode.{param} is a boolean parameter")
|
2022-04-26 21:03:02 +01:00
|
|
|
self.setter(f"mode.{param}", 1 if val else 0)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-17 14:08:49 +00:00
|
|
|
return property(fget, fset)
|
2022-03-21 11:20:53 +00:00
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
def action_prop(param, val=1):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""A param that performs an action"""
|
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
def fdo(self):
|
|
|
|
self.setter(param, val)
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-21 11:20:53 +00:00
|
|
|
return fdo
|