Repository navigation
Add Sensor wrappers - #290
Merged
Merged
Conversation
The assets and microgrid clients each carry their own `Sensor` wrapper, so v0.4.1 should provide the shared one. It follows `Microgrid` and `ElectricalComponent`: a frozen keyword-only dataclass guarded by `_allow_construction`, an `operational_lifetime` typed `Lifetime | InvalidLifetime` (defaulting to an unbounded lifetime, as a missing wire field means) with the raising `get_operational_lifetime()`, `is_operational_at()` and `is_operational_now()` accessors, an `identity` property, and a `SID1:name` string form. The fields follow the wire names of `v1alpha8` `Sensor`: `model` (not the downstream `model_name`), and `name` as a plain `str` that is empty when unset, like every other wrapper here. The deprecated `manufacturer` and `model_name` wire fields are not wrapped, as `ElectricalComponent` does for its own copies of them. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Add the `microgrid.sensors.proto.v1alpha8` package with the conversion function for the `frequenz.api.common.v1alpha8.microgrid.sensors.Sensor` message. Malformed input is kept in the returned object: a malformed operational lifetime becomes an `InvalidLifetime` through `lifetime_from_proto`, and a missing one an unbounded `Lifetime`, as `electrical_component_from_proto` does. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Add the New Features release note and list `Sensor` in the User Guide overview next to `SensorId`. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
llucax
requested review from
florian-wagner-frequenz
and removed request for
a team
September 25, 2026 15:10
llucax
enabled auto-merge
September 25, 2026 19:18
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The converter can silently lose legacy model information from valid v1alpha8 sensor messages.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
What changed in this PR
Adds a Pythonic Sensor wrapper and v1alpha8 protobuf conversion support.
Changes:
- Adds immutable
Sensormodeling and lifetime helpers. - Adds protobuf conversion and comprehensive tests.
- Updates user documentation and release notes.
| File | Description |
|---|---|
src/frequenz/client/common/microgrid/sensors/_sensor.py |
Defines the Sensor wrapper. |
src/frequenz/client/common/microgrid/sensors/__init__.py |
Exports Sensor. |
src/frequenz/client/common/microgrid/sensors/proto/__init__.py |
Adds the conversion package. |
src/frequenz/client/common/microgrid/sensors/proto/v1alpha8/__init__.py |
Exports the converter. |
src/frequenz/client/common/microgrid/sensors/proto/v1alpha8/_sensor.py |
Converts protobuf sensors. |
tests/microgrid/sensors/__init__.py |
Initializes sensor tests. |
tests/microgrid/sensors/test_sensor.py |
Tests wrapper behavior. |
tests/microgrid/sensors/proto/__init__.py |
Initializes converter tests. |
tests/microgrid/sensors/proto/v1alpha8/__init__.py |
Initializes v1alpha8 tests. |
tests/microgrid/sensors/proto/v1alpha8/test_sensor.py |
Tests protobuf conversion. |
docs/user-guide/overview.md |
Documents sensor usage. |
RELEASE_NOTES.md |
Announces the new API. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
tiyash-basu-frequenz
approved these changes
Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

No description provided.