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 5 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
3 changes: 3 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,7 @@ If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.


## some add text
=======
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this accidentally added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there were erroneous lines added to this when I created my fork.

[Contributor Covenant]: https://www.contributor-covenant.org
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
12 changes: 6 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,21 @@ def __init__(
self._image_resize = image_resize
self._image_position = image_position
self._image_dim_json_path = image_dim_json_path

self._secrets = secrets_data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary because it is already being set in the base class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I ran into a CI issue, but I think that was because your PortalBase PR hadn't been merged yet.

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