# Path: mppsolar/protocols/pi17.py
# class pi17(AbstractProtocol):
#     def __init__(self, *args, **kwargs) -> None:
#         super().__init__()
#         self._protocol_id = b"PI17"
#         self.COMMANDS = COMMANDS
#         self.STATUS_COMMANDS = []
#         self.SETTINGS_COMMANDS = [
#             "PI",
#             "ID",
#             "VFW",
#             "VFW2",
#             "MD",
#             "PIRI",
#             "GS",
#             "PS",
#             "MOD",
#             "WS",
#             "FLAG",
#             "T",
#             "ET",
#             "EY",
#             "ED",
#             "EH",
#             "HECS",
#         ]
#         self.DEFAULT_COMMAND = "PI"
# 
#     def get_full_command(self, command) -> bytes:
#         """
#         Override the default get_full_command as its different
#         """
#         log.info(f"Using protocol {self._protocol_id} with {len(self.COMMANDS)} commands")
#         # These need to be set to allow other functions to work`
#         self._command = command
#         self._command_defn = self.get_command_defn(command)
#         # End of required variables setting
#         if self._command_defn is None:
#             return None
# 
#         _cmd = bytes(self._command, "utf-8")
#         _type = self._command_defn["type"]
#         # No CRC in PI17 commands?
#         data_length = len(_cmd) + 1
#         if _type == "QUERY":
#             _prefix = f"^P{data_length:03}"
#             _pre_cmd = bytes(_prefix, "utf-8") + _cmd
#             log.debug(f"_pre_cmd: {_pre_cmd}")
#             log.debug(f"_prefix: {_prefix}")
#             # calculate the CRC
#             # crc_high; crc_low = crc(_pre_cmd)
#             # combine byte_cmd, CRC , return
#             # PI18 full command "^P005GS\x..\x..\r"
#             # _crc = bytes([crc_high, crc_low, 13])
#             full_command = _pre_cmd + bytes([13])  # + _crc
#             log.debug(f"full command: {full_command}")
#             return full_command
#         elif _type == "QUERYEN":
#             data_length1 = len(_cmd) + 4
#             _prefix = f"^P{data_length1:03}"
#             log.debug(f"_prefix: {_prefix}")
#             intermedstr = _prefix + self._command
#             _numb0 = sum(bytearray(intermedstr, "utf-8")) & 255
#             _numb = f"{_numb0:03d}"
#             log.debug(f"_numb: {_numb}")
#             _pre_cmd = intermedstr + str(_numb)
#             log.debug(f"_pre_cmd: {_pre_cmd}")
#             full_command = bytes(_pre_cmd, "utf-8") + bytes([13])
#             log.debug(f"full command: {full_command}")
#             return full_command
#         else:
#             _prefix = f"^S{data_length:03}"
#             _pre_cmd = bytes(_prefix, "utf-8") + _cmd
#             log.debug(f"_pre_cmd: {_pre_cmd}")
#             # calculate the CRC
#             # crc_high; crc_low = crc(_pre_cmd)
#             # combine byte_cmd, CRC , return
#             # PI18 full command "^P005GS\x..\x..\r"
#             # _crc = bytes([crc_high, crc_low, 13])
#             full_command = _pre_cmd + bytes([13])  # + _crc
#             log.debug(f"full command: {full_command}")
#             return full_command
# 
#     def get_responses(self, response):
#         """
#         Override the default get_responses as its different
#         """
#         responses = response.split(b",")
#         if responses[0] == b"^0\x1b\xe3\r":
#             # is a reject response
#             return ["NAK"]
#         elif responses[0] == b"^1\x0b\xc2\r":
#             # is a successful acknowledgement response
#             return ["ACK"]
# 
#         # Drop ^Dxxx from first response
#         responses[0] = responses[0][5:]
#         # Remove CRC of last response
#         responses[-1] = responses[-1][:-3]
#         return responses


import unittest
from mppsolar.protocols.pi17 import pi17 as pi


class test_pi17_decode(unittest.TestCase):
    maxDiff = None

    def test_pi17_PI(self):
        """test the decode of a PI response"""

# Path: mppsolar/protocols/pi17.py
# class pi17(AbstractProtocol):
#     def __init__(self, *args, **kwargs) -> None:
#         super().__init__()
#         self._protocol_id = b"PI17"
#         self.COMMANDS = COMMANDS
#         self.STATUS_COMMANDS = []
#         self.SETTINGS_COMMANDS = [
#             "PI",
#             "ID",
#             "VFW",
#             "VFW2",
#             "MD",
#             "PIRI",
#             "GS",
#             "PS",
#             "MOD",
#             "WS",
#             "FLAG",
#             "T",
#             "ET",
#             "EY",
#             "ED",
#             "EH",
#             "HECS",
#         ]
#         self.DEFAULT_COMMAND = "PI"
# 
#     def get_full_command(self, command) -> bytes:
#         """
#         Override the default get_full_command as its different
#         """
#         log.info(f"Using protocol {self._protocol_id} with {len(self.COMMANDS)} commands")
#         # These need to be set to allow other functions to work`
#         self._command = command
#         self._command_defn = self.get_command_defn(command)
#         # End of required variables setting
#         if self._command_defn is None:
#             return None
# 
#         _cmd = bytes(self._command, "utf-8")
#         _type = self._command_defn["type"]
#         # No CRC in PI17 commands?
#         data_length = len(_cmd) + 1
#         if _type == "QUERY":
#             _prefix = f"^P{data_length:03}"
#             _pre_cmd = bytes(_prefix, "utf-8") + _cmd
#             log.debug(f"_pre_cmd: {_pre_cmd}")
#             log.debug(f"_prefix: {_prefix}")
#             # calculate the CRC
#             # crc_high; crc_low = crc(_pre_cmd)
#             # combine byte_cmd, CRC , return
#             # PI18 full command "^P005GS\x..\x..\r"
#             # _crc = bytes([crc_high, crc_low, 13])
#             full_command = _pre_cmd + bytes([13])  # + _crc
#             log.debug(f"full command: {full_command}")
#             return full_command
#         elif _type == "QUERYEN":
#             data_length1 = len(_cmd) + 4
#             _prefix = f"^P{data_length1:03}"
#             log.debug(f"_prefix: {_prefix}")
#             intermedstr = _prefix + self._command
#             _numb0 = sum(bytearray(intermedstr, "utf-8")) & 255
#             _numb = f"{_numb0:03d}"
#             log.debug(f"_numb: {_numb}")
#             _pre_cmd = intermedstr + str(_numb)
#             log.debug(f"_pre_cmd: {_pre_cmd}")
#             full_command = bytes(_pre_cmd, "utf-8") + bytes([13])
#             log.debug(f"full command: {full_command}")
#             return full_command
#         else:
#             _prefix = f"^S{data_length:03}"
#             _pre_cmd = bytes(_prefix, "utf-8") + _cmd
#             log.debug(f"_pre_cmd: {_pre_cmd}")
#             # calculate the CRC
#             # crc_high; crc_low = crc(_pre_cmd)
#             # combine byte_cmd, CRC , return
#             # PI18 full command "^P005GS\x..\x..\r"
#             # _crc = bytes([crc_high, crc_low, 13])
#             full_command = _pre_cmd + bytes([13])  # + _crc
#             log.debug(f"full command: {full_command}")
#             return full_command
# 
#     def get_responses(self, response):
#         """
#         Override the default get_responses as its different
#         """
#         responses = response.split(b",")
#         if responses[0] == b"^0\x1b\xe3\r":
#             # is a reject response
#             return ["NAK"]
#         elif responses[0] == b"^1\x0b\xc2\r":
#             # is a successful acknowledgement response
#             return ["ACK"]
# 
#         # Drop ^Dxxx from first response
#         responses[0] = responses[0][5:]
#         # Remove CRC of last response
#         responses[-1] = responses[-1][:-3]
#         return responses


# Path: tests/test_protocol_pi17.py
import unittest
from mppsolar.protocols.pi17 import pi17 as pi



class test_pi17_decode(unittest.TestCase):
    maxDiff = None

    def test_pi17_PI(self):
        """test the decode of a PI response"""

        protocol = pi()