@@ -51,29 +51,32 @@ def __init__(
5151 types : list = None ,
5252 version : str = "0.0.0" ,
5353 format_flask_exceptions : bool = True ,
54+ json_encoder = LabThingsJSONEncoder ,
5455 ):
5556 if types is None :
5657 types = []
5758 self .app = app # Becomes a Flask app
5859 self .sockets = None # Becomes a Socket(app) websocket handler
5960
60- self .components = {}
61+ self .components = (
62+ {}
63+ ) # Dictionary of attached component objects, available to extensions
6164
62- self .extensions = {}
65+ self .extensions = {} # Dictionary of LabThings extension objects
6366
6467 self .actions = Pool () # Pool of threads for Actions
6568
66- self .events = {}
69+ self .events = {} # Dictionary of Event affordances
6770
68- self .views = []
69- self ._property_views = {}
70- self ._action_views = {}
71+ self .views = [] # List of View classes
72+ self ._property_views = {} # Dictionary of PropertyView views
73+ self ._action_views = {} # Dictionary of ActionView views
7174
72- self .subscribers = set ()
75+ self .subscribers = set () # Set of connected event subscribers
7376
74- self .endpoints = set ()
77+ self .endpoints = set () # Set of endpoint strings
7578
76- self .url_prefix = prefix
79+ self .url_prefix = prefix # Global URL prefix for all LabThings views
7780
7881 for t in types :
7982 if ";" in t :
@@ -97,7 +100,7 @@ def __init__(
97100 # Representation formatter map
98101 self .representations = DEFAULT_REPRESENTATIONS
99102
100- # API Spec
103+ # OpenAPI spec for Swagger docs
101104 self .spec = APISpec (
102105 title = self .title ,
103106 version = self .version ,
@@ -108,6 +111,9 @@ def __init__(
108111 # Thing description
109112 self .thing_description = ThingDescription ()
110113
114+ # JSON encoder class
115+ self .json_encoder = json_encoder
116+
111117 if app is not None :
112118 self .init_app (app )
113119
@@ -162,7 +168,7 @@ def init_app(self, app):
162168 error_handler .init_app (app )
163169
164170 # Custom JSON encoder
165- app .json_encoder = LabThingsJSONEncoder
171+ app .json_encoder = self . json_encoder
166172
167173 # Add resources, if registered before tying to a Flask app
168174 if len (self .views ) > 0 :
0 commit comments