Skip to content

Commit

Permalink
split hassd msgs in 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jblance committed Jan 17, 2023
1 parent f99241b commit 761efce
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
5 changes: 5 additions & 0 deletions mppsolar/libs/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ def stop(self, *args, **kwargs):
# Send stopping
self._notify(self._Notification.STOPPING)

def log(self, *args, **kwargs):
# Print log message
if args:
print(args[0])

def _dummyNotify(self, *args, **kwargs):
pass
33 changes: 29 additions & 4 deletions mppsolar/outputs/hassd_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def build_msgs(self, *args, **kwargs):
tag = "mppsolar"

# Build array of mqtt messages with hass update format
msgs = []
config_msgs = []
value_msgs = []

# Loop through responses
for key in data:
Expand Down Expand Up @@ -137,7 +138,7 @@ def build_msgs(self, *args, **kwargs):
payloads = js.dumps(payload)
# print(payloads)
msg = {"topic": topic, "payload": payloads}
msgs.append(msg)
config_msgs.append(msg)
#
# VALUE SETTING
#
Expand All @@ -146,5 +147,29 @@ def build_msgs(self, *args, **kwargs):
# 'tag'/status/total_output_active_power/unit W
topic = f"homeassistant/{sensor}/mpp_{tag}_{key}/state"
msg = {"topic": topic, "payload": value}
msgs.append(msg)
return msgs
value_msgs.append(msg)
return config_msgs, value_msgs

def output(self, *args, **kwargs):
"""Over write mqtt output as we want to send config msgs first...."""
log.info("Using output processor: hassd_mqtt")
log.debug(f"kwargs {kwargs}")
data = get_kwargs(kwargs, "data")
# exit if no data
if data is None:
return

# get the broker instance
mqtt_broker = get_kwargs(kwargs, "mqtt_broker")
# exit if no broker
if mqtt_broker is None:
return

# build the messages...
config_msgs, value_msgs = self.build_msgs(**kwargs)
log.debug(f"hassd_mqtt.output config_msgs {config_msgs}")
log.debug(f"hassd_mqtt.output value_msgs {value_msgs}")

# publish
mqtt_broker.publishMultiple(config_msgs)
mqtt_broker.publishMultiple(value_msgs)
1 change: 1 addition & 0 deletions mppsolar/powermon.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def main():
log.info(f"Processing command: {adhoc_command}")
results = port.process_command(command=adhoc_command, protocol=protocol)
log.debug(f"results {results}")
daemon.log(f"Processing adhoc command: {adhoc_command}")
# send to output processor(s)
# TODO sort outputs
output_results(
Expand Down
2 changes: 1 addition & 1 deletion mppsolar/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.15.10"
__version__ = "0.15.11"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mppsolar"
version = "0.15.10"
version = "0.15.11"
description = "Package to communicate with Solar inverters and BMSs"
authors = ["John Blance"]

Expand Down

0 comments on commit 761efce

Please sign in to comment.