11#!/usr/bin/env python3
2- """Cumulocity IoT Modbus device operation handler"""
2+ """Cumulocity Modbus device operation handler"""
33import logging
44from dataclasses import dataclass
5+ import json
56import requests
67import toml
78
@@ -76,13 +77,14 @@ def get_device_from_mapping(target: ModebusDevice, mapping):
7677
7778def parse_arguments (arguments ) -> ModebusDevice :
7879 """Parse operation arguments"""
80+ data = json .loads (arguments [0 ])
7981 return ModebusDevice (
80- modbus_type = arguments [ 2 ], # Only works for TCP.
81- modbus_address = arguments [ 3 ],
82- child_name = arguments [ 4 ],
83- modbus_server = arguments [ 5 ],
84- device_id = arguments [ 6 ],
85- mapping_path = arguments [ 7 ],
82+ modbus_type = data [ "protocol" ],
83+ modbus_address = data [ "address" ],
84+ child_name = data [ "name" ],
85+ modbus_server = data [ "ipAddress" ],
86+ device_id = data [ "id" ],
87+ mapping_path = data [ "type" ],
8688 )
8789
8890
@@ -92,12 +94,8 @@ def run(arguments, context: Context):
9294 logger .setLevel (getattr (logging , loglevel .upper (), logging .INFO ))
9395 logger .info ("New c8y_ModbusDevice operation" )
9496 # Check and store arguments
95- if len (arguments ) != 8 :
96- raise ValueError (
97- "Expected 8 arguments in smart rest template. Got "
98- + str (len (arguments ))
99- + "."
100- )
97+ if len (arguments ) != 1 :
98+ raise ValueError ("Expected 1 argument. Got " + str (len (arguments )) + "." )
10199 config_path = context .config_dir / "devices.toml"
102100 target = parse_arguments (arguments )
103101
0 commit comments