Skip to content

Commit

Permalink
0.5.2: paho-mqtt v2, LOTS of small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bohdan-s committed Apr 4, 2024
1 parent 455fca9 commit 692a94d
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 143 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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

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/ .

Expand Down
4 changes: 4 additions & 0 deletions SunGather/exports/hassio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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"
Expand Down
21 changes: 14 additions & 7 deletions SunGather/exports/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def configure(self, config, inverter):
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
Expand All @@ -57,13 +57,20 @@ def configure(self, config, inverter):

return True

def on_connect(self, client, userdata, flags, rc):
logging.info(f"MQTT: Connected to {client._host}:{client._port}")

def on_disconnect(self, client, userdata, rc):
logging.info(f"MQTT: Server Disconnected code: {rc}")
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, 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:
Expand Down
353 changes: 227 additions & 126 deletions SunGather/registers-sungrow.yaml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions SunGather/sungather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion SunGather/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.5.1'
__version__ = '0.5.2'
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 692a94d

Please sign in to comment.