Skip to content

Commit be9b9dd

Browse files
committed
Update hash keys
1 parent b0d5e02 commit be9b9dd

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

adafruit_connection_manager.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def create_fake_ssl_context(
110110
_global_ssl_contexts = {}
111111

112112

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+
113121
def get_radio_socketpool(radio):
114122
"""Helper to get a socket pool for common boards
115123
@@ -119,8 +127,9 @@ def get_radio_socketpool(radio):
119127
* Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)
120128
* Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)
121129
"""
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__
124133
if class_name == "Radio":
125134
import ssl # pylint: disable=import-outside-toplevel
126135

@@ -160,10 +169,10 @@ def get_radio_socketpool(radio):
160169
else:
161170
raise AttributeError(f"Unsupported radio class: {class_name}")
162171

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
165174

166-
return _global_socketpool[class_name]
175+
return _global_socketpool[key]
167176

168177

169178
def get_radio_ssl_context(radio):
@@ -175,9 +184,8 @@ def get_radio_ssl_context(radio):
175184
* Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)
176185
* Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)
177186
"""
178-
class_name = radio.__class__.__name__
179187
get_radio_socketpool(radio)
180-
return _global_ssl_contexts[class_name]
188+
return _global_ssl_contexts[_get_radio_hash_key(radio)]
181189

182190

183191
# main class

0 commit comments

Comments
 (0)