From d7e7d6789ebe5d3aa78520caf0c21786cc5b87c9 Mon Sep 17 00:00:00 2001 From: Alex Hope-O'Connor Date: Fri, 31 Oct 2025 02:19:47 +1000 Subject: [PATCH] Sync with upstream: battery_current datatype fix (U16->S16) - Merged upstream changes from bohdan-s/SunGather - Fixed battery_current register datatype from U16 to S16 for proper negative values - Preserved local VS Code debug configuration - Updated to SunGather v0.5.2 --- .vscode/tasks.json | 15 +++++++++++++++ SunGather/exports/mqtt.py | 19 ++++++++++++++++++- SunGather/sungather.py | 6 ++++-- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..ba597c2 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,15 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build and Push SunGather Docker Image (Multi-Arch)", + "type": "shell", + "command": "docker buildx build --push --platform linux/amd64,linux/arm64/v8 -t gitea.elixirtechnologies.au/alex/sungather:latest .", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/SunGather/exports/mqtt.py b/SunGather/exports/mqtt.py index 8d5c44e..881b07d 100644 --- a/SunGather/exports/mqtt.py +++ b/SunGather/exports/mqtt.py @@ -61,7 +61,24 @@ class export_mqtt(object): if reason_code == 0: logging.info(f"MQTT: Connected to {client._host}:{client._port}") if reason_code > 0: - logging.warn(f"MQTT: FAILED to connect {client._host}:{client._port}") + reason_messages = { + # MQTT 3.1.1 + 1: "Unacceptable Protocol Version", + 2: "Identifier Rejected", + 3: "Server Unavailable", + 4: "Bad Username or Password", + 5: "Not Authorized", + # MQTT 5.0 common + 128: "Unspecified Error", + 129: "Malformed Packet", + 130: "Protocol Error", + 131: "Implementation Specific Error", + 135: "Not Authorized", + 140: "Server Moved", + 141: "Server Unavailable", + } + error_message = reason_messages.get(reason_code, "Unknown Error") + logging.warning(f"MQTT: FAILED to disconnect (reason {reason_code}): {error_message}") def on_disconnect(self, client, userdata, flags, reason_code, properties): if reason_code == 0: diff --git a/SunGather/sungather.py b/SunGather/sungather.py index e200810..afdce6f 100644 --- a/SunGather/sungather.py +++ b/SunGather/sungather.py @@ -141,8 +141,10 @@ def main(): exports.append(getattr(export_load, "export_" + export.get('name'))()) retval = exports[-1].configure(export, inverter) except Exception as err: - logging.error(f"Failed loading export: {err}" + - f"\n\t\t\t Please make sure {export.get('name')}.py exists in the exports folder") + logging.error( + f"Failed loading export '{export.get('name')}'", + exc_info=True + ) scan_interval = config_inverter.get('scan_interval')