3636
3737_LOGGER = logging .getLogger (__name__ )
3838
39+
3940class Thing :
4041 """Represents a Thing, as defined by the Web of Things standard.
4142
@@ -90,7 +91,9 @@ async def __aexit__(self, exc_t, exc_v, exc_tb):
9091 if hasattr (self , "__exit__" ):
9192 return await run_sync (self .__exit__ , exc_t , exc_v , exc_tb )
9293
93- def attach_to_server (self , server : ThingServer , path : str , setting_storage_path : str ):
94+ def attach_to_server (
95+ self , server : ThingServer , path : str , setting_storage_path : str
96+ ):
9497 """Add HTTP handlers to an app for all Interaction Affordances"""
9598 self .path = path
9699 self .action_manager : ActionManager = server .action_manager
@@ -119,15 +122,16 @@ def thing_description(request: Request) -> ThingDescription:
119122 async def websocket (ws : WebSocket ):
120123 await websocket_endpoint (self , ws )
121124
122-
123125 _settings : Optional [list [str ]] = None
124126
125127 @property
126128 def settings (self ):
127129 if self ._settings is None :
128130 self ._settings = []
129131 for name , attribute in class_attributes (self ):
130- if hasattr (attribute , "property_affordance" ) and hasattr (attribute , "persistent" ):
132+ if hasattr (attribute , "property_affordance" ) and hasattr (
133+ attribute , "persistent"
134+ ):
131135 self ._settings .append (name )
132136 return self ._settings
133137
@@ -149,27 +153,31 @@ def load_settings(self, setting_storage_path):
149153 setting_dict = json .load (file_obj )
150154 setting_attributes = {}
151155 for name , attribute in class_attributes (self ):
152- if hasattr (attribute , "property_affordance" ) and hasattr (attribute , "persistent" ):
156+ if hasattr (attribute , "property_affordance" ) and hasattr (
157+ attribute , "persistent"
158+ ):
153159 setting_attributes [name ] = attribute
154160 for key , value in setting_dict .items ():
155161 if key in setting_attributes :
156- setting_attributes [key ].set_without_emit (self , value )
162+ setting_attributes [key ].set_without_emit (self , value )
157163 else :
158164 _LOGGER .warning (
159165 "Cannot set %s from persistent storage as %s has no matching setting." ,
160- key , thing_name
166+ key ,
167+ thing_name ,
161168 )
162169 except (FileNotFoundError , JSONDecodeError , PermissionError ):
163170 _LOGGER .warning ("Error loading settings for %s" , thing_name )
164171 self ._setting_storage_path = setting_storage_path
165172
166-
167173 def save_settings (self ):
168174 """Save settings to JSON. This is called when a setting is updated with a setter"""
169175 if self .settings is not None :
170176 setting_dict = {}
171177 for name , attribute in class_attributes (self ):
172- if hasattr (attribute , "property_affordance" ) and hasattr (attribute , "persistent" ):
178+ if hasattr (attribute , "property_affordance" ) and hasattr (
179+ attribute , "persistent"
180+ ):
173181 setting_dict [name ] = attribute .get_raw (self )
174182 # Dumpy to string before writing so if this fails the file isn't overwritten
175183 setting_json = json .dumps (setting_dict , indent = 4 )
0 commit comments