HERO Metadata¶
Metadata¶
If your HERO network grows larger, managing the large number of HEROs becomes tedious. It is then necessary To classify your HEROs somehow. This is why a HERO carries metadata in it’s discovery information. This metadata is
The identifier/name of the HERO
The class it was created from
An optional list of interfaces it implements
An optional list of tags attached to the HERO
An optional dict of extra metadata >=0.14.0
Note
Tags should be used for filtering and sorting of HEROs, while extra_metadata should contain metadata to for example control the behavior of HEROObserver``s, like the ``HEROMonitor.
The information of a LocalHERO that is controlling an RF device could look like the following
{
"name": "my_rfdevice",
"class": "vendorlibrary.module.rfdevice_class"
"implements": ["atomiq.components.electronics.rfsource.RFSource"],
"tags": ["boss:27ea419fe", "raspberry", "datasource"],
"extra_metadata": "{'my_option':'20'}"
}
In this case the HERO signals that it implements an atomiq RFSource, it was started by BOSS under a particular ID, it runs on a Raspberry Pi and is a datasource.
While the value for class is automatically determined from the class the LocalHERO has, setting values for the name, implements, extra_metadata and tags fields is up to the user.
All four fields can be set through the constructor of the LocalHERO class. Additionally, implements, extra_metadata and tags can be set through class level
attributes in your custom class that inherits from LocalHERO like shown in the following:
from heros import LocalHERO
class DummyRFDevice(LocalHERO):
_hero_implements = ["atomiq.components.electronics.rfsource.RFSource"]
_hero_tags = ["raspberry", "datasource"]
_hero_extra_metadata = {"my_option2":"400"}
def my_method(self):
pass
...
Note
If values are given to the constructor via arguments (like in the JSON above) and at class level, the lists/dicts are joined. Lists are converted to a set to avoid duplicates.
In a RemoteHERO the metadata is available from the class level attributes that could also be used on the LocalHERO side:
In [1]: from heros import RemoteHERO
In [2]: obj = RemoteHERO("my_rfdevice")
In [3]: obj._hero_implements
Out[3]: {'atomiq.components.electronics.rfsource.RFSource'}
In [4]: obj._hero_tags
Out[4]: {'raspberry', 'datasource'}
In [5]: obj._hero_extra_metadata
Out[5]: {'my_option':'20','my_option2','400'}
Note
Since the metadata is part of the discovery endpoint, it is also available in a HEROObserver.