-
Couldn't load subscription status.
- Fork 5
Implement ListComponents
#165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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_componentsmethod with component and category filters in the client - Added many component constructor and proto‐conversion tests, including new
test_list_components - Updated
Lifetimevalidation 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
idsas a filter name, but the parameter is namedcomponents. Update the example to usecomponentsfor consistency.
Example:
src/frequenz/client/microgrid/_client.py:169
- [nitpick] Consider renaming the
componentsparameter tocomponent_idsor similar to avoid confusion between component instances and component identifiers.
async def list_components( # noqa: DOC502 (raises ApiClientError indirectly)
|
This should be the last big PR. |
|
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. |
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]>
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]>
Implements the new
list_componentscall in theMicrogridApiClient, adds detailed tests for component classes and protobuf conversions, and enhances theLifetimevalidation message.list_componentsmethod with component and category filters in the clienttest_list_componentsLifetimevalidation to include values in the error message and adjusted tests accordinglyPart of #55.