1313from pydantic import BaseModel , Field
1414
1515from .con_sys_api import ConnectedSystemAPIRequest
16- from .constants import APIResourceTypes , EncodingSchema , APITerms
16+ from .constants import APIResourceTypes , ContentTypes , APITerms
1717
1818
1919# TODO: rework to make the first resource in the endpoint the primary key for URL construction, currently, the implementation is a bit on the confusing side with what is being generated and why.
@@ -77,6 +77,10 @@ def resource_type_to_endpoint(res_type: APIResourceTypes, parent_type: APIResour
7777 return APITerms .HISTORY .value
7878 case APIResourceTypes .DEPLOYMENT :
7979 return APITerms .DEPLOYMENTS .value
80+ case APIResourceTypes .STATUS :
81+ return APITerms .STATUS .value
82+ case APIResourceTypes .SCHEMA :
83+ return APITerms .SCHEMA .value
8084 case _:
8185 raise ValueError ('Invalid resource type' )
8286
@@ -279,16 +283,24 @@ def set_protocol(self, protocol: str):
279283 raise ValueError ('Protocol must be either "http" or "https"' )
280284 self .protocol = protocol
281285
282- def get_mqtt_topic ( self , resource_type , subresource_type , resource_id : str ,
283- for_socket : bool = False ):
286+ # TODO: add validity checking for resource type combinations
287+ def get_mqtt_topic ( self , resource_type , subresource_type , resource_id : str , subresource_id : str = None ):
284288 """
285- Returns the MQTT topic for the resource type, if applicable.
289+ Returns the MQTT topic for the resource type, does not check for validity of the resource type combination
290+ :param resource_type : The API resource type of the resource that comes first in the URL, cannot be None
291+ :param subresource_type: The API resource type of the sub-resource that comes second in the URL, optional if there
292+ is no sub-resource.
293+ :param resource_id: The ID of the primary resource, can be none if the request is being made for all resources of
294+ the given type.
295+ :param subresource_id: The ID of the sub-resource, can be none if the request is being made for all sub-resources of
296+ the given type.
286297 :return:
287298 """
288- resource_endpoint = f'/{ resource_type_to_endpoint (subresource_type , resource_type )} '
289- parent_endpoint = "" if resource_type is None else f'/{ resource_type_to_endpoint (resource_type )} '
290- parent_id = "" if resource_id is None else f'/{ resource_id } '
291- topic_locator = f'/{ self .api_root } { parent_endpoint } { parent_id } { resource_endpoint } '
299+ subresource_endpoint = f'/{ resource_type_to_endpoint (subresource_type )} '
300+ resource_endpoint = "" if resource_type is None else f'/{ resource_type_to_endpoint (resource_type )} '
301+ resource_ident = "" if resource_id is None else f'/{ resource_id } '
302+ subresource_ident = "" if subresource_id is None else f'/{ subresource_id } '
303+ topic_locator = f'/{ self .api_root } { resource_endpoint } { resource_ident } { subresource_endpoint } { subresource_ident } '
292304 print (f'MQTT Topic: { topic_locator } ' )
293305
294306 return topic_locator
@@ -305,17 +317,17 @@ class DefaultObjectRepresentations(BaseModel):
305317 Should work in tandem with planned Serializer/Deserializer classes.
306318 """
307319 # Part 1
308- collections : str = Field (EncodingSchema .JSON .value )
309- deployments : str = Field (EncodingSchema .GEO_JSON .value )
310- procedures : str = Field (EncodingSchema .GEO_JSON .value )
311- properties : str = Field (EncodingSchema .SML_JSON .value )
312- sampling_features : str = Field (EncodingSchema .GEO_JSON .value )
313- systems : str = Field (EncodingSchema .GEO_JSON .value )
320+ collections : str = Field (ContentTypes .JSON .value )
321+ deployments : str = Field (ContentTypes .GEO_JSON .value )
322+ procedures : str = Field (ContentTypes .GEO_JSON .value )
323+ properties : str = Field (ContentTypes .SML_JSON .value )
324+ sampling_features : str = Field (ContentTypes .GEO_JSON .value )
325+ systems : str = Field (ContentTypes .GEO_JSON .value )
314326 # Part 2
315- datastreams : str = Field (EncodingSchema .JSON .value )
316- observations : str = Field (EncodingSchema .JSON .value )
317- control_channels : str = Field (EncodingSchema .JSON .value )
318- commands : str = Field (EncodingSchema .JSON .value )
319- system_events : str = Field (EncodingSchema .OM_JSON .value )
320- system_history : str = Field (EncodingSchema .GEO_JSON .value )
327+ datastreams : str = Field (ContentTypes .JSON .value )
328+ observations : str = Field (ContentTypes .JSON .value )
329+ control_channels : str = Field (ContentTypes .JSON .value )
330+ commands : str = Field (ContentTypes .JSON .value )
331+ system_events : str = Field (ContentTypes .OM_JSON .value )
332+ system_history : str = Field (ContentTypes .GEO_JSON .value )
321333 # TODO: validate schemas for each resource to amke sure they are allowed per the spec
0 commit comments