# Path: mppsolar/protocols/pi18.py
# class pi18(AbstractProtocol):
#     def __init__(self, *args, **kwargs) -> None:
#         super().__init__()
#         self._protocol_id = b"PI18"
#         self.COMMANDS = COMMANDS
#         self.STATUS_COMMANDS = ["MOD", "GS", "ET"]
#         self.SETTINGS_COMMANDS = [
#             "PI",
#         ]
#         self.DEFAULT_COMMAND = "PI"
# 
#     def get_full_command(self, command) -> bytes:
#         """
#         Override the default get_full_command as its different for PI18
#         """
#         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"]
# 
#         data_length = len(_cmd) + 2 + 1
#         if _type == "QUERY":
#             _prefix = f"^P{data_length:03}"
#         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 + _crc
#         log.debug(f"full command: {full_command}")
#         return full_command
# 
#     def get_responses(self, response):
#         """
#         Override the default get_responses as its different for PI18
#         """
#         responses = response.split(b",")
#         if responses[0] == b"^0\x1b\xe3\r":
#             # is a reject response
#             return ["NAK"]
# 
#         # 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.pi18 import pi18 as pi


class test_pi18_decode(unittest.TestCase):
    maxDiff = None

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

# Path: mppsolar/protocols/pi18.py
# class pi18(AbstractProtocol):
#     def __init__(self, *args, **kwargs) -> None:
#         super().__init__()
#         self._protocol_id = b"PI18"
#         self.COMMANDS = COMMANDS
#         self.STATUS_COMMANDS = ["MOD", "GS", "ET"]
#         self.SETTINGS_COMMANDS = [
#             "PI",
#         ]
#         self.DEFAULT_COMMAND = "PI"
# 
#     def get_full_command(self, command) -> bytes:
#         """
#         Override the default get_full_command as its different for PI18
#         """
#         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"]
# 
#         data_length = len(_cmd) + 2 + 1
#         if _type == "QUERY":
#             _prefix = f"^P{data_length:03}"
#         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 + _crc
#         log.debug(f"full command: {full_command}")
#         return full_command
# 
#     def get_responses(self, response):
#         """
#         Override the default get_responses as its different for PI18
#         """
#         responses = response.split(b",")
#         if responses[0] == b"^0\x1b\xe3\r":
#             # is a reject response
#             return ["NAK"]
# 
#         # 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_pi18.py
import unittest
from mppsolar.protocols.pi18 import pi18 as pi



class test_pi18_decode(unittest.TestCase):
    maxDiff = None

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

        protocol = pi()