Skip to content

hololinked.td.interaction_affordance.EventAffordance

Bases: InteractionAffordance

creates event affordance schema from events.

Schema
UML Diagram
Supported Fields

Source code in hololinked\td\interaction_affordance.py
class EventAffordance(InteractionAffordance):
    """
    creates event affordance schema from events.

    [Schema](https://www.w3.org/TR/wot-thing-description11/#eventaffordance) <br>
    [UML Diagram](https://docs.hololinked.dev/UML/PDF/InteractionAffordance.pdf) <br>
    [Supported Fields]() <br>
    """
    subscription: str = None
    data: JSON = None

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

    @property 
    def what(self):
        return ResourceTypes.EVENT

    def build(self, event, owner, authority : str) -> None:
        self.title = event.label or event._obj_name 
        if event.doc:
            self.description = self.format_doc(event.doc)
        if event.schema:
            self.data = event.schema

        form = Form()
        form.op = "subscribeevent"
        form.href = f"{authority}{owner._full_URL_path_prefix}{event.URL_path}"
        form.htv_methodName = "GET"
        form.contentType = "text/plain"
        form.subprotocol = "sse"
        self.forms = [form.asdict()]

    @classmethod
    def generate_schema(cls, event, owner, authority : str) -> JSON:
        schema = EventAffordance()
        schema.build(event=event, owner=owner, authority=authority)
        return schema.asdict()
field supported meaning default usage
subscription ✔️ schema of the input required to invoke action input_schema value of action decorator
data ✔️ schema of the output returned by the action output_schema value of action decorator