# Path: mppsolar/protocols/protocol_helpers.py
# def Hex2Int(hexString):
#     """
#     Decode the first byte of a hexString to int
#     """
#     answer = hexString[0]
#     log.debug(f"Hex {hexString} decoded to {answer}")
# 
#     return answer
# 
# def Hex2Str(hexString):
#     """
#     Return the hexString as ASCII representation of hex, ie 0x4a -> 4a
#     """
#     answer = ""
#     for x in hexString:
#         answer += f"{x:02x}"
# 
#     log.debug(f"Hex {hexString} decoded to {answer}")
# 
#     return answer
# 
# Path: mppsolar/protocols/protocol_helpers.py
# def BigHex2Float(hexString):
#     """
#     Decode a 4 byte hexString to int (big endian coded)
#     """
#     # Make sure supplied String is the correct length
#     if len(hexString) != 4:
#         log.info(f"Hex encoded value must be 4 bytes long. Was {len(hexString)} length")
#         return 0
# 
#     answer = unpack(">I", hexString)[0]
#     # answer = int(hexString.hex(), 16)
#     log.debug(f"Hex {hexString} 4 byte decoded to {answer}")
#     return answer


import unittest
from mppsolar.protocols.protocol_helpers import Hex2Int, Hex2Str
from mppsolar.protocols.protocol_helpers import BigHex2Float


class test_protocol_helpers(unittest.TestCase):
    def test_Hex2Int(self):
        """ test the Hex2Int"""
        result = Hex2Int(bytes.fromhex("64"))
        expected = 100
        # print(result)
        self.assertEqual(result, expected)

    def test_Hex2Str(self):
        """ test the Hex2Str"""

# Path: mppsolar/protocols/protocol_helpers.py
# def Hex2Int(hexString):
#     """
#     Decode the first byte of a hexString to int
#     """
#     answer = hexString[0]
#     log.debug(f"Hex {hexString} decoded to {answer}")
# 
#     return answer
# 
# def Hex2Str(hexString):
#     """
#     Return the hexString as ASCII representation of hex, ie 0x4a -> 4a
#     """
#     answer = ""
#     for x in hexString:
#         answer += f"{x:02x}"
# 
#     log.debug(f"Hex {hexString} decoded to {answer}")
# 
#     return answer
# 
# Path: mppsolar/protocols/protocol_helpers.py
# def BigHex2Float(hexString):
#     """
#     Decode a 4 byte hexString to int (big endian coded)
#     """
#     # Make sure supplied String is the correct length
#     if len(hexString) != 4:
#         log.info(f"Hex encoded value must be 4 bytes long. Was {len(hexString)} length")
#         return 0
# 
#     answer = unpack(">I", hexString)[0]
#     # answer = int(hexString.hex(), 16)
#     log.debug(f"Hex {hexString} 4 byte decoded to {answer}")
#     return answer


# Path: tests/test_protocol_helpers.py
import unittest
from mppsolar.protocols.protocol_helpers import Hex2Int, Hex2Str
from mppsolar.protocols.protocol_helpers import BigHex2Float



class test_protocol_helpers(unittest.TestCase):
    def test_Hex2Int(self):
        """ test the Hex2Int"""
        result = Hex2Int(bytes.fromhex("64"))
        expected = 100
        # print(result)
        self.assertEqual(result, expected)

    def test_Hex2Str(self):
        """ test the Hex2Str"""

        result = Hex2Str(bytes.fromhex("AE0212"))