Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Dont require secrets if no network #70

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 3 commits into from
Apr 25, 2022
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
35 changes: 34 additions & 1 deletion adafruit_portalbase/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,32 @@ def __init__(
except ImportError:
self._alarm = None
self._debug = debug
if url and self.network is None:
raise RuntimeError("network must not be None to get data from a url")
self.url = url
if headers and self.network is None:
raise RuntimeError("network must not be None to send headers")
self._headers = headers
if json_path and self.network is None:
raise RuntimeError("network must not be None to use json_path")
self._json_path = None
self.json_path = json_path

if regexp_path and self.network is None:
raise RuntimeError("network must not be None to use regexp_path")
self._regexp_path = regexp_path

if success_callback and self.network is None:
raise RuntimeError("network must not be None to use success_callback")
self._success_callback = success_callback

# Add any JSON translators

if json_transform:
self.network.add_json_transform(json_transform)
if self.network is not None:
self.network.add_json_transform(json_transform)
else:
raise RuntimeError("network must not be None to use json_transform.")

def _load_font(self, font):
"""
Expand Down Expand Up @@ -416,6 +431,9 @@ def fetch(self, refresh_url=None, timeout=10):
:param int timeout: The timeout period in seconds.

"""

if self.network is None:
raise RuntimeError("network must not be None to use fetch()")
if refresh_url:
self.url = refresh_url
values = []
Expand Down Expand Up @@ -459,6 +477,9 @@ def _fill_text_labels(self, values):

def get_local_time(self, location=None):
"""Accessor function for get_local_time()"""
if self.network is None:
raise RuntimeError("network must not be None to use get_local_time()")

return self.network.get_local_time(location=location)

def push_to_io(self, feed_key, data, metadata=None, precision=None):
Expand All @@ -470,6 +491,8 @@ def push_to_io(self, feed_key, data, metadata=None, precision=None):
:param int precision: Optional amount of precision points to send with floating point data

"""
if self.network is None:
raise RuntimeError("network must not be None to use push_to_io()")

self.network.push_to_io(feed_key, data, metadata=metadata, precision=precision)

Expand All @@ -479,6 +502,8 @@ def get_io_data(self, feed_key):
:param str feed_key: Name of feed key to receive data from.

"""
if self.network is None:
raise RuntimeError("network must not be None to use get_io_data()")

return self.network.get_io_data(feed_key)

Expand All @@ -489,6 +514,9 @@ def get_io_feed(self, feed_key, detailed=False):
:param bool detailed: Whether to return additional detailed information

"""
if self.network is None:
raise RuntimeError("network must not be None to use get_io_feed()")

return self.network.get_io_feed(feed_key, detailed)

def get_io_group(self, group_key):
Expand All @@ -497,6 +525,8 @@ def get_io_group(self, group_key):
:param str group_key: Name of group key to match.

"""
if self.network is None:
raise RuntimeError("network must not be None to use get_io_group()")
return self.network.get_io_group(group_key)

@property
Expand All @@ -509,6 +539,9 @@ def json_path(self):

@json_path.setter
def json_path(self, value):
if value is not None and self.network is None:
raise RuntimeError("network must not be None to use json_path.")

if value:
if isinstance(value[0], (list, tuple)):
self._json_path = value
Expand Down
3 changes: 2 additions & 1 deletion adafruit_portalbase/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
except ImportError:
print(
"""WiFi settings are kept in secrets.py, please add them there!
the secrets dictionary must contain 'ssid' and 'password' at a minimum"""
the secrets dictionary must contain 'ssid' and 'password' at a minimum
in order to use network related features"""
)

__version__ = "0.0.0-auto.0"
Expand Down