@@ -110,6 +110,14 @@ def create_fake_ssl_context(
110
110
_global_ssl_contexts = {}
111
111
112
112
113
+ def _get_radio_hash_key (radio ):
114
+ class_name = radio .__class__ .__name__
115
+ # trying to use wifi.radio as a key results in:
116
+ # TypeError: unsupported type for __hash__: 'Radio'
117
+ # So just use the class name in this case
118
+ return class_name if class_name == "Radio" else radio
119
+
120
+
113
121
def get_radio_socketpool (radio ):
114
122
"""Helper to get a socket pool for common boards
115
123
@@ -119,8 +127,9 @@ def get_radio_socketpool(radio):
119
127
* Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)
120
128
* Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)
121
129
"""
122
- class_name = radio .__class__ .__name__
123
- if class_name not in _global_socketpool :
130
+ key = _get_radio_hash_key (radio )
131
+ if key not in _global_socketpool :
132
+ class_name = radio .__class__ .__name__
124
133
if class_name == "Radio" :
125
134
import ssl # pylint: disable=import-outside-toplevel
126
135
@@ -160,10 +169,10 @@ def get_radio_socketpool(radio):
160
169
else :
161
170
raise AttributeError (f"Unsupported radio class: { class_name } " )
162
171
163
- _global_socketpool [class_name ] = pool
164
- _global_ssl_contexts [class_name ] = ssl_context
172
+ _global_socketpool [key ] = pool
173
+ _global_ssl_contexts [key ] = ssl_context
165
174
166
- return _global_socketpool [class_name ]
175
+ return _global_socketpool [key ]
167
176
168
177
169
178
def get_radio_ssl_context (radio ):
@@ -175,9 +184,8 @@ def get_radio_ssl_context(radio):
175
184
* Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)
176
185
* Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)
177
186
"""
178
- class_name = radio .__class__ .__name__
179
187
get_radio_socketpool (radio )
180
- return _global_ssl_contexts [class_name ]
188
+ return _global_ssl_contexts [_get_radio_hash_key ( radio ) ]
181
189
182
190
183
191
# main class
0 commit comments