heros

Submodules

Classes

LocalDatasourceHERO

A datasource is a HERO that can provide information on a standardized interface.

PolledLocalDatasourceHERO

This local HERO periodically triggers the event "observable_data" to poll and publish data.

DatasourceObserver

A class that can observe and handle the data emitted by one or more datasource HEROs.

DatasourceReturnValue

A structure to store data returned from a single entity in a datasource.

DatasourceReturnSet

Collection of multiple DatasourceReturnValue.

Functions

event(func)

Decorator for events.

Package Contents

class heros.LocalDatasourceHERO(*args, observables: dict | None = None, **kwargs)

Bases: heros.LocalHERO

A datasource is a HERO that can provide information on a standardized interface. This interface is the event observable_data. Instances in the zenoh network interested in the data provided by data sources can simply subscribe to the key expression @objects/realm/*/observable_data or use the DatasourceObserver.

To make your class a LocalDatasourceHERO make it inherit this class. This class is meant for datasources that create asynchronous events on their own. When processing such an event call observable_data to publish the data from this datasource.

Parameters:
  • name – name/identifier under which the object is available. Make sure this name is unique in the realm.

  • realm – realm the HERO should exist in. default is “heros”

observable_processor
_process_data(data)
observable_data(data)
class heros.PolledLocalDatasourceHERO(*args, loop, interval: float = 5, **kwargs)

Bases: LocalDatasourceHERO

This local HERO periodically triggers the event “observable_data” to poll and publish data. This class is meant for datasources that do not generate events on their own an thus should be polled on a periodical basis.

To make your class a PolledLocalDatasourceHERO make it inherit this class an implement the method _observable_data. The method will get called periodically and the return value will be published as an event.

Note

The periodic calling is realized via asyncio and will thus only work if the asyncio mainloop is started.

Parameters:
  • name – name/identifier under which the object is available. Make sure this name is unique in the realm.

  • realm – realm the HERO should exist in. default is “heros”

  • interval – time interval in seconds between consecutive calls of observable_data event

datasource_interval = 5
_loop
_stop_loop
_loop_task
async _trigger_datasource()
_destroy_hero()
observable_data()
_observable_data()
class heros.DatasourceObserver(object_selector: str = '*', *args, **kwargs)

Bases: heros.EventObserver

A class that can observe and handle the data emitted by one or more datasource HEROs. In particular, this class provides an efficient way to listen to the data emitted by all datasource HEROs in the realm. By not instantiating the HEROs themselves but just subscribing to the topics for the datasource, this reduces the pressure on the backing zenoh network. If, however, only the data of a few HEROs should be observed, it might make more sense to just instantiate the according RemoteHEROs and connect a callback to their observable_data signal.

Parameters:
  • object_selector – selector to specify which objects to observe. This becomes part of a zenoh selector and thus

  • realm. (can be anything that makes sense in the selector. Defaults to * to observe all HEROs in the)

_handle_event(key_expr: str, data)
register_observable_data_callback(func: callable)

Register a callback that should be called on observable_data. This method passes the function to EventObserver.register_callback

Parameters:

func – function to call on observable_data.

class heros.DatasourceReturnValue(id: str = None, time: float = None, value: float = None, unit: str = None, raw_value: float = None, raw_unit: str = None, inbound: int = -1, calibrated: bool = False, **kwargs)

Bases: dict

A structure to store data returned from a single entity in a datasource. A datasource can return multiple entities at once. In this case many DatasourceReturnValues are stored in a DatasourceReturnSet.

Default return values from datasource. They can be converted using a calibration.
param raw_value:

(float)

param raw_unit:

(str[10])

param time:

(int) creation time of the rawValue.

property id
property raw_value
property raw_unit
property value

(float) value in specified units.

property unit

SI Unit of the current tuple.

property time
property inbound

Boundary level (int) -1=unbound, 0=ok, 1=warn,error, fault

__str__()

Return str(self).

__repr__()

Return repr(self).

class heros.DatasourceReturnSet

Bases: tuple

Collection of multiple DatasourceReturnValue.

static from_data(data)
We try to build a DatasourceReturnSet by guessing the data format from the following options:
  • [FLOAT, FLOAT, ..] -> A list of raw_values

  • [(FLOAT, STR), (FLOAT, STR), ..] -> a list of (raw_value, raw_unit) tuples

  • {STR: FLOAT, STR: FLOAT, ..} -> a dict with id: raw_value

  • {STR: (FLOAT, STR), STR: (FLOAT, STR), …} a dict with id: (raw_value, raw_unit)

  • FLOAT -> raw_value

  • (FLOAT, STR) -> (raw_value, raw_unit)

heros.event(func: callable)

Decorator for events.

Note

Only use on methods bound to objects.