Skip to content

Conversation

@llucax
Copy link
Contributor

@llucax llucax commented Jul 2, 2025

Implements the new list_components call in the MicrogridApiClient, adds detailed tests for component classes and protobuf conversions, and enhances the Lifetime validation message.

  • Introduced list_components method with component and category filters in the client
  • Added many component constructor and proto‐conversion tests, including new test_list_components
  • Updated Lifetime validation to include values in the error message and adjusted tests accordingly

Part of #55.

@Copilot Copilot AI review requested due to automatic review settings July 2, 2025 15:29
@llucax llucax requested review from a team as code owners July 2, 2025 15:29
@github-actions github-actions bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:client Affects the client code labels Jul 2, 2025
@llucax llucax requested a review from shsms July 2, 2025 15:29
@llucax llucax self-assigned this Jul 2, 2025
@llucax llucax added this to the v0.17.0 milestone Jul 2, 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

Implements the new list_components call in the MicrogridApiClient, adds detailed tests for component classes and protobuf conversions, and enhances the Lifetime validation message.

  • Introduced list_components method with component and category filters in the client
  • Added many component constructor and proto‐conversion tests, including new test_list_components
  • Updated Lifetime validation to include values in the error message and adjusted tests accordingly

Reviewed Changes

Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.

File Description
src/frequenz/client/microgrid/_client.py Added list_components method and _get_category_value helper
src/frequenz/client/microgrid/_lifetime.py Enhanced ValueError message in Lifetime.__post_init__
tests/test_client.py Added test_list_components for the client API call
Comments suppressed due to low confidence (3)

src/frequenz/client/microgrid/_client.py:178

  • [nitpick] There is a grammar error in the docstring: remove the extra "are" so it reads "can be connected to each other" instead of "are can be connected to each other".
        are can be connected to each other to form an electrical circuit, which can

src/frequenz/client/microgrid/_client.py:186

  • The example refers to ids as a filter name, but the parameter is named components. Update the example to use components for consistency.
        Example:

src/frequenz/client/microgrid/_client.py:169

  • [nitpick] Consider renaming the components parameter to component_ids or similar to avoid confusion between component instances and component identifiers.
    async def list_components(  # noqa: DOC502 (raises ApiClientError indirectly)

@llucax
Copy link
Contributor Author

llucax commented Jul 2, 2025

This should be the last big PR.

@llucax
Copy link
Contributor Author

llucax commented Jul 3, 2025

I replied to all comments and applied the suggested fix to the electrolyzer docstring. I will squash to the commit introducing that docstring when the PR is approved.

@llucax llucax requested a review from shsms July 3, 2025 11:13
@llucax llucax enabled auto-merge July 4, 2025 08:47
llucax added 9 commits July 4, 2025 10:48
The following classes are added:

* `Chp`
* `Converter`
* `CryptoMiner`
* `Electrolyzer`
* `Hvac`
* `Meter`
* `Precharger`
* `Relay`

All these components are just plain subclasses of `Component` that only
override the category.

Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
Battery components have an attached battery type. To encode this into
the Python type system, we create a sub-class per each battery type,
similar to what we do with components.

The special types `UnspecifiedBattery` and `UnrecognizedBattery` are
added to represent a battery with type `UNSPECIFIED` and a battery with
a battery type we don't recognize (this could happen if using a newer
server providing new battery types) respectively.

On top of that, we define a `BatteryTypes` type alias to make it easy
to type-hint function that want to return all known battery types as a
type union instead of using inheritance.

Signed-off-by: Leandro Lucarella <[email protected]>
Like batteries, EV charger components have an attached type. To encode
this into the Python type system, we create a sub-class per each type.

As with batteries, special types are using to represent a EV charger
with type `UNSPECIFIED` and with type we don't recognize, and define a
type alias to make it easy to type-hint function that want to return all
known EV charger types as a type union instead of using inheritance.

Signed-off-by: Leandro Lucarella <[email protected]>
Like batteries and EV chargers, inverter components have an attached
type. To encode this into the Python type system, we create a sub-class
per each type.

Special types are also used to represent a inverter with type
`UNSPECIFIED` and with type we don't recognize, and we define a type
alias to make it easy to type-hint function that want to return all
known inverter types as a type union instead of using inheritance.

Signed-off-by: Leandro Lucarella <[email protected]>
Problematic components are components that can't be mapped to known
category types (or are `UNSPECIFIED`).  They also include components
with mismatched a category, i.e. a component with a particular known
category but that also has category-specific information that doesn't
match the specified category. For example if the category is `BATTERY`
but the category-specific information is for a `INVERTER`.

Signed-off-by: Leandro Lucarella <[email protected]>
These aliases are type unions for all supported components, and for all
known problematic, unspecified and unrecognized components. These
include the specific types of components with sub-types, like batteries,
EV chargers and inverters.

These type aliases only include concrete types, the base types are not
included, this way they can be used as type hints where match statements
should be used.

Signed-off-by: Leandro Lucarella <[email protected]>
llucax added 3 commits July 4, 2025 10:48
The message now includes the problematic values.

Signed-off-by: Leandro Lucarella <[email protected]>
The `component_from_proto()` function parses protobuf `Component`
messages and create the appropriate and specific component type of our
component hierarchy.

During parsing, a few consistency checks are done in the protobuf
message. Solvable errors are recovered as much as possible. Major issues
are logged as warnings, and minor issues are logged as debug.

Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
@llucax llucax force-pushed the list-components branch from aa96f1a to dad8574 Compare July 4, 2025 08:49
@llucax llucax merged commit f6dfe48 into frequenz-floss:v0.17.x Jul 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:client Affects the client code part:docs Affects the documentation 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