@@ -85,17 +85,32 @@ def __init__(
85
85
except ImportError :
86
86
self ._alarm = None
87
87
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" )
88
90
self .url = url
91
+ if headers and self .network is None :
92
+ raise RuntimeError ("network must not be None to send headers" )
89
93
self ._headers = headers
94
+ if json_path and self .network is None :
95
+ raise RuntimeError ("network must not be None to use json_path" )
90
96
self ._json_path = None
91
97
self .json_path = json_path
92
98
99
+ if regexp_path and self .network is None :
100
+ raise RuntimeError ("network must not be None to use regexp_path" )
93
101
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" )
94
105
self ._success_callback = success_callback
95
106
96
107
# Add any JSON translators
108
+
97
109
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." )
99
114
100
115
def _load_font (self , font ):
101
116
"""
@@ -416,6 +431,9 @@ def fetch(self, refresh_url=None, timeout=10):
416
431
:param int timeout: The timeout period in seconds.
417
432
418
433
"""
434
+
435
+ if self .network is None :
436
+ raise RuntimeError ("network must not be None to use fetch()" )
419
437
if refresh_url :
420
438
self .url = refresh_url
421
439
values = []
@@ -459,7 +477,10 @@ def _fill_text_labels(self, values):
459
477
460
478
def get_local_time (self , location = None ):
461
479
"""Accessor function for get_local_time()"""
462
- return self .network .get_local_time (location = location )
480
+ if self .network is not None :
481
+ return self .network .get_local_time (location = location )
482
+
483
+ raise RuntimeError ("network must not be None to use get_local_time()" )
463
484
464
485
def push_to_io (self , feed_key , data , metadata = None , precision = None ):
465
486
"""Push data to an adafruit.io feed
@@ -470,17 +491,23 @@ def push_to_io(self, feed_key, data, metadata=None, precision=None):
470
491
:param int precision: Optional amount of precision points to send with floating point data
471
492
472
493
"""
473
-
474
- self .network .push_to_io (feed_key , data , metadata = metadata , precision = precision )
494
+ if self .network is not None :
495
+ self .network .push_to_io (
496
+ feed_key , data , metadata = metadata , precision = precision
497
+ )
498
+ else :
499
+ raise RuntimeError ("network must not be None to use push_to_io()" )
475
500
476
501
def get_io_data (self , feed_key ):
477
502
"""Return all values from the Adafruit IO Feed Data that matches the feed key
478
503
479
504
:param str feed_key: Name of feed key to receive data from.
480
505
481
506
"""
507
+ if self .network is not None :
508
+ return self .network .get_io_data (feed_key )
482
509
483
- return self . network . get_io_data (feed_key )
510
+ raise RuntimeError ( " network must not be None to use get_io_data()" )
484
511
485
512
def get_io_feed (self , feed_key , detailed = False ):
486
513
"""Return the Adafruit IO Feed that matches the feed key
@@ -489,15 +516,21 @@ def get_io_feed(self, feed_key, detailed=False):
489
516
:param bool detailed: Whether to return additional detailed information
490
517
491
518
"""
492
- return self .network .get_io_feed (feed_key , detailed )
519
+ if self .network is not None :
520
+ return self .network .get_io_feed (feed_key , detailed )
521
+
522
+ raise RuntimeError ("network must not be None to use get_io_feed()" )
493
523
494
524
def get_io_group (self , group_key ):
495
525
"""Return the Adafruit IO Group that matches the group key
496
526
497
527
:param str group_key: Name of group key to match.
498
528
499
529
"""
500
- return self .network .get_io_group (group_key )
530
+ if self .network is not None :
531
+ return self .network .get_io_group (group_key )
532
+
533
+ raise RuntimeError ("network must not be None to use get_io_group()" )
501
534
502
535
@property
503
536
def json_path (self ):
@@ -509,6 +542,9 @@ def json_path(self):
509
542
510
543
@json_path .setter
511
544
def json_path (self , value ):
545
+ if value is not None and self .network is None :
546
+ raise RuntimeError ("network must not be None to use json_path." )
547
+
512
548
if value :
513
549
if isinstance (value [0 ], (list , tuple )):
514
550
self ._json_path = value
0 commit comments