Skip to content

Commit 6df6dd6

Browse files
committed
Initial port to Python 3
1 parent 342ca00 commit 6df6dd6

File tree

4 files changed

+101
-100
lines changed

4 files changed

+101
-100
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ celerybeat.pid
110110
.venv
111111
env/
112112
venv/
113+
venv3/
113114
ENV/
114115
env.bak/
115116
venv.bak/

PyGrowatt/growatt_framer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GrowattV6Framer(ModbusSocketFramer):
3939
* The -1 is to account for the uid byte
4040
"""
4141

42-
def __init__(self, decoder, client=None, key="Growatt"):
42+
def __init__(self, decoder, client=None, key=b'Growatt'):
4343
""" Initializes a new instance of the framer
4444
4545
:param decoder: The decoder factory implementation to use
@@ -54,7 +54,7 @@ def _process(self, callback, error=False):
5454
data = self.getRawFrame() if error else self.getFrame()
5555
# data contains the function_code, then encrypted payload
5656
payload = self._xor(data[1:])
57-
data = data[0] + payload
57+
data = bytes([data[0]]) + payload
5858
result = self.decoder.decode(data)
5959
if result is None:
6060
raise ModbusIOException("Unable to decode request")
@@ -123,7 +123,7 @@ def buildPacket(self, message):
123123
return packet
124124

125125
def _xor(self, data):
126-
decrypted = ''
126+
decrypted = b''
127127
for i in range(0, len(data)):
128-
decrypted += chr(ord(data[i]) ^ ord(self._key[i % len(self._key)]))
128+
decrypted += bytes([data[i] ^ self._key[i % len(self._key)]])
129129
return decrypted

0 commit comments

Comments
 (0)