Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented Jun 27, 2025

  • Make enums unique
  • Add missing component categories
  • Add a generic enum_from_proto() function
  • Deprecate uses of enum's .from_proto()

Signed-off-by: Leandro Lucarella <[email protected]>
Copilot AI review requested due to automatic review settings June 27, 2025 07:57
@llucax llucax requested a review from a team as a code owner June 27, 2025 07:57
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:microgrid Affects the microgrid protobuf definitions labels Jun 27, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves enum handling by introducing a generic enum_from_proto function and making various enums unique, while deprecating their old from_proto methods.

  • Introduces a generic enum_from_proto utility for converting protobuf enum values.
  • Applies the @enum.unique decorator to enums and deprecates the from_proto methods.
  • Adds missing component categories and updates Metric enum accordingly.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/test_enum_proto.py Adds tests for the new enum_from_proto utility
src/frequenz/client/common/microgrid/components/init.py Updates enums with @enum.unique and adds new component categories; deprecates from_proto
src/frequenz/client/common/metric/init.py Updates Metric enum with unique and deprecates from_proto method
src/frequenz/client/common/enum_proto.py Introduces the generic enum_from_proto utility and updates its documentation

llucax added 2 commits June 27, 2025 10:10
Signed-off-by: Leandro Lucarella <[email protected]>
This needs a bump of the minimum `frequenz-api-common` to v0.6.1 as this
category was added in that version.

Signed-off-by: Leandro Lucarella <[email protected]>
@github-actions github-actions bot added the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Jun 27, 2025
@llucax
Copy link
Contributor Author

llucax commented Jun 27, 2025

@flora-hofmann-frequenz feel free to port these changes to the v0.x.x branch

llucax added 4 commits June 27, 2025 11:36
This function can convert any `int` to any `Enum`, with optional
validation or forward-compatibility.

Signed-off-by: Leandro Lucarella <[email protected]>
Recommend using the new `enum_from_proto()` instead.

Signed-off-by: Leandro Lucarella <[email protected]>
This is to avoid errors in tests about duplicated `BaseId` prefixes.

Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax merged commit 2e59182 into frequenz-floss:v0.3.x Jun 30, 2025
5 checks passed
@llucax llucax deleted the enums branch July 1, 2025 08:49
@llucax llucax added this to the v0.3.3 milestone Jul 1, 2025
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 part:tooling Affects the development tooling (CI, deployment, dependency management, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants