Bases: InteractionAffordance
creates event affordance schema from events.
Schema
UML Diagram
Source code in hololinked/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) -> None:
event = self.objekt # type: Event
if event.__doc__:
title = get_summary(event.doc)
description = self.format_doc(event.doc)
if title and not description.startswith(title):
self.title = title
self.description = description
else:
self.description = description
if event.schema:
if isinstance(event.schema, dict):
self.data = event.schema
elif issubklass(event.schema, (BaseModel, RootModel)):
self.data = type_to_dataschema(event.schema)
else:
raise ValueError(f"unknown schema definition for event data, given type: {type(event.schema)}")
@classmethod
def generate(cls, event: Event, owner, **kwargs) -> "EventAffordance":
if not isinstance(event, Event):
raise TypeError(f"event must be instance of Event, given type {type(event)}")
affordance = EventAffordance()
affordance.owner = owner
affordance.objekt = event
affordance.build()
affordance.build_non_compliant_metadata()
return affordance
|