Skip to content

hololinked.client.abstractions.ConsumedThingAction

Client side action call abstraction. Subclass from here to implement protocol specific action call.

Source code in repo/hololinked/hololinked/client/abstractions.py
class ConsumedThingAction:  # noqa: D101  # Dont add class doc otherwise it will conflict with __doc__ in slots
    # Client side action call abstraction. Subclasss from here to implement protocol specific action call.

    if TYPE_CHECKING:
        # These are declared as __slots__ in the protocol-specific mixin subclasses.
        # Annotated here only so type checkers resolve them on the base type.
        __name__: str
        __qualname__: str
        __doc__: str | None

    def __init__(
        self,
        resource: ActionAffordance,
        owner_inst: Any,
        logger: structlog.stdlib.BoundLogger,
    ) -> None:
        """
        Initialize a consumed thing action.

        Parameters
        ----------
        resource: ActionAffordance
            dataclass TD fragment representing the action (must have forms).
        owner_inst: ObjectProxy
            instance of the owning consumed Thing or `ObjectProxy`
        logger: structlog.stdlib.BoundLogger
            logger instance
        """
        from . import ObjectProxy  # noqa: F401

        self.resource = resource
        self.owner_inst = owner_inst  # type: ObjectProxy
        self.logger = logger
        self.schema_validator = None  # schema_validator

    def get_last_return_value(self, raise_exception: bool = False) -> Any:
        """Retrieve return value of the last call to the action."""
        raise NotImplementedError("implement get_last_return_value per protocol")

    last_return_value = property(
        fget=get_last_return_value,
        doc="cached return value of the last call to the method",
    )
    """cached return value of the last call to the method."""

    def __call__(self, *args, **kwargs) -> Any:
        """
        Invoke action/method on server.

        Parameters
        ----------
        *args: Any
            arguments to the action
        **kwargs: Any
            keyword arguments to the action

        Returns
        -------
        Any
            reply of the action call
        """
        raise NotImplementedError("implement action __call__ per protocol")

    async def async_call(self, *args, **kwargs) -> Any:
        """
        Async invoke action/method on server.

        Asynchronous at the network level, may not necessarily be at the server level.

        Parameters
        ----------
        *args: Any
            arguments to the action
        **kwargs: Any
            keyword arguments to the action

        Returns
        -------
        Any
            reply of the action call
        """
        raise NotImplementedError("implement action async_call per protocol")

    def oneway(self, *args, **kwargs) -> None:
        """
        Only invokes the action on the server and does not wait for reply.

        Neither does the server (need to) reply to this invokation as any responses are not processed.

        Parameters
        ----------
        *args: Any
            arguments to the action
        **kwargs: Any
            keyword arguments to the action
        """
        raise NotImplementedError("implement action oneway call per protocol")

    def noblock(self, *args, **kwargs) -> str:
        """
        Invoke the action and collect the reply later.

        A message ID must be returned by the server to identify the invokation.

        Parameters
        ----------
        *args: Any
            arguments to the action
        **kwargs: Any
            keyword arguments to the action

        Returns
        -------
        str
            id of the request or message (UUID4 as string)
        """
        raise NotImplementedError("implement action noblock call per protocol")

    def read_reply(self, message_id: str, timeout: float | None = None) -> Any:
        """
        Read the reply of the action call which was scheduled with `noblock`.

        Parameters
        ----------
        message_id: str
            id of the request or message (UUID4 as string)
        timeout: float | int | None
            timeout in seconds to wait for the reply, None means wait indefinitely

        Returns
        -------
        Any
            reply of the action call
        """
        raise NotImplementedError("implement action read_reply per protocol")

    def __hash__(self):  # noqa: D105
        return hash(self.resource.name)

    def __eq__(self, other):  # noqa: D105
        if not isinstance(other, ConsumedThingAction):
            return False
        return self.resource.name == other.resource.name

Attributes

last_return_value class-attribute instance-attribute

last_return_value = property(fget=get_last_return_value, doc='cached return value of the last call to the method')

cached return value of the last call to the method.

Functions

__init__

__init__(resource: ActionAffordance, owner_inst: Any, logger: BoundLogger) -> None

Initialize a consumed thing action.

Parameters:

Name Type Description Default

resource

ActionAffordance

dataclass TD fragment representing the action (must have forms).

required

owner_inst

Any

instance of the owning consumed Thing or ObjectProxy

required

logger

BoundLogger

logger instance

required
Source code in repo/hololinked/hololinked/client/abstractions.py
def __init__(
    self,
    resource: ActionAffordance,
    owner_inst: Any,
    logger: structlog.stdlib.BoundLogger,
) -> None:
    """
    Initialize a consumed thing action.

    Parameters
    ----------
    resource: ActionAffordance
        dataclass TD fragment representing the action (must have forms).
    owner_inst: ObjectProxy
        instance of the owning consumed Thing or `ObjectProxy`
    logger: structlog.stdlib.BoundLogger
        logger instance
    """
    from . import ObjectProxy  # noqa: F401

    self.resource = resource
    self.owner_inst = owner_inst  # type: ObjectProxy
    self.logger = logger
    self.schema_validator = None  # schema_validator

__call__

__call__(*args, **kwargs) -> Any

Invoke action/method on server.

Parameters:

Name Type Description Default

*args

arguments to the action

()

**kwargs

keyword arguments to the action

{}

Returns:

Type Description
Any

reply of the action call

Source code in repo/hololinked/hololinked/client/abstractions.py
def __call__(self, *args, **kwargs) -> Any:
    """
    Invoke action/method on server.

    Parameters
    ----------
    *args: Any
        arguments to the action
    **kwargs: Any
        keyword arguments to the action

    Returns
    -------
    Any
        reply of the action call
    """
    raise NotImplementedError("implement action __call__ per protocol")

async_call async

async_call(*args, **kwargs) -> Any

Async invoke action/method on server.

Asynchronous at the network level, may not necessarily be at the server level.

Parameters:

Name Type Description Default

*args

arguments to the action

()

**kwargs

keyword arguments to the action

{}

Returns:

Type Description
Any

reply of the action call

Source code in repo/hololinked/hololinked/client/abstractions.py
async def async_call(self, *args, **kwargs) -> Any:
    """
    Async invoke action/method on server.

    Asynchronous at the network level, may not necessarily be at the server level.

    Parameters
    ----------
    *args: Any
        arguments to the action
    **kwargs: Any
        keyword arguments to the action

    Returns
    -------
    Any
        reply of the action call
    """
    raise NotImplementedError("implement action async_call per protocol")

oneway

oneway(*args, **kwargs) -> None

Only invokes the action on the server and does not wait for reply.

Neither does the server (need to) reply to this invokation as any responses are not processed.

Parameters:

Name Type Description Default

*args

arguments to the action

()

**kwargs

keyword arguments to the action

{}
Source code in repo/hololinked/hololinked/client/abstractions.py
def oneway(self, *args, **kwargs) -> None:
    """
    Only invokes the action on the server and does not wait for reply.

    Neither does the server (need to) reply to this invokation as any responses are not processed.

    Parameters
    ----------
    *args: Any
        arguments to the action
    **kwargs: Any
        keyword arguments to the action
    """
    raise NotImplementedError("implement action oneway call per protocol")

noblock

noblock(*args, **kwargs) -> str

Invoke the action and collect the reply later.

A message ID must be returned by the server to identify the invokation.

Parameters:

Name Type Description Default

*args

arguments to the action

()

**kwargs

keyword arguments to the action

{}

Returns:

Type Description
str

id of the request or message (UUID4 as string)

Source code in repo/hololinked/hololinked/client/abstractions.py
def noblock(self, *args, **kwargs) -> str:
    """
    Invoke the action and collect the reply later.

    A message ID must be returned by the server to identify the invokation.

    Parameters
    ----------
    *args: Any
        arguments to the action
    **kwargs: Any
        keyword arguments to the action

    Returns
    -------
    str
        id of the request or message (UUID4 as string)
    """
    raise NotImplementedError("implement action noblock call per protocol")

read_reply

read_reply(message_id: str, timeout: float | None = None) -> Any

Read the reply of the action call which was scheduled with noblock.

Parameters:

Name Type Description Default

message_id

str

id of the request or message (UUID4 as string)

required

timeout

float | None

timeout in seconds to wait for the reply, None means wait indefinitely

None

Returns:

Type Description
Any

reply of the action call

Source code in repo/hololinked/hololinked/client/abstractions.py
def read_reply(self, message_id: str, timeout: float | None = None) -> Any:
    """
    Read the reply of the action call which was scheduled with `noblock`.

    Parameters
    ----------
    message_id: str
        id of the request or message (UUID4 as string)
    timeout: float | int | None
        timeout in seconds to wait for the reply, None means wait indefinitely

    Returns
    -------
    Any
        reply of the action call
    """
    raise NotImplementedError("implement action read_reply per protocol")

get_last_return_value

get_last_return_value(raise_exception: bool = False) -> Any

Retrieve return value of the last call to the action.

Source code in repo/hololinked/hololinked/client/abstractions.py
def get_last_return_value(self, raise_exception: bool = False) -> Any:
    """Retrieve return value of the last call to the action."""
    raise NotImplementedError("implement get_last_return_value per protocol")