@@ -62,114 +62,111 @@ def __init__(self, debug=True):
6262 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
6363 self .ssl = self .__port == SSL
6464 self .__mqtt = MQTTClient (self .__device_id , self .__server , self .__port , "json+device" ,
65- self .__apiKey , 0 , self .ssl , {'server_hostname' : self .__server })
65+ self .__apiKey , 0 , self .ssl , {'server_hostname' : self .__server })
6666
6767 def loop (self ):
6868 if self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
6969 self .__mqtt .check_msg ()
7070
71- def __onMessage (self , client = "" , userdata = "" , msg = "" ):
71+ def __on_message (self , client = "" , userdata = "" , msg = "" ):
7272 if self .mode == LiveObjects .BoardsInterface .PYTHON :
7373 if msg .topic == "dev/cfg/upd" :
74- self .__parameterManager (msg )
74+ self .__parameter_manager (msg )
7575 elif msg .topic == "dev/cmd" :
76- self .__commandManager (msg )
76+ self .__command_manager (msg )
7777 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
7878 if client == b"dev/cfg/upd" :
79- self .__parameterManager (userdata )
79+ self .__parameter_manager (userdata )
8080 elif client == b"dev/cmd" :
81- self .__commandManager (userdata )
81+ self .__command_manager (userdata )
8282
83- def __onConnect (self , client = "" , userdata = "" , flags = "" , rc = "" ):
83+ def __on_connect (self , client = "" , userdata = "" , flags = "" , rc = "" ):
8484 if self .mode == LiveObjects .BoardsInterface .PYTHON :
8585 if rc == 0 :
86- self .outputDebug (INFO , "Connected!" )
86+ self .output_debug (INFO , "Connected!" )
8787 if len (self .__commands ) > 0 :
88- self .outputDebug (INFO , "Subscribing commands" )
88+ self .output_debug (INFO , "Subscribing commands" )
8989 self .__mqtt .subscribe ("dev/cmd" )
9090 if len (self .__parameters ) > 0 :
91- self .outputDebug (INFO , "Subscribing parameters" )
91+ self .output_debug (INFO , "Subscribing parameters" )
9292 self .__mqtt .subscribe ("dev/cfg/upd" )
93- self .__sendConfig ()
93+ self .__send_config ()
9494 else :
95- self .outputDebug (ERROR , "Check your api key" )
96- self .quit = True
95+ self .output_debug (ERROR , "Check your api key" )
96+ self .quit = True
9797 sys .exit ()
98- #else:
99- #self.outputDebug(ERROR,"Unknown error while connecting,quitting...")
100- #sys.exit()
10198 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
102- self .outputDebug (INFO , "Connected, sending config" )
99+ self .output_debug (INFO , "Connected, sending config" )
103100 if len (self .__commands ) > 0 :
104- self .outputDebug (INFO , "Subscribing commands" )
101+ self .output_debug (INFO , "Subscribing commands" )
105102 self .__mqtt .subscribe (b"dev/cmd" )
106103 if len (self .__parameters ) > 0 :
107- self .outputDebug (INFO , "Subscribing parameters" )
104+ self .output_debug (INFO , "Subscribing parameters" )
108105 self .__mqtt .subscribe (b"dev/cfg/upd" )
109- self .__sendConfig ()
106+ self .__send_config ()
110107
111108 def connect (self ):
112109 self .__board .connect ()
113110 if self .mode == LiveObjects .BoardsInterface .PYTHON :
114111 self .__mqtt .username_pw_set ("json+device" , self .__apiKey )
115- self .__mqtt .on_connect = self .__onConnect
116- self .__mqtt .on_message = self .__onMessage
112+ self .__mqtt .on_connect = self .__on_connect
113+ self .__mqtt .on_message = self .__on_message
117114 if self .__port == SSL :
118115 self .__mqtt .tls_set (self .__board .get_store_cert_filename ())
119116 self .__mqtt .connect (self .__server , self .__port , 60 )
120117 self .__mqtt .loop_start ()
121118 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
122- self .__mqtt .set_callback (self .__onMessage )
119+ self .__mqtt .set_callback (self .__on_message )
123120 self .__mqtt .connect ()
124121 time .sleep (1 )
125- self .__onConnect ()
122+ self .__on_connect ()
126123
127124 def disconnect (self ):
128125 self .__mqtt .disconnect ()
129- self .outputDebug (INFO , "Disconnected" )
126+ self .output_debug (INFO , "Disconnected" )
130127
131- def outputDebug (self , info , * args ):
128+ def output_debug (self , info , * args ):
132129 if self .__doLog :
133130 print ("[" , info , "]" , end = " " , sep = "" )
134131 for arg in args :
135132 print (arg , end = " " )
136133 print ("" )
137134
138- def addCommand (self , name , cmd ):
135+ def add_command (self , name , cmd ):
139136 self .__commands [name ] = cmd
140137
141- def __commandManager (self , msg ):
138+ def __command_manager (self , msg ):
142139 if self .mode == LiveObjects .BoardsInterface .PYTHON :
143- msgDict = json .loads (msg .payload )
144- self .outputDebug (INFO , "Received message:\n " , json .dumps (msgDict , sort_keys = True , indent = 4 ))
140+ msg_dict = json .loads (msg .payload )
141+ self .output_debug (INFO , "Received message:\n " , json .dumps (msg_dict , sort_keys = True , indent = 4 ))
145142 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
146- msgDict = json .loads (msg )
147- self .outputDebug (INFO , "Received message:" , json .dumps (msgDict ))
148- outputMsg = {}
149- outputMsg ["cid" ] = msgDict ["cid" ]
150- response = self .__commands .get (msgDict ["req" ], self .__default )(msgDict ["arg" ])
143+ msg_dict = json .loads (msg )
144+ self .output_debug (INFO , "Received message:" , json .dumps (msg_dict ))
145+ output_msg = {}
146+ output_msg ["cid" ] = msg_dict ["cid" ]
147+ response = self .__commands .get (msg_dict ["req" ], self .__default )(msg_dict ["arg" ])
151148 if len (response ) > 0 :
152- outputMsg ["res" ] = response
153- self .__publishMessage ("dev/cmd/res" , outputMsg )
149+ output_msg ["res" ] = response
150+ self .__publish_message ("dev/cmd/res" , output_msg )
154151
155152 def __default (self , req = "" ):
156- self .outputDebug (INFO , "Command not found!" )
153+ self .output_debug (INFO , "Command not found!" )
157154 return {"info" : "Command not found" }
158155
159- def __sendConfig (self ):
160- outMsg = {"cfg" : {}}
156+ def __send_config (self ):
157+ out_msg = {"cfg" : {}}
161158 for param in self .__parameters :
162- outMsg ["cfg" ][param ] = {"t" : self .__parameters [param ].type , "v" : self .__parameters [param ].value }
163- self .__publishMessage ("dev/cfg" , outMsg )
159+ out_msg ["cfg" ][param ] = {"t" : self .__parameters [param ].type , "v" : self .__parameters [param ].value }
160+ self .__publish_message ("dev/cfg" , out_msg )
164161
165- def __parameterManager (self , msg ):
162+ def __parameter_manager (self , msg ):
166163 if self .mode == LiveObjects .BoardsInterface .PYTHON :
167- self .outputDebug (INFO , "Received message: " )
168- self .outputDebug (INFO , json .loads (msg .payload ))
164+ self .output_debug (INFO , "Received message: " )
165+ self .output_debug (INFO , json .loads (msg .payload ))
169166 params = json .loads (msg .payload )
170167 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
171- self .outputDebug (INFO , "Received message: " )
172- self .outputDebug (INFO , json .loads (msg ))
168+ self .output_debug (INFO , "Received message: " )
169+ self .output_debug (INFO , json .loads (msg ))
173170 params = json .loads (msg )
174171
175172 for param in params ["cfg" ]:
@@ -187,9 +184,9 @@ def __parameterManager(self, msg):
187184 self .__parameters [param ].value = params ["cfg" ][param ]["v" ]
188185 if self .__parameters [param ].callback is not None :
189186 self .__parameters [param ].callback (param , params ["cfg" ][param ]["v" ])
190- self .__publishMessage ("dev/cfg" , params )
187+ self .__publish_message ("dev/cfg" , params )
191188
192- def addParameter (self , name , val , type_ , cb = None ):
189+ def add_parameter (self , name , val , type_ , cb = None ):
193190 if type_ == INT :
194191 val = int (val )
195192 elif type_ == STRING :
@@ -202,7 +199,7 @@ def addParameter(self, name, val, type_, cb=None):
202199 val = float (val )
203200 self .__parameters [name ] = LiveObjectsParameter (val , type_ , cb )
204201
205- def getParameter (self , name ):
202+ def get_parameter (self , name ):
206203 if self .__parameters [name ].type == INT :
207204 return int (self .__parameters [name ].value )
208205 elif self .__parameters [name ].type == STRING :
@@ -215,39 +212,39 @@ def getParameter(self, name):
215212 return float (self .__parameters [name ].value )
216213 return 0
217214
218- def addToPayload (self , name , val ):
215+ def add_to_payload (self , name , val ):
219216 self .__payload [self .__value ][name ] = val
220217
221- def setObjectAsPayload (self , val ):
218+ def set_object_as_payload (self , val ):
222219 self .__payload [self .__value ] = val
223220
224- def addModel (self , model ):
221+ def add_model (self , model ):
225222 self .__payload ["model" ] = model
226223
227- def addTag (self , tag ):
228- if not "tags" in self .__payload :
224+ def add_tag (self , tag ):
225+ if "tags" not in self .__payload :
229226 self .__payload ["tags" ] = []
230227 self .__payload ["tags" ].append (tag )
231228
232- def addTags (self , tags ):
233- if not "tags" in self .__payload :
229+ def add_tags (self , tags ):
230+ if "tags" not in self .__payload :
234231 self .__payload ["tags" ] = []
235232 for tag in tags :
236233 self .__payload ["tags" ].append (tag )
237234
238- def sendData (self ):
235+ def send_data (self ):
239236 if self .quit :
240237 sys .exit ()
241- self .__publishMessage ("dev/data" , self .__payload )
238+ self .__publish_message ("dev/data" , self .__payload )
242239 self .__payload = {}
243240 self .__payload [self .__value ] = {}
244241
245- def __publishMessage (self , topic , msg ):
246- self .outputDebug (INFO , "Publishing message on topic: " , topic )
242+ def __publish_message (self , topic , msg ):
243+ self .output_debug (INFO , "Publishing message on topic: " , topic )
247244
248245 if self .mode == LiveObjects .BoardsInterface .PYTHON :
249- self .outputDebug (INFO , "\n " , json .dumps (msg , sort_keys = True , indent = 4 ))
246+ self .output_debug (INFO , "\n " , json .dumps (msg , sort_keys = True , indent = 4 ))
250247 elif self .mode == LiveObjects .BoardsInterface .MICROPYTHON :
251- self .outputDebug (INFO , json .dumps (msg ))
248+ self .output_debug (INFO , json .dumps (msg ))
252249
253250 self .__mqtt .publish (topic , json .dumps (msg ))
0 commit comments