# 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 logging
from .pi30 import pi30

# New / overriden commands
NEW_COMMANDS = {
    "QP2GS": {
        "name": "QP2GS",
        "description": "Parallel Information inquiry",
        "help": " -- example: QP2GS1 queries the values of various metrics from instance 1 of parallel setup Inverters (numbers from 0)",
        "type": "QUERY",
        "response": [
            ["int", "Parallel instance number??", ""],
            ["int", "Serial number", ""],
            [
                "keyed",
                "Work mode",
                {
                    "P": "Power On Mode",
                    "S": "Standby Mode",
                    "L": "Line Mode",
                    "B": "Battery Mode",
                    "F": "Fault Mode",
                    "H": "Power Saving Mode",
                },
            ],
            [
                "keyed",
                "Fault code",
                {
                    "00": "No fault",
                    "01": "Fan is locked",
                    "02": "Over temperature",

# 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: mppsolar/protocols/pi41.py
import logging
from .pi30 import pi30


# New / overriden commands
NEW_COMMANDS = {
    "QP2GS": {
        "name": "QP2GS",
        "description": "Parallel Information inquiry",
        "help": " -- example: QP2GS1 queries the values of various metrics from instance 1 of parallel setup Inverters (numbers from 0)",
        "type": "QUERY",
        "response": [
            ["int", "Parallel instance number??", ""],
            ["int", "Serial number", ""],
            [
                "keyed",
                "Work mode",
                {
                    "P": "Power On Mode",
                    "S": "Standby Mode",
                    "L": "Line Mode",
                    "B": "Battery Mode",
                    "F": "Fault Mode",
                    "H": "Power Saving Mode",
                },
            ],
            [
                "keyed",
                "Fault code",
                {
                    "00": "No fault",
                    "01": "Fan is locked",
                    "02": "Over temperature",

                    "03": "Battery voltage is too high",