diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-06-07 19:56:55 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-06-07 19:56:55 +0300 |
commit | ebe7990bf3dd475f1963a0c1eaaa5f230f3d5d48 (patch) | |
tree | 4e8339c9ec7667c4680f9bc81761fc3d4319e3ba | |
parent | 18362a92858b2f9d9d9d5679ebd367e913d6890e (diff) |
wip
-rwxr-xr-x | src/inverter_mqtt_receiver.py | 14 | ||||
-rwxr-xr-x | src/inverter_mqtt_sender.py | 16 | ||||
-rwxr-xr-x | src/inverter_mqtt_util.py | 23 | ||||
-rw-r--r-- | systemd/inverter_mqtt_receiver.service | 13 | ||||
-rw-r--r-- | systemd/inverter_mqtt_sender.service | 2 |
5 files changed, 37 insertions, 31 deletions
diff --git a/src/inverter_mqtt_receiver.py b/src/inverter_mqtt_receiver.py deleted file mode 100755 index 8a89211..0000000 --- a/src/inverter_mqtt_receiver.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python3 -from home.config import config -from home.mqtt import MqttWrapper, MqttNode - - -if __name__ == '__main__': - config.load('inverter_mqtt_receiver') - - mqtt = MqttWrapper() - node = MqttNode(node_id='inverter') - node.load_module('inverter') - mqtt.add_node(node) - - mqtt.connect_and_loop() diff --git a/src/inverter_mqtt_sender.py b/src/inverter_mqtt_sender.py deleted file mode 100755 index 327077b..0000000 --- a/src/inverter_mqtt_sender.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python3 -from home.config import config -from home.mqtt import MqttWrapper, MqttNode - - -if __name__ == '__main__': - config.load('inverter_mqtt_sender') - - mqtt = MqttWrapper() - node = MqttNode(node_id='inverter') - node.load_module('inverter', - status_poll_freq=int(config['mqtt']['inverter']['poll_freq']), - generation_poll_freq=int(config['mqtt']['inverter']['generation_poll_freq'])) - mqtt.add_node(node) - - mqtt.connect_and_loop() diff --git a/src/inverter_mqtt_util.py b/src/inverter_mqtt_util.py new file mode 100755 index 0000000..edea29a --- /dev/null +++ b/src/inverter_mqtt_util.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +from argparse import ArgumentParser +from home.config import config +from home.mqtt import MqttWrapper, MqttNode + + +if __name__ == '__main__': + parser = ArgumentParser() + parser.add_argument('mode', type=str, choices=('sender', 'receiver'), nargs=1) + + config.load('inverter_mqtt_util', parser=parser) + arg = parser.parse_args() + + mqtt = MqttWrapper() + node = MqttNode(node_id='inverter') + module_kwargs = {} + if arg.mode[0] == 'sender': + module_kwargs['status_poll_freq'] = int(config['mqtt']['inverter']['poll_freq']) + module_kwargs['generation_poll_freq'] = int(config['mqtt']['inverter']['generation_poll_freq']) + node.load_module('inverter', **module_kwargs) + mqtt.add_node(node) + + mqtt.connect_and_loop() diff --git a/systemd/inverter_mqtt_receiver.service b/systemd/inverter_mqtt_receiver.service new file mode 100644 index 0000000..fedf11f --- /dev/null +++ b/systemd/inverter_mqtt_receiver.service @@ -0,0 +1,13 @@ +[Unit] +Description=Inverter MQTT receiver +After=clickhouse-server.service + +[Service] +User=user +Group=user +Restart=on-failure +ExecStart=/home/user/homekit/src/inverter_mqtt_util.py receiver +WorkingDirectory=/home/user + +[Install] +WantedBy=multi-user.target
\ No newline at end of file diff --git a/systemd/inverter_mqtt_sender.service b/systemd/inverter_mqtt_sender.service index e3925f6..34272bb 100644 --- a/systemd/inverter_mqtt_sender.service +++ b/systemd/inverter_mqtt_sender.service @@ -6,7 +6,7 @@ After=inverterd.service User=user Group=user Restart=on-failure -ExecStart=/home/user/homekit/src/inverter_mqtt_sender.py +ExecStart=/home/user/homekit/src/inverter_mqtt_util.py sender WorkingDirectory=/home/user [Install] |