labthings_fastapi.descriptors.property
Define an object to represent an Action, as a descriptor.
Module Contents
Classes
A property that can be accessed via the HTTP API |
API
- class labthings_fastapi.descriptors.property.PropertyDescriptor(model: type, initial_value: Any = None, readonly: bool = False, observable: bool = False, description: Optional[str] = None, title: Optional[str] = None, getter: Optional[Callable] = None, setter: Optional[Callable] = None)
A property that can be accessed via the HTTP API
By default, a PropertyDescriptor is “dumb”, i.e. it acts just like a normal variable.
Initialization
- property title
A human-readable title
- property description
A description of the property
- __get__(obj, type=None) Any
The value of the property
If
objis none (i.e. we are getting the attribute of the class), we return the descriptor.If no getter is set, we’ll return either the initial value, or the value from the object’s dict, i.e. we behave like a variable.
If a getter is set, we will use it, unless the property is observable, at which point the getter is only ever used once, to set the initial value.
- __set__(obj, value)
Set the property’s value
- _observers_set(obj)
A set used to notify changes
- emit_changed_event(obj: labthings_fastapi.thing.Thing, value: Any) None
Notify subscribers that the property has changed
NB this function must be run from a thread, not the event loop.
- async emit_changed_event_async(obj: labthings_fastapi.thing.Thing, value: Any)
Notify subscribers that the property has changed
- property name
The name of the property
- add_to_fastapi(app: fastapi.FastAPI, thing: labthings_fastapi.thing.Thing)
Add this action to a FastAPI app, bound to a particular Thing.
- property_affordance(thing: labthings_fastapi.thing.Thing, path: Optional[str] = None) labthings_fastapi.thing_description.model.PropertyAffordance
Represent the property in a Thing Description.