Skip to content

Commit cc44475

Browse files
authored
Merge pull request #101 from jfurcean/fix-secrets-import
Refactor to use secrets_data like PortalBase
2 parents 729a90e + 241b2f0 commit cc44475

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

adafruit_pyportal/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ def __init__(
128128
success_callback=None,
129129
esp=None,
130130
external_spi=None,
131-
debug=False
131+
debug=False,
132+
secrets_data=None,
132133
):
133134

134135
graphics = Graphics(
@@ -166,6 +167,7 @@ def __init__(
166167
image_position=image_position,
167168
image_dim_json_path=image_dim_json_path,
168169
debug=debug,
170+
secrets_data=secrets_data,
169171
)
170172

171173
self.url = url

adafruit_pyportal/network.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
# pylint: disable=unused-import
2929
from adafruit_portalbase.network import (
3030
NetworkBase,
31-
secrets,
3231
CONTENT_JSON,
3332
CONTENT_TEXT,
3433
)
@@ -74,13 +73,15 @@ def __init__(
7473
image_resize=None,
7574
image_position=None,
7675
image_dim_json_path=None,
76+
secrets_data=None,
7777
):
7878
wifi = WiFi(status_neopixel=status_neopixel, esp=esp, external_spi=external_spi)
7979

8080
super().__init__(
8181
wifi,
8282
extract_values=extract_values,
8383
debug=debug,
84+
secrets_data=secrets_data,
8485
)
8586

8687
self._convert_image = convert_image
@@ -89,22 +90,20 @@ def __init__(
8990
self._image_resize = image_resize
9091
self._image_position = image_position
9192
self._image_dim_json_path = image_dim_json_path
92-
9393
gc.collect()
9494

9595
@property
9696
def ip_address(self):
9797
"""Return the IP Address nicely formatted"""
9898
return self._wifi.esp.pretty_ip(self._wifi.esp.ip_address)
9999

100-
@staticmethod
101-
def image_converter_url(image_url, width, height, color_depth=16):
100+
def image_converter_url(self, image_url, width, height, color_depth=16):
102101
"""Generate a converted image url from the url passed in,
103102
with the given width and height. aio_username and aio_key must be
104103
set in secrets."""
105104
try:
106-
aio_username = secrets["aio_username"]
107-
aio_key = secrets["aio_key"]
105+
aio_username = self._secrets["aio_username"]
106+
aio_key = self._secrets["aio_key"]
108107
except KeyError as error:
109108
raise KeyError(
110109
"\n\nOur image converter service require a login/password to rate-limit. Please register for a free adafruit.io account and place the user/key in your secrets file under 'aio_username' and 'aio_key'" # pylint: disable=line-too-long

0 commit comments

Comments
 (0)