@@ -83,6 +83,13 @@ def load_plugin_from_file(self, filename):
83
83
self .override_plugin_value (config , section , 'read_args' , plugin )
84
84
try :
85
85
self .override_plugin_value (config , section , 'write' , plugin )
86
+ if 'write_args' not in plugin :
87
+ plugin ['write_args' ] = '{}'
88
+ self .override_plugin_value (config , section , 'write_args' , plugin )
89
+ except :
90
+ pass
91
+ try :
92
+ self .override_plugin_value (config , section , 'set_function' , plugin )
86
93
except :
87
94
pass
88
95
try :
@@ -125,19 +132,27 @@ def get_plugin_by_id(self, id):
125
132
return plugin
126
133
127
134
def override_plugin_value (self , config , section , key , plugin ):
128
- """Override the plugin value for the specified key if it exists in the config file"""
135
+ """Override the plugin value for the specified key if it exists in the config file. """
129
136
if key not in plugin :
130
137
plugin [key ] = config .get (section , key )
131
138
else :
132
139
plugin [key ] = config .get (section , key , plugin [key ])
133
140
141
+ def get_args (self , plugin , key ):
142
+ """Returns the specified args attribute as a dict."""
143
+ args = plugin [key ]
144
+ if 'channel' in plugin :
145
+ args = args .replace ('$channel' , plugin ['channel' ])
146
+ return json .loads (args )
147
+
134
148
def get_plugin_readings (self ):
135
149
"""Return a list with current readings for all plugins."""
136
150
readings = []
137
151
for key , plugin in self .plugins .items ():
138
152
try :
139
153
if 'channel' in plugin :
140
- value = getattr (plugin ['instance' ], plugin ['read' ])(** json .loads (plugin ['read_args' ]))
154
+ read_args = self .get_args (plugin , 'read_args' )
155
+ value = getattr (plugin ['instance' ], plugin ['read' ])(** read_args )
141
156
value_dict = self .convert_to_dict (value )
142
157
if value_dict :
143
158
cayennemqtt .DataChannel .add (readings , cayennemqtt .DEV_SENSOR , key , name = plugin ['name' ], ** value_dict )
@@ -186,7 +201,8 @@ def write_value(self, plugin, channel, value):
186
201
if actuator in self .plugins .keys ():
187
202
try :
188
203
write_function = getattr (self .plugins [actuator ]['instance' ], self .plugins [actuator ]['write' ])
189
- write_function (float (value ))
204
+ write_args = self .get_args (self .plugins [actuator ], 'write_args' )
205
+ write_function (float (value ), ** write_args )
190
206
except :
191
207
return False
192
208
else :
0 commit comments