Allow metrics with an alias when no explicit metric name is provided #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the handling of metrics with aliases in the library to align with the Sparkplug specification. Previously, every metric was required to have a name when creating data messages, but the specification allows metrics with aliases to exclude the name. The changes introduce an alias-to-name mapping, and the logic is updated to handle metrics with either a name or alias.
Changes
When setting up metrics, if a metric has an alias, it is stored in the _names_mapping dictionary, which maps the alias to the metric name.
When updating metrics, we first check if the name is None and, if so, look up the alias in _names_mapping. If neither a name nor a valid alias is found, a ValueError is raised.