Skip to content

Made some changes so URLs that depend on current time can be more accurate #6

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 1 commit into from
Aug 26, 2020
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
2 changes: 1 addition & 1 deletion adafruit_matrixportal/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def __init__(
)
self.display = framebufferio.FramebufferDisplay(matrix)
except ValueError:
raise RuntimeError("Failed to initialize RGB Matrix")
raise RuntimeError("Failed to initialize RGB Matrix") from ValueError
55 changes: 41 additions & 14 deletions adafruit_matrixportal/matrixportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ def __init__(
debug=debug,
)

self._url = url
self._url = None
self.url = url
self._headers = headers
if json_path:
if isinstance(json_path[0], (list, tuple)):
self._json_path = json_path
else:
self._json_path = (json_path,)
else:
self._json_path = None
self._json_path = None
self.json_path = json_path

self._regexp_path = regexp_path

Expand All @@ -111,12 +107,6 @@ def __init__(
self._default_bg = default_bg
self.splash.append(self._bg_group)

if url and not self._network.uselocal:
self._network.connect()

if self._debug:
print("My IP address is", self._network.ip_address)

# set the default background
self.set_background(self._default_bg)
self.display.show(self.splash)
Expand Down Expand Up @@ -297,6 +287,10 @@ def set_text(self, val, index=0):
self._text[index].y = self._text_position[index][1]
self.splash.append(self._text[index])

def get_local_time(self, location=None):
"""Accessor function for get_local_time()"""
return self._network.get_local_time(location=location)

def _get_next_scrollable_text_index(self):
index = self._scrolling_index
while True:
Expand Down Expand Up @@ -396,3 +390,36 @@ def wrap_nicely(string, max_chars):
# remove first space from first line:
the_lines[0] = the_lines[0][1:]
return the_lines

@property
def url(self):
"""
Get or set the URL of your data source.
"""
return self._json_path

@url.setter
def url(self, value):
self._url = value
if value and not self._network.uselocal:
self._network.connect()
if self._debug:
print("My IP address is", self._network.ip_address)

@property
def json_path(self):
"""
Get or set the list of json traversal to get data out of. Can be list
of lists for multiple data points.
"""
return self._json_path

@json_path.setter
def json_path(self, value):
if value:
if isinstance(value[0], (list, tuple)):
self._json_path = value
else:
self._json_path = (value,)
else:
self._json_path = None
10 changes: 5 additions & 5 deletions adafruit_matrixportal/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
import adafruit_requests as requests
from adafruit_matrixportal.wifi import WiFi
from adafruit_matrixportal.fakerequests import Fake_Requests
import supervisor
import rtc
from adafruit_matrixportal.wifi import WiFi
from adafruit_matrixportal.fakerequests import Fake_Requests

try:
from secrets import secrets
Expand Down Expand Up @@ -166,7 +166,7 @@ def get_local_time(self, location=None):
except KeyError:
raise KeyError(
"\n\nOur time service requires 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
)
) from KeyError

location = secrets.get("timezone", location)
if location:
Expand Down Expand Up @@ -196,7 +196,7 @@ def get_local_time(self, location=None):
except KeyError:
raise KeyError(
"Was unable to lookup the time, try setting secrets['timezone'] according to http://worldtimeapi.org/timezones" # pylint: disable=line-too-long
)
) from KeyError
year, month, mday = [int(x) for x in the_date.split("-")]
the_time = the_time.split(".")[0]
hours, minutes, seconds = [int(x) for x in the_time.split(":")]
Expand Down Expand Up @@ -293,7 +293,7 @@ def push_to_io(self, feed_key, data):
except KeyError:
raise KeyError(
"Adafruit IO secrets are kept in secrets.py, please add them there!\n\n"
)
) from KeyError

io_client = IO_HTTP(aio_username, aio_key, self._wifi.manager(secrets))

Expand Down