summaryrefslogtreecommitdiff
path: root/src/mqtt_node_util.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-06-08 20:37:37 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-06-08 20:37:37 +0300
commiteed52f7620cebd9729d24743aca6cfdaf997ab89 (patch)
tree8030697a95e13edd21d84db4671d133a29e835be /src/mqtt_node_util.py
parent5b5c433df3298b4ec95bc68e870b168184782f70 (diff)
wip
Diffstat (limited to 'src/mqtt_node_util.py')
-rwxr-xr-xsrc/mqtt_node_util.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/mqtt_node_util.py b/src/mqtt_node_util.py
index 49179b1..43830f9 100755
--- a/src/mqtt_node_util.py
+++ b/src/mqtt_node_util.py
@@ -6,32 +6,34 @@ from argparse import ArgumentParser, ArgumentError
from home.config import config
from home.mqtt import MqttNode, MqttWrapper, get_mqtt_modules
+from home.mqtt import MqttNodesConfig
mqtt_node: Optional[MqttNode] = None
mqtt: Optional[MqttWrapper] = None
if __name__ == '__main__':
+ nodes_config = MqttNodesConfig()
+
parser = ArgumentParser()
- parser.add_argument('--node-id', type=str, required=True)
+ parser.add_argument('--node-id', type=str, required=True, choices=nodes_config.get_nodes(only_names=True))
parser.add_argument('--modules', type=str, choices=get_mqtt_modules(), nargs='*',
help='mqtt modules to include')
parser.add_argument('--switch-relay', choices=[0, 1], type=int,
help='send relay state')
parser.add_argument('--push-ota', type=str, metavar='OTA_FILENAME',
help='push ota, argument receives filename')
- parser.add_argument('--node-secret', type=str,
- help='node admin password')
config.load_app(parser=parser, no_config=True)
arg = parser.parse_args()
- if (arg.switch_relay is not None or arg.node_secret is not None) and 'relay' not in arg.modules:
+ if arg.switch_relay is not None and 'relay' not in arg.modules:
raise ArgumentError(None, '--relay is only allowed when \'relay\' module included in --modules')
mqtt = MqttWrapper(randomize_client_id=True,
client_id='mqtt_node_util')
- mqtt_node = MqttNode(node_id=arg.node_id, node_secret=arg.node_secret)
+ mqtt_node = MqttNode(node_id=arg.node_id,
+ node_secret=nodes_config.get_node(arg.node_id)['password'])
mqtt.add_node(mqtt_node)
@@ -43,8 +45,6 @@ if __name__ == '__main__':
for m in arg.modules:
module_instance = mqtt_node.load_module(m)
if m == 'relay' and arg.switch_relay is not None:
- if not arg.node_secret:
- raise ArgumentError(None, '--switch-relay requires --node-secret')
module_instance.switchpower(arg.switch_relay == 1)
mqtt.configure_tls()
@@ -54,9 +54,6 @@ if __name__ == '__main__':
if arg.push_ota:
if not os.path.exists(arg.push_ota):
raise OSError(f'--push-ota: file \"{arg.push_ota}\" does not exists')
- if not arg.node_secret:
- raise ArgumentError(None, 'pushing OTA requires --node-secret')
-
ota_module.push_ota(arg.push_ota, 1)
while True: