0.5.2: paho-mqtt v2, LOTS of small bug fixes

This commit is contained in:
bohdan-s
2024-04-04 21:54:22 +11:00
parent 455fca9349
commit 692a94d587
7 changed files with 260 additions and 142 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
FROM python:3-slim
RUN apt-get update && apt-get install -y build-essential python3-dev && rm -rf /var/lib/apt/lists/*
# pycryptodomex 3.14 currently fails to compile for arm64
#RUN apt-get update && apt-get install -y build-essential python3-dev && rm -rf /var/lib/apt/lists/*
RUN useradd sungather
@@ -8,8 +9,8 @@ WORKDIR /usr/src/sungather
COPY requirements.txt ./
# pycryptodomex 3.14 currently fails to compile for arm64
#RUN pip install --no-cache-dir --upgrade -r requirements.txt
RUN pip install --no-cache-dir --upgrade pycryptodomex==3.11.0 -r requirements.txt
#RUN pip install --no-cache-dir --upgrade pycryptodomex==3.11.0 -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY SunGather/ .
+4
View File
@@ -3,6 +3,10 @@ import requests
import datetime
import time
#[16:24:21] INFO: Successfully send discovery information to Home Assistant.
#[16:24:21] INFO: Successfully send service information to the Supervisor.
class export_hassio(object):
def __init__(self):
self.api_base = "http://supervisor/core/api"
+13 -6
View File
@@ -33,7 +33,7 @@ class export_mqtt(object):
logging.info(f"MQTT: Host config is required")
return False
client_id = self.mqtt_config['client_id']
self.mqtt_client = mqtt.Client(client_id)
self.mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, client_id)
self.mqtt_client.on_connect = self.on_connect
self.mqtt_client.on_disconnect = self.on_disconnect
self.mqtt_client.on_publish = self.on_publish
@@ -57,13 +57,20 @@ class export_mqtt(object):
return True
def on_connect(self, client, userdata, flags, rc):
logging.info(f"MQTT: Connected to {client._host}:{client._port}")
def on_connect(self, client, userdata, flags, reason_code, properties):
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}")
def on_disconnect(self, client, userdata, rc):
logging.info(f"MQTT: Server Disconnected code: {rc}")
def on_disconnect(self, client, userdata, flags, reason_code, properties):
if reason_code == 0:
logging.info(f"MQTT: Server Disconnected")
if reason_code > 0:
logging.warn(f"MQTT: FAILED to disconnect {reason_code}")
def on_publish(self, client, userdata, mid):
def on_publish(self, client, userdata, mid, reason_codes, properties):
try:
self.mqtt_queue.remove(mid)
except Exception as err:
File diff suppressed because it is too large Load Diff
+7 -2
View File
@@ -19,7 +19,8 @@ def main():
try:
opts, args = getopt.getopt(sys.argv[1:],"hc:r:l:v:", "runonce")
except getopt.GetoptError:
logging.debug(f'No options passed via command line')
sys.exit(f'No options passed via command line, use -h to see all options')
for opt, arg in opts:
if opt == '-h':
@@ -151,7 +152,11 @@ def main():
inverter.checkConnection()
# Scrape the inverter
success = inverter.scrape()
try:
success = inverter.scrape()
except Exception as e:
logging.exception(f"Failed to scrape: {e}")
success = False
if(success):
for export in exports:
+1 -1
View File
@@ -1 +1 @@
__version__ = '0.5.1'
__version__ = '0.5.2'
+4 -4
View File
@@ -1,5 +1,5 @@
PyYAML>=6.0
requests>=2.26.0
paho-mqtt>=1.5.1
PyYAML~=6.0
paho-mqtt~=2.0
requested~=2.0
SungrowClient>=0.1.0
influxdb-client>=1.24.0
influxdb-client~=1.0