88
99from ..actions .pool import Pool
1010from ..deque import Deque
11- from ..find import current_labthing
11+ from ..find import current_labthing , find_extension
1212from ..marshalling import marshal_with , use_args
1313from ..representations import DEFAULT_REPRESENTATIONS
1414from ..schema import ActionSchema , EventSchema , Schema , build_action_schema
@@ -40,6 +40,11 @@ class View(MethodView):
4040 _cls_tags : Set [str ] = set () # Class tags that shouldn't be removed
4141 _opmap : Dict [str , str ] = {} # Mapping of Thing Description ops to class methods
4242
43+ # Name of parent extension, if one exists.
44+ # This is only used for extension development where Views are added to the extension.
45+ # We store the name instead of the object itself to prevent circular references.
46+ _parent_extension_name : Optional [str ] = None
47+
4348 def __init__ (self , * args , ** kwargs ):
4449 MethodView .__init__ (self , * args , ** kwargs )
4550
@@ -50,6 +55,12 @@ def __init__(self, *args, **kwargs):
5055 else DEFAULT_REPRESENTATIONS
5156 )
5257
58+ @property
59+ def extension (self ):
60+ if self ._parent_extension_name :
61+ return find_extension (self ._parent_extension_name )
62+ return None
63+
5364 @classmethod
5465 def get_tags (cls ):
5566 """ """
@@ -257,7 +268,7 @@ class EventView(View):
257268
258269 # Internal
259270 _opmap = {
260- "subscribeevent" : "get" ,
271+ "subscribeevent" : "get"
261272 } # Mapping of Thing Description ops to class methods
262273 _cls_tags = {"events" }
263274 _deque = Deque () # Action queue
0 commit comments