Skip to content

Commit

Permalink
Fix charmap_decode error (mostly under Win)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaluxPL committed Mar 1, 2022
1 parent f5572fa commit e8a8069
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,13 @@ Fixes, code refactoring and clean-ups

### Fixed
1. Sending offline status to MQTT (basic, Domoticz, HomeAssistant)

## [1.83] - 2022-03-01
Fix

### Added

### Changed

### Fixed
1. Small fix for potential charmap_decode error (especially in Windows environment)
8 changes: 4 additions & 4 deletions InverterData.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3
# Script gathering solar data from Sofar Solar Inverter (K-TLX) via logger module LSW-3/LSE
# by Michalux (based on DEYE script by jlopez77, HA initial code by pablolite).
# Version: 1.82
# Version: 1.83
#

import sys
Expand Down Expand Up @@ -152,10 +152,10 @@ def PrepareDomoticzData(DData, idx, svalue):
checksum += frame_bytes[i] & 255
frame_bytes[len(frame_bytes) - 2] = int((checksum & 255))

# SEND DATA
if verbose=="1":
print("*** Chunk no: ", chunks);
print("Sent data: ", frame);
# SEND DATA
clientSocket.sendall(frame_bytes);

ok=False;
Expand All @@ -182,7 +182,7 @@ def PrepareDomoticzData(DData, idx, svalue):
p2=60+(a*4)
hexpos=str("0x") + str(hex(a+pini)[2:].zfill(4)).upper()
response=twosComplement_hex(str(''.join(hex(ord(chr(x)))[2:].zfill(2) for x in bytearray(data))+' '+re.sub('[^\x20-\x7f]', '', ''))[p1:p2], hexpos)
with open("./SOFARMap.xml") as txtfile:
with open("./SOFARMap.xml", encoding="utf-8") as txtfile:
parameters=json.loads(txtfile.read())
for parameter in parameters:
for item in parameter["items"]:
Expand Down Expand Up @@ -336,7 +336,7 @@ def PrepareDomoticzData(DData, idx, svalue):
if not result.is_published:
print("Error publishing device status to MQTT")
if DomoticzSupport=="1":
with open("./SOFARMap.xml") as txtfile:
with open("./SOFARMap.xml", encoding="utf-8") as txtfile:
parameters=json.loads(txtfile.read())
result=client.publish(domoticz_mqtt_topic, "{ \"idx\": "+str(parameters[2]['items'][0]['DomoticzIdx'])+", \"svalue\": \"Off\" }", retain=True)
result.wait_for_publish()
Expand Down

0 comments on commit e8a8069

Please sign in to comment.