Skip to content

hololinked.td.interaction_affordance.PropertyAffordance

Bases: InteractionAffordance, DataSchema

Implements property affordance schema from Property descriptor object.

Schema
UML Diagram
Supported Fields

Source code in hololinked\td\interaction_affordance.py
class PropertyAffordance(InteractionAffordance, DataSchema):
    """
    Implements property affordance schema from `Property` descriptor object.

    [Schema](https://www.w3.org/TR/wot-thing-description11/#propertyaffordance) <br>
    [UML Diagram](https://docs.hololinked.dev/UML/PDF/InteractionAffordance.pdf) <br>
    [Supported Fields]() <br>
    """
    observable: Optional[bool] = None

    def __init__(self):
        super().__init__()

    @property
    def what(self) -> Enum:
        return ResourceTypes.PROPERTY

    def build(self) -> None:
        property = self.objekt
        self.ds_build_from_property(property)
        if property._observable:
            self.observable = property._observable

    def build_forms(self, authority: str) -> None:
        property = self.objekt
        self.forms = []
        for index, method in enumerate(property._remote_info.http_method):
            form = Form()
            # index is the order for http methods for (get, set, delete), generally (GET, PUT, DELETE)
            if (index == 1 and property.readonly) or index >= 2:
                continue # delete property is not a part of WoT, we also mostly never use it, so ignore.
            elif index == 0:
                form.op = 'readproperty'
            elif index == 1:
                form.op = 'writeproperty'
            form.href = f"{authority}{self.owner._qualified_id}{property._remote_info.URL_path}"
            form.htv_methodName = method.upper()
            form.contentType = "application/json"
            self.forms.append(form.asdict())

        if property._observable:
            self.observable = property._observable
            form = Form()
            form.op = 'observeproperty'
            form.href = f"{authority}{owner._full_URL_path_prefix}{property._observable_event_descriptor.URL_path}"
            form.htv_methodName = "GET"
            form.subprotocol = "sse"
            form.contentType = "text/plain"
            self.forms.append(form.asdict())

    @classmethod
    def generate(cls, property, owner):
        assert isinstance(property, Property), f"property must be instance of Property, given type {type(property)}"
        schema = PropertyAffordance()
        schema.owner = owner      
        schema.objekt = property
        schema.build()       
        return schema

TD Supported Fields

Apart from the fields supported InteractionAffordance and DataSchema, the following is supported

field supported meaning default usage
observable ✔️ true if Property pushes change events Property.observable value