Source code for sunix_ledstrip_controller_client.packets.responses

from construct import Struct, Int8ub

from sunix_ledstrip_controller_client.packets import _evaluate_checksum


[docs]class StatusResponse(Struct): """ The response to the StatusRequest request """ def __init__(self, data: bytearray): super().__init__( "packet_id" / Int8ub, "device_name" / Int8ub, "power_status" / Int8ub, "mode" / Int8ub, "run_status" / Int8ub, "speed" / Int8ub, "red" / Int8ub, "green" / Int8ub, "blue" / Int8ub, "warm_white" / Int8ub, "unknown1" / Int8ub, "cold_white" / Int8ub, "unknown2" / Int8ub, "checksum" / Int8ub ) self._data = data
[docs] def evaluate(self) -> bool: """ :return: True if this response is valid, false otherwise """ return _evaluate_checksum(self.parse(self._data))
[docs] def get_response(self) -> dict: """ :return: the response in the expected format """ if not self.evaluate(): raise ValueError("invalid or missing checksum") return self.parse(self._data)
[docs]class GetTimeResponse(Struct): """ The response to the GetTimeRequest request """ def __init__(self, data: bytearray): super().__init__( "packet_id" / Int8ub, "unknown1" / Int8ub, "unknown2" / Int8ub, # add 2000 to this value to get the correct year "year" / Int8ub, "month" / Int8ub, "day" / Int8ub, "hour" / Int8ub, "minute" / Int8ub, "second" / Int8ub, "dayofweek" / Int8ub, "unknown3" / Int8ub, "checksum" / Int8ub ) self._data = data
[docs] def evaluate(self) -> bool: """ :return: True if this response is valid, false otherwise """ return _evaluate_checksum(self.parse(self._data))
[docs] def get_response(self) -> dict: """ :return: the response in the expected format """ if not self.evaluate(): raise ValueError("invalid or missing checksum") return self.parse(self._data)