Skip to content

hololinked.client.abstractions.ConsumedThingProperty

Client side property abstraction. Subclass from here to implement protocol specific property access.

Source code in hololinked/hololinked/client/abstractions.py
class ConsumedThingProperty:
    # property get set abstraction
    # Dont add doc otherwise __doc__ in slots will conflict with class variable

    def __init__(self, resource: PropertyAffordance, owner_inst: Any, logger: structlog.stdlib.BoundLogger) -> None:
        """
        Parameters
        ----------
        resource: PropertyAffordance
            dataclass object TD fragment representing the property (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

    @property  # i.e. cannot have setter
    def last_read_value(self) -> Any:
        """cache of last read value"""
        raise NotImplementedError("implement last_read_value per protocol")

    def set(self, value: Any) -> None:
        """
        Set or write property value.

        Parameters
        ----------
        value: Any
            value to set
        """
        raise NotImplementedError("implement property set per protocol")

    def get(self) -> Any:
        """
        Get or read property value.

        Returns
        -------
        Any
            property value
        """
        raise NotImplementedError("implement property get per protocol")

    async def async_set(self, value: Any) -> None:
        """
        Async set or write property value - asynchronous at the network level,
        may not necessarily be at the server level.

        Parameters
        ----------
        value: Any
            value to set
        """
        raise NotImplementedError("implement async property set per protocol")

    async def async_get(self) -> Any:
        """
        Async get or read property value - asynchronous at the network level,
        may not necessarily be at the server level.

        Returns
        -------
        Any
            property value
        """
        raise NotImplementedError("implement async property get per protocol")

    def noblock_get(self) -> str:
        """
        Get or read property value without blocking, i.e. make a request and collect it later
        and the method returns immediately. Server must return a message ID to identify the request.

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

    def noblock_set(self, value: Any) -> str:
        """
        Set or write property value without blocking, i.e. make a request and collect it later
        and the method returns immediately. Server must return a message ID to identify the request.

        Parameters
        ----------
        value: Any
            value to set

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

    def oneway_set(self, value: Any) -> None:
        """
        Set property value without waiting for acknowledgement. The server also does not send any reply.
        There is no guarantee that the property value was set.

        Parameters
        ----------
        value: Any
            value to set
        """
        raise NotImplementedError("implement property oneway set per protocol")

    def observe(self, *callbacks: Callable) -> None:
        """
        Observe property value changes

        Parameters
        ----------
        *callbacks: Callable
            callback to call when property value changes
        """
        # looks like this will be unused. observe property is done via ConsumedThingEvent
        raise NotImplementedError("implement property observe per protocol")

    def unobserve(self) -> None:
        """Stop observing property value changes"""
        # looks like this will be unused, observe property is done via ConsumedThingEvent
        raise NotImplementedError("implement property unobserve per protocol")

    def read_reply(self, message_id: str, timeout: float | int | None = None) -> Any:
        """
        Read the reply of the property get or set 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 property get or set
        """
        raise NotImplementedError("implement property read_reply per protocol")

Functions

__init__

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

Parameters:

Name Type Description Default

resource

PropertyAffordance

dataclass object TD fragment representing the property (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: PropertyAffordance, owner_inst: Any, logger: structlog.stdlib.BoundLogger) -> None:
    """
    Parameters
    ----------
    resource: PropertyAffordance
        dataclass object TD fragment representing the property (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

get

get() -> Any

Get or read property value.

Returns:

Type Description
Any

property value

Source code in hololinked/hololinked/client/abstractions.py
def get(self) -> Any:
    """
    Get or read property value.

    Returns
    -------
    Any
        property value
    """
    raise NotImplementedError("implement property get per protocol")

set

set(value: Any) -> None

Set or write property value.

Parameters:

Name Type Description Default

value

Any

value to set

required
Source code in hololinked/hololinked/client/abstractions.py
def set(self, value: Any) -> None:
    """
    Set or write property value.

    Parameters
    ----------
    value: Any
        value to set
    """
    raise NotImplementedError("implement property set per protocol")

async_get async

async_get() -> Any

Async get or read property value - asynchronous at the network level, may not necessarily be at the server level.

Returns:

Type Description
Any

property value

Source code in hololinked/hololinked/client/abstractions.py
async def async_get(self) -> Any:
    """
    Async get or read property value - asynchronous at the network level,
    may not necessarily be at the server level.

    Returns
    -------
    Any
        property value
    """
    raise NotImplementedError("implement async property get per protocol")

async_set async

async_set(value: Any) -> None

Async set or write property value - asynchronous at the network level, may not necessarily be at the server level.

Parameters:

Name Type Description Default

value

Any

value to set

required
Source code in hololinked/hololinked/client/abstractions.py
async def async_set(self, value: Any) -> None:
    """
    Async set or write property value - asynchronous at the network level,
    may not necessarily be at the server level.

    Parameters
    ----------
    value: Any
        value to set
    """
    raise NotImplementedError("implement async property set per protocol")

noblock_get

noblock_get() -> str

Get or read property value without blocking, i.e. make a request and collect it later and the method returns immediately. Server must return a message ID to identify the request.

Returns:

Type Description
str

id of the request or message (UUID4 as string)

Source code in hololinked/hololinked/client/abstractions.py
def noblock_get(self) -> str:
    """
    Get or read property value without blocking, i.e. make a request and collect it later
    and the method returns immediately. Server must return a message ID to identify the request.

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

noblock_set

noblock_set(value: Any) -> str

Set or write property value without blocking, i.e. make a request and collect it later and the method returns immediately. Server must return a message ID to identify the request.

Parameters:

Name Type Description Default

value

Any

value to set

required

Returns:

Type Description
str

id of the request or message (UUID4 as string)

Source code in hololinked/hololinked/client/abstractions.py
def noblock_set(self, value: Any) -> str:
    """
    Set or write property value without blocking, i.e. make a request and collect it later
    and the method returns immediately. Server must return a message ID to identify the request.

    Parameters
    ----------
    value: Any
        value to set

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

oneway_set

oneway_set(value: Any) -> None

Set property value without waiting for acknowledgement. The server also does not send any reply. There is no guarantee that the property value was set.

Parameters:

Name Type Description Default

value

Any

value to set

required
Source code in hololinked/hololinked/client/abstractions.py
def oneway_set(self, value: Any) -> None:
    """
    Set property value without waiting for acknowledgement. The server also does not send any reply.
    There is no guarantee that the property value was set.

    Parameters
    ----------
    value: Any
        value to set
    """
    raise NotImplementedError("implement property oneway set per protocol")

read_reply

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

Read the reply of the property get or set 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 property get or set

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 property get or set 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 property get or set
    """
    raise NotImplementedError("implement property read_reply per protocol")

observe

observe(*callbacks: Callable) -> None

Observe property value changes

Parameters:

Name Type Description Default

*callbacks

Callable

callback to call when property value changes

()
Source code in hololinked/hololinked/client/abstractions.py
def observe(self, *callbacks: Callable) -> None:
    """
    Observe property value changes

    Parameters
    ----------
    *callbacks: Callable
        callback to call when property value changes
    """
    # looks like this will be unused. observe property is done via ConsumedThingEvent
    raise NotImplementedError("implement property observe per protocol")

unobserve

unobserve() -> None

Stop observing property value changes

Source code in hololinked/hololinked/client/abstractions.py
def unobserve(self) -> None:
    """Stop observing property value changes"""
    # looks like this will be unused, observe property is done via ConsumedThingEvent
    raise NotImplementedError("implement property unobserve per protocol")