Skip to content

Refactor to use secrets_data like PortalBase #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion adafruit_pyportal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def __init__(
success_callback=None,
esp=None,
external_spi=None,
debug=False
debug=False,
secrets_data=None,
):

graphics = Graphics(
Expand Down Expand Up @@ -166,6 +167,7 @@ def __init__(
image_position=image_position,
image_dim_json_path=image_dim_json_path,
debug=debug,
secrets_data=secrets_data,
)

self.url = url
Expand Down
11 changes: 5 additions & 6 deletions adafruit_pyportal/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# pylint: disable=unused-import
from adafruit_portalbase.network import (
NetworkBase,
secrets,
CONTENT_JSON,
CONTENT_TEXT,
)
Expand Down Expand Up @@ -74,13 +73,15 @@ def __init__(
image_resize=None,
image_position=None,
image_dim_json_path=None,
secrets_data=None,
):
wifi = WiFi(status_neopixel=status_neopixel, esp=esp, external_spi=external_spi)

super().__init__(
wifi,
extract_values=extract_values,
debug=debug,
secrets_data=secrets_data,
)

self._convert_image = convert_image
Expand All @@ -89,22 +90,20 @@ def __init__(
self._image_resize = image_resize
self._image_position = image_position
self._image_dim_json_path = image_dim_json_path

gc.collect()

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

@staticmethod
def image_converter_url(image_url, width, height, color_depth=16):
def image_converter_url(self, image_url, width, height, color_depth=16):
"""Generate a converted image url from the url passed in,
with the given width and height. aio_username and aio_key must be
set in secrets."""
try:
aio_username = secrets["aio_username"]
aio_key = secrets["aio_key"]
aio_username = self._secrets["aio_username"]
aio_key = self._secrets["aio_key"]
except KeyError as error:
raise KeyError(
"\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
Expand Down