Bases: InteractionAffordance
creates action affordance schema from actions (or methods).
Schema
UML Diagram
Source code in .venv/lib/python3.13/site-packages/hololinked/td/interaction_affordance.py
| class ActionAffordance(InteractionAffordance):
"""
creates action affordance schema from actions (or methods).
[Schema](https://www.w3.org/TR/wot-thing-description11/#actionaffordance) <br>
[UML Diagram](https://docs.hololinked.dev/UML/PDF/InteractionAffordance.pdf) <br>
"""
# [Supported Fields]() <br>
input: JSON = None
output: JSON = None
safe: bool = None
idempotent: bool = None
synchronous: bool = None
def __init__(self):
super().__init__()
@property
def what(self):
return ResourceTypes.ACTION
def build(self) -> None:
action = self.objekt
assert isinstance(action, Action) # type definition
if action.obj.__doc__:
title = get_summary(action.obj.__doc__)
description = self.format_doc(action.obj.__doc__)
if title == description:
self.description = description
else:
self.title = title
self.description = description
if action.execution_info.argument_schema:
self.input = action.execution_info.argument_schema
if action.execution_info.return_value_schema:
self.output = action.execution_info.return_value_schema
if (
not (hasattr(self.owner, 'state_machine') and self.owner.state_machine is not None and
self.owner.state_machine.contains_object(action)) and
action.execution_info.idempotent
):
self.idempotent = action.execution_info.idempotent
if action.execution_info.synchronous:
self.synchronous = action.execution_info.synchronous
if action.execution_info.safe:
self.safe = action.execution_info.safe
# def build_forms(self, protocol: str, authority : str, **protocol_metadata) -> None:
# self.forms = []
# for method in action.execution_info_validator.http_method:
# form = Form()
# form.op = 'invokeaction'
# form.href = f'{authority}/{self.owner.id}/{protocol_metadata.get("path", "")}/{action.name}'
# form.htv_methodName = method.upper()
# form.contentType = 'application/json'
# # form.additionalResponses = [AdditionalExpectedResponse().asdict()]
# self.forms.append(form.asdict())
@classmethod
def generate(cls, action: Action, owner, **kwargs) -> "ActionAffordance":
affordance = ActionAffordance()
affordance.owner = owner
affordance.objekt = action
affordance.build()
return affordance
|