Skip to content

Commit bcfaae8

Browse files
authored
Merge pull request #70 from FoamyGuy/dont_require_secrets_if_no_network
Dont require secrets if no network
2 parents e80d71c + 4656a44 commit bcfaae8

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

adafruit_portalbase/__init__.py

100755100644
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,32 @@ def __init__(
8585
except ImportError:
8686
self._alarm = None
8787
self._debug = debug
88+
if url and self.network is None:
89+
raise RuntimeError("network must not be None to get data from a url")
8890
self.url = url
91+
if headers and self.network is None:
92+
raise RuntimeError("network must not be None to send headers")
8993
self._headers = headers
94+
if json_path and self.network is None:
95+
raise RuntimeError("network must not be None to use json_path")
9096
self._json_path = None
9197
self.json_path = json_path
9298

99+
if regexp_path and self.network is None:
100+
raise RuntimeError("network must not be None to use regexp_path")
93101
self._regexp_path = regexp_path
102+
103+
if success_callback and self.network is None:
104+
raise RuntimeError("network must not be None to use success_callback")
94105
self._success_callback = success_callback
95106

96107
# Add any JSON translators
108+
97109
if json_transform:
98-
self.network.add_json_transform(json_transform)
110+
if self.network is not None:
111+
self.network.add_json_transform(json_transform)
112+
else:
113+
raise RuntimeError("network must not be None to use json_transform.")
99114

100115
def _load_font(self, font):
101116
"""
@@ -416,6 +431,9 @@ def fetch(self, refresh_url=None, timeout=10):
416431
:param int timeout: The timeout period in seconds.
417432
418433
"""
434+
435+
if self.network is None:
436+
raise RuntimeError("network must not be None to use fetch()")
419437
if refresh_url:
420438
self.url = refresh_url
421439
values = []
@@ -459,6 +477,9 @@ def _fill_text_labels(self, values):
459477

460478
def get_local_time(self, location=None):
461479
"""Accessor function for get_local_time()"""
480+
if self.network is None:
481+
raise RuntimeError("network must not be None to use get_local_time()")
482+
462483
return self.network.get_local_time(location=location)
463484

464485
def push_to_io(self, feed_key, data, metadata=None, precision=None):
@@ -470,6 +491,8 @@ def push_to_io(self, feed_key, data, metadata=None, precision=None):
470491
:param int precision: Optional amount of precision points to send with floating point data
471492
472493
"""
494+
if self.network is None:
495+
raise RuntimeError("network must not be None to use push_to_io()")
473496

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

@@ -479,6 +502,8 @@ def get_io_data(self, feed_key):
479502
:param str feed_key: Name of feed key to receive data from.
480503
481504
"""
505+
if self.network is None:
506+
raise RuntimeError("network must not be None to use get_io_data()")
482507

483508
return self.network.get_io_data(feed_key)
484509

@@ -489,6 +514,9 @@ def get_io_feed(self, feed_key, detailed=False):
489514
:param bool detailed: Whether to return additional detailed information
490515
491516
"""
517+
if self.network is None:
518+
raise RuntimeError("network must not be None to use get_io_feed()")
519+
492520
return self.network.get_io_feed(feed_key, detailed)
493521

494522
def get_io_group(self, group_key):
@@ -497,6 +525,8 @@ def get_io_group(self, group_key):
497525
:param str group_key: Name of group key to match.
498526
499527
"""
528+
if self.network is None:
529+
raise RuntimeError("network must not be None to use get_io_group()")
500530
return self.network.get_io_group(group_key)
501531

502532
@property
@@ -509,6 +539,9 @@ def json_path(self):
509539

510540
@json_path.setter
511541
def json_path(self, value):
542+
if value is not None and self.network is None:
543+
raise RuntimeError("network must not be None to use json_path.")
544+
512545
if value:
513546
if isinstance(value[0], (list, tuple)):
514547
self._json_path = value

adafruit_portalbase/network.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
except ImportError:
3939
print(
4040
"""WiFi settings are kept in secrets.py, please add them there!
41-
the secrets dictionary must contain 'ssid' and 'password' at a minimum"""
41+
the secrets dictionary must contain 'ssid' and 'password' at a minimum
42+
in order to use network related features"""
4243
)
4344

4445
__version__ = "0.0.0-auto.0"

0 commit comments

Comments
 (0)