# Path: mppsolar/protocols/pi30.py
# class pi30(AbstractProtocol):
#     def __init__(self, *args, **kwargs) -> None:
#         super().__init__()
#         self._protocol_id = b"PI30"
#         self.COMMANDS = COMMANDS
#         self.STATUS_COMMANDS = ["QPIGS", "Q1"]
#         self.SETTINGS_COMMANDS = ["QPIRI", "QFLAG"]
#         self.DEFAULT_COMMAND = "QPI"
#         # log.info(f'Using protocol {self._protocol_id} with {len(self.COMMANDS)} commands')
# 
#     def check_response_valid(self, response):
#         if response is None:
#             return False, {"ERROR": ["No response", ""]}
#         if len(response) <= 3:
#             return False, {"ERROR": ["Response to short", ""]}
# 
#         if type(response) is str:
#             if "(NAK" in response:
#                 return False, {"ERROR": ["NAK", ""]}
#             crc_high, crc_low = crc(response[:-3])
#             if [ord(response[-3]), ord(response[-2])] != [crc_high, crc_low]:
#                 return False, {"ERROR": ["Invalid response CRCs", ""]}
#         elif type(response) is bytes:
#             if b"(NAK" in response:
#                 return False, {"ERROR": ["NAK", ""]}
# 
#             crc_high, crc_low = crc(response[:-3])
#             if response[-3:-1] != bytes([crc_high, crc_low]):
#                 return False, {"ERROR": ["Invalid response CRC", ""]}
#         log.debug("CRCs match")
#         return True, {}


import unittest
from mppsolar.protocols.pi30 import pi30 as pi
            "Battery Recharge Voltage": [47.0, "V"],
            "Battery Under Voltage": [46.5, "V"],
            "Battery Bulk Charge Voltage": [57.6, "V"],
            "Battery Float Charge Voltage": [57.6, "V"],
            "Battery Type": ["Invalid option: 9", ""],
            "Max AC Charging Current": [30, "A"],
            "Max Charging Current": [80, "A"],
            "Input Voltage Range": ["Appliance", ""],
            "Output Source Priority": ["Solar first", ""],
            "Charger Source Priority": ["Solar + Utility", ""],
            "Max Parallel Units": [1, "units"],
            "Machine Type": ["Off Grid", ""],
            "Topology": ["transformerless", ""],
            "Output Mode": ["single machine output", ""],
            "Battery Redischarge Voltage": [52.0, "V"],
            "PV OK Condition": [
                "As long as one unit of inverters has connect PV, parallel system will consider PV OK",
                "",
            ],
            "PV Power Balance": [
                "PV input max power will be the sum of the max charged power and loads power",
                "",
            ],
        }
        result = protocol.decode(response, command)
        # print(result)
        self.assertEqual(result, expected)

    def test_pi30_QFLAG(self):
        """ test the decode of a QFLAG response"""

# Path: mppsolar/protocols/pi30.py
# class pi30(AbstractProtocol):
#     def __init__(self, *args, **kwargs) -> None:
#         super().__init__()
#         self._protocol_id = b"PI30"
#         self.COMMANDS = COMMANDS
#         self.STATUS_COMMANDS = ["QPIGS", "Q1"]
#         self.SETTINGS_COMMANDS = ["QPIRI", "QFLAG"]
#         self.DEFAULT_COMMAND = "QPI"
#         # log.info(f'Using protocol {self._protocol_id} with {len(self.COMMANDS)} commands')
# 
#     def check_response_valid(self, response):
#         if response is None:
#             return False, {"ERROR": ["No response", ""]}
#         if len(response) <= 3:
#             return False, {"ERROR": ["Response to short", ""]}
# 
#         if type(response) is str:
#             if "(NAK" in response:
#                 return False, {"ERROR": ["NAK", ""]}
#             crc_high, crc_low = crc(response[:-3])
#             if [ord(response[-3]), ord(response[-2])] != [crc_high, crc_low]:
#                 return False, {"ERROR": ["Invalid response CRCs", ""]}
#         elif type(response) is bytes:
#             if b"(NAK" in response:
#                 return False, {"ERROR": ["NAK", ""]}
# 
#             crc_high, crc_low = crc(response[:-3])
#             if response[-3:-1] != bytes([crc_high, crc_low]):
#                 return False, {"ERROR": ["Invalid response CRC", ""]}
#         log.debug("CRCs match")
#         return True, {}


# Path: tests/test_protocol_pi30.py
import unittest
from mppsolar.protocols.pi30 import pi30 as pi

            "Battery Recharge Voltage": [47.0, "V"],
            "Battery Under Voltage": [46.5, "V"],
            "Battery Bulk Charge Voltage": [57.6, "V"],
            "Battery Float Charge Voltage": [57.6, "V"],
            "Battery Type": ["Invalid option: 9", ""],
            "Max AC Charging Current": [30, "A"],
            "Max Charging Current": [80, "A"],
            "Input Voltage Range": ["Appliance", ""],
            "Output Source Priority": ["Solar first", ""],
            "Charger Source Priority": ["Solar + Utility", ""],
            "Max Parallel Units": [1, "units"],
            "Machine Type": ["Off Grid", ""],
            "Topology": ["transformerless", ""],
            "Output Mode": ["single machine output", ""],
            "Battery Redischarge Voltage": [52.0, "V"],
            "PV OK Condition": [
                "As long as one unit of inverters has connect PV, parallel system will consider PV OK",
                "",
            ],
            "PV Power Balance": [
                "PV input max power will be the sum of the max charged power and loads power",
                "",
            ],
        }
        result = protocol.decode(response, command)
        # print(result)
        self.assertEqual(result, expected)

    def test_pi30_QFLAG(self):
        """ test the decode of a QFLAG response"""

        protocol = pi()