# 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

# Examples
# self.assertRaises(mppinverter.NoDeviceError, mppinverter.mppInverter)
# self.assertEqual(inverter._baud_rate, 2400)
# self.assertIsNone(inverter._serial_number)
# self.assertFalse(inverter._direct_usb)
# self.assertIsInstance(inverter.getAllCommands(), list)
# self.assertTrue(inverter._direct_usb)
# self.assertListEqual(mppcommand.crc(bytes('196', 'utf-8')), [27, 14])


class test_pi30_decode(unittest.TestCase):
    maxDiff = None

    def test_pi30_QPI(self):
        """ test the decode of a QPI 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


# Examples
# self.assertRaises(mppinverter.NoDeviceError, mppinverter.mppInverter)
# self.assertEqual(inverter._baud_rate, 2400)
# self.assertIsNone(inverter._serial_number)
# self.assertFalse(inverter._direct_usb)
# self.assertIsInstance(inverter.getAllCommands(), list)
# self.assertTrue(inverter._direct_usb)
# self.assertListEqual(mppcommand.crc(bytes('196', 'utf-8')), [27, 14])


class test_pi30_decode(unittest.TestCase):
    maxDiff = None

    def test_pi30_QPI(self):
        """ test the decode of a QPI response"""

        protocol = pi()