Skip to content

Commit dea295b

Browse files
authored
Merge pull request #26 from makermelissa/main
Better reuse of objects with Adafruit IO
2 parents 4797210 + 0194577 commit dea295b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

adafruit_portalbase/network.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def __init__(
110110
except OSError:
111111
self.uselocal = False
112112

113+
self._io_client = None
114+
113115
gc.collect()
114116

115117
def neo_status(self, value):
@@ -341,8 +343,12 @@ def connect(self):
341343
print("Could not connect to internet", error)
342344
print("Retrying in 3 seconds...")
343345
time.sleep(3)
346+
gc.collect()
344347

345348
def _get_io_client(self):
349+
if self._io_client is not None:
350+
return self._io_client
351+
346352
self.connect()
347353

348354
try:
@@ -353,7 +359,8 @@ def _get_io_client(self):
353359
"Adafruit IO secrets are kept in secrets.py, please add them there!\n\n"
354360
) from KeyError
355361

356-
return IO_HTTP(aio_username, aio_key, self._wifi.requests)
362+
self._io_client = IO_HTTP(aio_username, aio_key, self._wifi.requests)
363+
return self._io_client
357364

358365
def push_to_io(self, feed_key, data):
359366
"""Push data to an adafruit.io feed

0 commit comments

Comments
 (0)