heros.datasource.datasource¶
Classes¶
A datasource is a HERO that can provide information on a standardized interface. |
|
A class that can observe and handle the data emitted by one or more datasource HEROs. |
|
This local HERO periodically triggers the event "observable_data" to poll and publish data. |
Module Contents¶
- class heros.datasource.datasource.LocalDatasourceHERO(*args, observables: dict | None = None, **kwargs)¶
Bases:
heros.LocalHEROA 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.datasource.datasource.DatasourceObserver(object_selector: str = '*', *args, **kwargs)¶
Bases:
heros.EventObserverA 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.datasource.datasource.PolledLocalDatasourceHERO(*args, loop, interval: float = 5, **kwargs)¶
Bases:
LocalDatasourceHEROThis 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()¶