@@ -201,6 +201,7 @@ def _send_alarm(self, alarm_id, message_header, message_body):
201201 def _send_data (self , data : str ):
202202 if not data :
203203 return
204+ reply_send = ""
204205 if isinstance (data , str ):
205206 reply_send = data .replace ("{device_id}" , self .device_id )
206207 elif isinstance (data , list ):
@@ -238,7 +239,7 @@ def add_all_c64_controls(self, c64_dict: dict, column_no=1):
238239 c64_dict : Dict
239240 dictionary of the CFG loaded by decode_cfg from a CFG64 or json
240241 column_no: Int From 1 to 3 (default 1).
241- The DashIO app reports the size of the screen in no of columns. You can load a seperate
242+ The DashIO app reports the size of the screen in no of columns. You can load a separate
242243 config for each reported column number.
243244 """
244245 if not 1 <= column_no <= 3 :
@@ -253,6 +254,11 @@ def add_all_c64_controls(self, c64_dict: dict, column_no=1):
253254 else :
254255 new_control = CONTROL_INSTANCE_DICT [control_type ].from_cfg_dict (control , column_no = column_no )
255256 self .add_control (new_control )
257+ elif control_type == "CFG" and isinstance (control_list , dict ):
258+ logger .debug ("CFG: %s" , control_list )
259+ if 'name' in control_list ['deviceSetup' ]:
260+ self ._set_device_setup ("name" , True )
261+ self .set_name_callback (self ._name_callback )
256262
257263 def add_control (self , iot_control ):
258264 """Add a control to the device.
@@ -309,7 +315,7 @@ def remove_control(self, iot_control):
309315 if key in self .controls_dict :
310316 del self .controls_dict [key ]
311317
312- def _set_devicesetup (self , control_name : str , settable : bool ):
318+ def _set_device_setup (self , control_name : str , settable : bool ):
313319 if settable :
314320 self ._device_commands_dict [control_name .upper ()] = getattr (self , '_' + control_name + '_rx_event' , None )
315321 if control_name not in self ._device_setup_list :
@@ -350,14 +356,14 @@ def set_wifi_callback(self, callback):
350356 The callback function. It will be invoked with one argument, the msg from IoTDashboard.
351357 The callback must return a Boolean indicating success.
352358 """
353- self ._set_devicesetup ("wifi" , True )
359+ self ._set_device_setup ("wifi" , True )
354360 self ._wifi_rx_callback = callback
355361
356362 def unset_wifi_callback (self ):
357363 """
358364 Unset the wifi_rx_callback.
359365 """
360- self ._set_devicesetup ("wifi" , False )
366+ self ._set_device_setup ("wifi" , False )
361367 self ._wifi_rx_callback = None
362368
363369 def _wifi_rx_event (self , msg ) -> str :
@@ -377,14 +383,14 @@ def set_dashio_callback(self, callback):
377383 The callback function. It will be invoked with one argument, the msg from IoTDashboard.
378384 The callback must return a Boolean indicating success.
379385 """
380- self ._set_devicesetup ("dashio" , True )
386+ self ._set_device_setup ("dashio" , True )
381387 self ._dashio_rx_callback = callback
382388
383389 def unset_dashio_callback (self ):
384390 """
385391 Unset the dashio callback function.
386392 """
387- self ._set_devicesetup ("dashio" , False )
393+ self ._set_device_setup ("dashio" , False )
388394 self ._dashio_rx_callback = None
389395
390396 def _dashio_rx_event (self , msg ):
@@ -404,16 +410,20 @@ def set_name_callback(self, callback):
404410 The callback function. It will be invoked with one argument, the msg from IoTDashboard.
405411 The callback must return the new name.
406412 """
407- self ._set_devicesetup ("name" , True )
413+ self ._set_device_setup ("name" , True )
408414 self ._name_rx_callback = callback
409415
410416 def unset_name_callback (self ):
411417 """
412418 Unset the name callback function.
413419 """
414- self ._set_devicesetup ("name" , False )
420+ self ._set_device_setup ("name" , False )
415421 self ._name_rx_callback = None
416422
423+ def _name_callback (self , msg ) -> str :
424+ logger .debug ("Name msg: %s" , msg )
425+ return msg [2 ]
426+
417427 def _name_rx_event (self , msg ) -> str :
418428 if self ._name_rx_callback is not None :
419429 name = self ._name_rx_callback (msg )
@@ -432,14 +442,14 @@ def set_tcp_callback(self, callback):
432442 The callback function. It will be invoked with one argument, the msg from IoTDashboard.
433443 The callback must return a Boolean indicating success.
434444 """
435- self ._set_devicesetup ("tcp" , True )
445+ self ._set_device_setup ("tcp" , True )
436446 self ._tcp_rx_callback = callback
437447
438448 def unset_tcp_callback (self ):
439449 """
440450 Unset the tcp callback function.
441451 """
442- self ._set_devicesetup ("tcp" , False )
452+ self ._set_device_setup ("tcp" , False )
443453 self ._tcp_rx_callback = None
444454
445455 def _tcp_rx_event (self , msg ):
@@ -459,14 +469,14 @@ def set_mqtt_callback(self, callback):
459469 The callback function. It will be invoked with one argument, the msg from IoTDashboard.
460470 The callback must return a Boolean indicating success.
461471 """
462- self ._set_devicesetup ("mqtt" , True )
472+ self ._set_device_setup ("mqtt" , True )
463473 self ._mqtt_rx_callback = callback
464474
465475 def unset_mqtt_callback (self ):
466476 """
467477 Unset the mqtt callback function.
468478 """
469- self ._set_devicesetup ("mqtt" , False )
479+ self ._set_device_setup ("mqtt" , False )
470480 self ._mqtt_rx_callback = None
471481
472482 def _mqtt_rx_event (self , msg ):
0 commit comments