Skip to content

hololinked.client.abstractions.ConsumedThingAction

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

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

    def __init__(
        self,
        resource: ActionAffordance,
        owner_inst: Any,
        logger: structlog.stdlib.BoundLogger,
    ) -> None:
        """
        Parameters
        ----------
        resource: ActionAffordance
            dataclass TD fragment representing the action (must have forms).
        owner_inst: Any
            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 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 reply to this invokation.

        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 | int | 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):
        return hash(self.resource.name)

    def __eq__(self, other):
        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

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 hololinked/hololinked/client/abstractions.py
def __init__(
    self,
    resource: ActionAffordance,
    owner_inst: Any,
    logger: structlog.stdlib.BoundLogger,
) -> None:
    """
    Parameters
    ----------
    resource: ActionAffordance
        dataclass TD fragment representing the action (must have forms).
    owner_inst: Any
        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 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 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 hololinked/hololinked/client/abstractions.py
async def async_call(self, *args, **kwargs) -> Any:
    """
    async invoke action 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 reply to this invokation.

Parameters:

Name Type Description Default

*args

arguments to the action

()

**kwargs

keyword arguments to the action

{}
Source code in 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 reply to this invokation.

    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 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 | int | 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 | int | 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 hololinked/hololinked/client/abstractions.py
def read_reply(self, message_id: str, timeout: float | int | 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 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")