Skip to content

Conversation

@eduardiazf
Copy link
Contributor

@eduardiazf eduardiazf commented Aug 25, 2025

Summary

This PR introduces comprehensive support for electrical components in the Frequenz Assets API client, including new data types, enums, CLI commands, and enhanced serialization capabilities.

Changes Made

🆕 New Features

  • Electrical Component Types: Added ElectricalComponent class with support for batteries, EV chargers, inverters, grid connection points, and power transformers
  • Component Categories: Implemented category-specific information classes (Battery, EvCharger, Inverter, GridConnectionPoint, PowerTransformer)
  • Metric System: Added Metric enum supporting various electrical measurements (DC voltage/current/power, AC frequency/voltage, phase-to-phase voltages)
  • Operational Lifetime: Added Lifetime class for tracking component operational periods
  • Configuration Bounds: Implemented MetricConfigBounds and Bound classes for component metric limits

🔧 Enhanced Functionality

  • API Client: Added get_electrical_components() method to retrieve electrical components from a microgrid
  • CLI Commands: New electrical-components command for querying component data
  • Custom JSON Encoders: Implemented specialized serializers for both Microgrid and ElectricalComponent objects
  • Type Consolidation: Consolidated battery, EV charger, and inverter enums into unified imports

📚 Documentation & CLI

  • Enhanced CLI command documentation for retrieving electrical components
  • Added comprehensive docstrings for all new classes and methods
  • Improved error handling and user experience in CLI utilities

🔄 Dependencies

  • Updated frequenz-client-common from >=0.3.2 to >=0.3.6

Examples

CLI Usage

Query electrical components for a specific microgrid:

assets-cli electrical-components 1

Sample Output

[
  {
    "id": 414,
    "microgrid_id": 226,
    "name": "battery1",
    "category": 5,
    "manufacturer": "Commeo",
    "model_name": "Commeo HV",
    "operational_lifetime": {
      "start": null,
      "end": null
    },
    "rated_bounds": {
      "102": {
        "lower": 9.0,
        "upper": 45.0
      },
      "101": {
        "lower": 5.0,
        "upper": 95.0
      }
    },
    "type": 1
  },
  {
    "id": 415,
    "microgrid_id": 226,
    "name": "Grid1",
    "category": 1,
    "manufacturer": null,
    "model_name": null,
    "operational_lifetime": {
      "start": null,
      "end": null
    },
    "rated_bounds": {},
    "rated_fuse_current": 10
  },
  {
    "id": 416,
    "microgrid_id": 226,
    "name": "Relay1",
    "category": 7,
    "manufacturer": null,
    "model_name": null,
    "operational_lifetime": {
      "start": null,
      "end": null
    },
    "rated_bounds": {}
  }
]

Testing

  • All new functionality includes comprehensive type hints and documentation
  • Maintains backward compatibility with existing microgrid functionality
  • Follows established patterns for protobuf message handling and serialization

Breaking Changes

None - this is a purely additive feature that extends existing functionality.

@eduardiazf eduardiazf requested review from a team as code owners August 25, 2025 09:39
@eduardiazf eduardiazf added the cmd:skip-release-notes It is not necessary to update release notes for this PR label Aug 25, 2025
@eduardiazf eduardiazf force-pushed the feat/electrial-components branch 2 times, most recently from 3e84a78 to ea8cfdb Compare August 25, 2025 12:50
@github-actions github-actions bot added the part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) label Aug 25, 2025
@eduardiazf eduardiazf force-pushed the feat/electrial-components branch 2 times, most recently from 3e9ed22 to 291f468 Compare August 26, 2025 11:08
@eduardiazf eduardiazf removed the cmd:skip-release-notes It is not necessary to update release notes for this PR label Aug 26, 2025
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:docs Affects the documentation labels Aug 26, 2025
@eduardiazf eduardiazf force-pushed the feat/electrial-components branch 3 times, most recently from f768466 to d98bb97 Compare September 1, 2025 12:02
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

Besides the comments, it LGTM in general although I didn't check in depth if there are more diversions compared to my base implementation of the dataclass wrappers.

@eduardiazf eduardiazf force-pushed the feat/electrial-components branch from 8ce9622 to 7ae1238 Compare September 2, 2025 12:17
@eduardiazf eduardiazf requested a review from llucax September 3, 2025 10:01
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

OK, this looks good in general to me. I think most comments are FYI about ideas I have for the final version in client-common, but there are a few comments about a couple of small issues.

About the commit split, I think by now the split makes this PR (and the git history) harder to read, as not only there a lot of commits, but also commits are not very isolated, they look more like checkpoints while editing files, which makes it very hard to review and very easy to get lost among the unrelated changes.

I would strongly suggest to improve the commit splitting before merging. I don't think we need a lot of commits here, as 95% of the changes here is just creating new files, and all of that is probably fine to include in just one commit.

So splitting in 2 commits, one adding all the new files, and then a second commit adding the new client method, for me would be a huge improvement already.

Ideally I would split a bit more, also not a lot, but something like:

  • First commit adding the new files verbatim as you copy them from the microgrid API client, using the old common version.
  • Copy all the files in the current state overwriting those original files. With this we get one commit where we can clearly see all the changes that were necessary to go from common API pre-v0.8 to v0.8, which will be very useful when migrating the microgrid API client too.
  • Unrelated fixes, like re-exporting the PermissionDenied exception (ideally one per unrelated change, but I'm also fine to do them all in one commit if it makes things easier).
  • Add the new client method.
  • Add the tests for the new client method.
  • Add the get_microgrid_details method test, or even leave those for a separate PR, but not sure, maybe you need to include them here if you are removing old tests for that method). If splitting is complicated, also one commit with all test-related changes would be fine too.

Comment on lines +18 to +29
@enum.unique
class BatteryType(enum.Enum):
"""The known types of batteries."""

UNSPECIFIED = electrical_components_pb2.BATTERY_TYPE_UNSPECIFIED
"""The battery type is unspecified."""

LI_ION = electrical_components_pb2.BATTERY_TYPE_LI_ION
"""Lithium-ion (Li-ion) battery."""

NA_ION = electrical_components_pb2.BATTERY_TYPE_NA_ION
"""Sodium-ion (Na-ion) battery."""
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking about removing these enums in the final version for client-common. With the current approach we can easily specify battery/inverter/etc. types and different component categories using Python classes, so providing the enums too doesn't add any value and introduces more ways to do the same thing, which can be confusing for users.

We don't need to change anything else, but just FYI and to know your opinion, in case I'm missing something.

Comment on lines +51 to +52
type: BatteryType | int
"""The type of this battery.
Copy link
Contributor

Choose a reason for hiding this comment

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

If/when we remove the enum, this field will be gone here, and only added to UnrecognizedBattery as just type: int.

Again, just FYI.

Copy link
Contributor

Choose a reason for hiding this comment

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

This encoder ended up being pretty generally useful! I think we should definitely move this encoder to frequenz-core/frequenz-client-common in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

): self._encode(value)
for key, value in o.items()
}
if isinstance(o, (list, tuple, set, frozenset)):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick:

Suggested change
if isinstance(o, (list, tuple, set, frozenset)):
elif isinstance(o, (list, tuple, set, frozenset)):

@llucax
Copy link
Contributor

llucax commented Sep 8, 2025

Oh, and BTW and just for the records, I didn't review much of the _from_proto() implementations or tests, I assumed they are more or less the same as the original files.

…utilities

This commit introduces a comprehensive set of classes and functions for managing electrical components within the microgrid framework. Key additions include:

- Definitions for various electrical components such as batteries, inverters, chargers, and more, each with specific attributes and categories.
- Protobuf message loading functions to convert messages into corresponding Python objects.
- JSON encoding utilities for serializing component data for API interactions.

These changes lay the groundwork for enhanced functionality and integration within the microgrid system.

Signed-off-by: eduardiazf <[email protected]>
This commit includes the following changes:
- Updated `setuptools_scm` and various dependencies in `pyproject.toml` to their latest versions.
- Changed the GitHub Actions checkout action from version 4 to 5 in CI workflows.
- Removed unused test files and helper functions related to the Assets API client, including type definitions and mock data.

These updates enhance the project's dependency management and streamline the testing setup.

Signed-off-by: eduardiazf <[email protected]>
…improvements

This commit introduces several key updates to the Assets API client, including:
- New method `list_microgrid_electrical_components()` for retrieving electrical components in a microgrid.
- Updated CLI command `assets-cli electrical-components <microgrid-id>` for displaying electrical components.
- Improved error handling and type safety in the client.
- Enhanced JSON encoding for better serialization of enum keys.
- Added new exceptions for better error management.

These changes significantly enhance the functionality and usability of the Assets API client within the Frequenz microgrid framework.

Signed-off-by: eduardiazf <[email protected]>
This commit includes several updates to the Assets API client tests and utility functions:
- Refactored test structure for better organization and clarity, including renaming test files and updating docstrings.
- Introduced new test cases for retrieving microgrid details and electrical components, enhancing coverage for the Assets API client.
- Added utility functions to streamline test case management and improve readability.
- Updated the JSON encoder logic in the AssetsJSONEncoder class for better handling of container types.

These changes enhance the maintainability and robustness of the testing framework for the Assets API client.

Signed-off-by: eduardiazf <[email protected]>
@eduardiazf eduardiazf force-pushed the feat/electrial-components branch from 4d50f08 to 24d835c Compare September 26, 2025 10:46
llucax
llucax previously approved these changes Sep 26, 2025
Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

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

Awesome 🎉

Thanks for the patience! I will create a follow-up issues with pending comments where appropriate.

@eduardiazf eduardiazf dismissed llucax’s stale review September 26, 2025 13:05

The merge-base changed after approval.

@eduardiazf eduardiazf added this pull request to the merge queue Sep 26, 2025
Merged via the queue into frequenz-floss:v0.x.x with commit 3a7a39f Sep 26, 2025
5 checks passed
@eduardiazf eduardiazf deleted the feat/electrial-components branch September 29, 2025 07:56
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: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