Metrics and SenML¶
Python API reference for the tolomeo.metrics and tolomeo.senml modules.
A Metric describes one value a plugin publishes; SenMLRecordBuilder turns metric values into the SenML records sent
over NATS. For the wire format, see SenML Format.
Metric¶
tolomeo.metrics.Metric
dataclass
¶
A single metric definition used to describe sensor data.
Metrics are declared in a plugin's Meta.out_metrics or
Meta.in_metrics. They define the shape of data the plugin
produces or consumes.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable metric name (e.g. |
unit |
str
|
Unit of measure (e.g. |
type |
MetricType
|
|
data_type |
MetricDataType
|
|
id |
str
|
Unique identifier, equal to |
Source code in tolomeo/metrics.py
as_dict()
¶
custom_dict(kv_pairs)
staticmethod
¶
Drop private fields when a metric is rendered as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kv_pairs
|
Any
|
The field name/value pairs, as passed by |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
The pairs whose name does not start with an underscore. |
Source code in tolomeo/metrics.py
tolomeo.metrics.MetricType
¶
tolomeo.metrics.MetricDataType
¶
SenML¶
tolomeo.senml.SenMLRecord
dataclass
¶
A single SenML record representing one measurement or command.
Follows the SenML (Sensor Measurement Lists) JSON format defined in RFC 8428. Only the fields relevant to the ToloMEO protocol are used.
Attributes:
| Name | Type | Description |
|---|---|---|
bn |
str
|
Base name — identifies the source device or service. |
n |
str
|
Name — identifies the specific measurement or command. |
t |
float | None
|
Timestamp as a Unix epoch float (optional). |
u |
str | None
|
Unit of measure (optional, e.g. |
v |
float | None
|
Numeric value (optional). |
vs |
str | None
|
String value — used for JSON-encoded command payloads (optional). |
Source code in tolomeo/senml.py
as_dict()
¶
custom_dict(kv_pairs)
staticmethod
¶
Drop unset fields when a record is rendered as a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kv_pairs
|
Any
|
The field name/value pairs, as passed by |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
The pairs whose value is not None. SenML omits absent fields |
Dict
|
rather than sending them as nulls. |
Source code in tolomeo/senml.py
tolomeo.senml.SenMLRecordBuilder
¶
Builds a single SenMLRecord from raw data using a configurable factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_name
|
str
|
The |
required |
factory_class
|
Type[SenMLRecordFactory]
|
The |
required |
Source code in tolomeo/senml.py
build(data)
¶
Build one SenMLRecord from data using the configured factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Raw input passed to |
required |
Returns:
| Type | Description |
|---|---|
SenMLRecord
|
A fully constructed |
Source code in tolomeo/senml.py
Errors¶
tolomeo.exceptions.MetricNotFoundError
¶
tolomeo.exceptions.DuplicateMetricError
¶
Bases: ValueError
Raised when attempting to add a metric that already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The id of the metric. |
required |
name
|
str
|
The name of the metric. |
required |