Skip to content

Commit

Permalink
Initial port to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjbrown committed Apr 18, 2021
1 parent 342ca00 commit 6df6dd6
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 100 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ celerybeat.pid
.venv
env/
venv/
venv3/
ENV/
env.bak/
venv.bak/
Expand Down
8 changes: 4 additions & 4 deletions PyGrowatt/growatt_framer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GrowattV6Framer(ModbusSocketFramer):
* The -1 is to account for the uid byte
"""

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

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

0 comments on commit 6df6dd6

Please sign in to comment.