File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -473,7 +473,7 @@ def get_property() -> Any:
473473 return self .__get__ (thing )
474474
475475 def property_affordance (
476- self , thing : Thing , path : str | None = None
476+ self , thing : Owner , path : str | None = None
477477 ) -> PropertyAffordance :
478478 """Represent the property in a Thing Description.
479479
@@ -500,12 +500,22 @@ def property_affordance(
500500 ),
501501 ]
502502 data_schema : DataSchema = type_to_dataschema (self .model )
503+ extra_fields = {}
504+ try :
505+ # Try to get hold of the default - may raise FeatureNotAvailable
506+ default = self .default (thing )
507+ # Validate and dump it with the model to ensure it's simple types only
508+ default_validated = self .model .model_validate (default )
509+ extra_fields ["default" ] = default_validated .model_dump ()
510+ except FeatureNotAvailable :
511+ pass # Default should only be included if it's needed.
503512 pa : PropertyAffordance = PropertyAffordance (
504513 title = self .title ,
505514 forms = forms ,
506515 description = self .description ,
507516 readOnly = self .readonly ,
508517 writeOnly = False , # write-only properties are not yet supported
518+ ** extra_fields ,
509519 )
510520 # We merge the data schema with the property affordance (which subclasses the
511521 # DataSchema model) with the affordance second so its values take priority.
Original file line number Diff line number Diff line change @@ -504,3 +504,9 @@ def strprop(self) -> str:
504504 # Resetting won't work for FunctionalProperty
505505 with pytest .raises (FeatureNotAvailable ):
506506 example .properties ["strprop" ].reset ()
507+
508+ # Check defaults show up in the Thing Description
509+ td = example .thing_description_dict ()
510+ assert td ["properties" ]["intprop" ]["default" ] == 42
511+ assert td ["properties" ]["listprop" ]["default" ] == ["a" , "list" ]
512+ assert "default" not in td ["properties" ]["strprop" ]
You can’t perform that action at this time.
0 commit comments