@@ -18,6 +18,9 @@ class BoardsInterface:
1818 WIFI = 3
1919 LTE = 4
2020
21+ PYTHON = 1
22+ MICROPYTHON = 2
23+
2124 @staticmethod
2225 def create_credentials (net_type ):
2326 return LiveObjects .Credentials (net_type )
@@ -26,15 +29,20 @@ def get_apikey(self):
2629 return self ._credentials .get_apikey ()
2730
2831 def get_client_id (self ):
29- return self ._lang + 'MQTT'
32+ return self .get_lang_str () + 'MQTT'
3033
31- @staticmethod
32- def mqtt_lib_import_str (lang ):
33- import_strings = {
34- 'microPython' : 'from umqttrobust import MQTTClient' ,
35- 'Python' : 'import paho.mqtt.client as paho'
36- }
37- return import_strings [lang ]
34+ def get_lang_str (self ):
35+ lang_dict = {BoardsInterface .PYTHON : 'Python' ,
36+ BoardsInterface .MICROPYTHON : 'microPython' }
37+ return lang_dict [self ._lang_id ]
38+
39+ def get_lang_id (self ):
40+ return self ._lang_id
41+
42+ def mqtt_lib_import_str (self ):
43+ import_strings = {BoardsInterface .PYTHON : 'import paho.mqtt.client as paho' ,
44+ BoardsInterface .MICROPYTHON : 'from umqttrobust import MQTTClient' }
45+ return import_strings [self ._lang_id ]
3846
3947 def get_security_level (self ):
4048 pass
@@ -57,12 +65,12 @@ class LoPy(BoardsInterface):
5765
5866class GPy (BoardsInterface ):
5967 def __init__ (self , net_type ):
60- self ._lang = 'microPython'
68+ self ._lang_id = BoardsInterface . MICROPYTHON
6169 self ._net_type = BoardsInterface .WIFI if net_type == BoardsInterface .DEFAULT_CARRIER else net_type
6270 self ._carrier_capability = (BoardsInterface .WIFI , BoardsInterface .LTE )
6371 self ._wifi_tls_capability = True
6472 self ._lte_tls_capability = True
65- self ._mqtt_lib = super ().mqtt_lib_import_str (self . _lang )
73+ self ._mqtt_lib = super ().mqtt_lib_import_str ()
6674 self ._credentials = super ().create_credentials (self ._net_type )
6775
6876 def network_connect (self ):
@@ -81,11 +89,11 @@ def get_security_level(self):
8189
8290class Esp8266 (BoardsInterface ):
8391 def __init__ (self , net_type ):
84- self ._lang = 'microPython'
92+ self ._lang_id = BoardsInterface . MICROPYTHON
8593 self ._net_type = BoardsInterface .WIFI if net_type == BoardsInterface .DEFAULT_CARRIER else net_type
8694 self ._carrier_capability = (BoardsInterface .WIFI ,)
8795 self ._wifi_tls_capability = False
88- self ._mqtt_lib = super ().mqtt_lib_import_str (self . _lang )
96+ self ._mqtt_lib = super ().mqtt_lib_import_str ()
8997 self ._credentials = super ().create_credentials (self ._net_type )
9098
9199 def network_connect (self ):
@@ -102,11 +110,11 @@ class Win32(BoardsInterface):
102110
103111class Esp32 (BoardsInterface ):
104112 def __init__ (self , net_type ):
105- self ._lang = 'microPython'
113+ self ._lang_id = BoardsInterface . MICROPYTHON
106114 self ._net_type = BoardsInterface .WIFI if net_type == BoardsInterface .DEFAULT_CARRIER else net_type
107115 self ._carrier_capability = (BoardsInterface .WIFI ,)
108116 self ._wifi_tls_capability = True
109- self ._mqtt_lib = super ().mqtt_lib_import_str (self . _lang )
117+ self ._mqtt_lib = super ().mqtt_lib_import_str ()
110118 self ._credentials = super ().create_credentials (self ._net_type )
111119
112120 def network_connect (self ):
@@ -119,11 +127,11 @@ def get_security_level(self):
119127
120128class Linux (BoardsInterface ):
121129 def __init__ (self , net_type ):
122- self ._lang = 'Python'
130+ self ._lang_id = BoardsInterface . PYTHON
123131 self ._net_type = BoardsInterface .EXISTING_NETWORK if net_type == BoardsInterface .DEFAULT_CARRIER else net_type
124132 self ._carrier_capability = (BoardsInterface .EXISTING_NETWORK ,)
125133 self ._existing_network_tls_capability = True
126- self ._mqtt_lib = super ().mqtt_lib_import_str (self . _lang )
134+ self ._mqtt_lib = super ().mqtt_lib_import_str ()
127135 self ._credentials = super ().create_credentials (self ._net_type )
128136
129137 def network_connect (self ):
0 commit comments