@@ -344,3 +344,49 @@ class BadIntModel(pydantic.BaseModel):
344344 assert example .badprop == 3
345345 with pytest .raises (TypeError ):
346346 _ = example .properties ["badprop" ].model_instance
347+
348+
349+ def test_readonly_metadata ():
350+ """Check read-only data propagates to the Thing Description."""
351+
352+ class Example (lt .Thing ):
353+ prop : int = lt .property (default = 0 )
354+ ro_property : int = lt .property (default = 0 , readonly = True )
355+
356+ @lt .property
357+ def ro_functional_property (self ) -> int :
358+ """This property should be read-only as there's no setter."""
359+ return 42
360+
361+ @lt .property
362+ def ro_functional_property_with_setter (self ) -> int :
363+ return 42
364+
365+ @ro_functional_property_with_setter .setter
366+ def _set_ro_functional_property_with_setter (self , val : int ) -> None :
367+ pass
368+
369+ ro_functional_property_with_setter .readonly = True
370+
371+ @lt .property
372+ def funcprop (self ) -> int :
373+ return 42
374+
375+ @funcprop .setter
376+ def _set_funcprop (self , val : int ) -> None :
377+ pass
378+
379+ example = create_thing_without_server (Example )
380+
381+ td = example .thing_description ()
382+
383+ # Check read-write properties are not read-only
384+ for name in ["prop" , "funcprop" ]:
385+ assert td .properties [name ].readOnly is False
386+
387+ for name in [
388+ "ro_property" ,
389+ "ro_functional_property" ,
390+ "ro_functional_property_with_setter" ,
391+ ]:
392+ assert td .properties [name ].readOnly is True
0 commit comments