Skip to content

Add Sensor wrappers - #290

Merged
llucax merged 4 commits into
frequenz-floss:v0.x.xfrom
llucax:add-sensor-wrapper
Sep 28, 2026
Merged

llucax merged 4 commits into
frequenz-floss:v0.x.xfrom
llucax:add-sensor-wrapper

Conversation

@llucax

@llucax llucax commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

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
llucax requested a review from a team as a code owner September 25, 2026 15:10
@llucax
llucax requested review from florian-wagner-frequenz and removed request for a team September 25, 2026 15:10
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:microgrid Affects the microgrid protobuf definitions labels Sep 25, 2026
@llucax llucax self-assigned this Sep 25, 2026
@llucax
llucax requested a balanced review from Copilot September 25, 2026 19:18
@llucax
llucax enabled auto-merge September 25, 2026 19:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Medium severity

Open (1)
What changed in this PR

Adds a Pythonic Sensor wrapper and v1alpha8 protobuf conversion support.

Changes:

  • Adds immutable Sensor modeling 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.

@llucax
llucax added this pull request to the merge queue Sep 28, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit 13b269a Sep 28, 2026
9 checks passed
@llucax
llucax deleted the add-sensor-wrapper branch September 28, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:microgrid Affects the microgrid protobuf definitions part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants