Skip to content

Allow targeting categories with subtypes #168

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

Open
wants to merge 2 commits into
base: v0.x.x
Choose a base branch
from

Conversation

Marenz
Copy link
Contributor

@Marenz Marenz commented May 19, 2025

  • Update to latest dispatch-api
  • Implement extra classes for each target type

Fixes #139

@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:tooling Affects the development tooling (CI, deployment, dependency management, etc.) part:cli Affects the command-line interface part:test-utils Affects the test utilities part:dispatcher labels May 19, 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.

LGTM in general, although not completely convinced about the current approach with CategoryAndType, looks a bit too low-level for the "high-level interface".

Comment on lines 40 to 53
class EvChargerType(IntEnum):
"""Enum representing the type of EV charger."""

EV_CHARGER_TYPE_UNSPECIFIED = PBEvChargerType.EV_CHARGER_TYPE_UNSPECIFIED
"""Unspecified type of EV charger."""

EV_CHARGER_TYPE_AC = PBEvChargerType.EV_CHARGER_TYPE_AC
"""AC EV charger."""

EV_CHARGER_TYPE_DC = PBEvChargerType.EV_CHARGER_TYPE_DC
"""DC EV charger."""

EV_CHARGER_TYPE_HYBRID = PBEvChargerType.EV_CHARGER_TYPE_HYBRID
"""Hybrid EV charger."""
Copy link
Contributor

Choose a reason for hiding this comment

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

I have these in the microgrid API too, next step is to move them to client-common so we can share it. I will do a PR with this soon after I finish the microgrid API 0.17 PR, probably this week. But just FYI, I think we should move forward adding it where needed locally as it might take some time to agree on something we are all happy about to put in common + release. In any case, I would remove the EV_CHARGER_TYPE_ prefix here.


This is a frozen set, so it is immutable.
The target components are used to specify the components that a dispatch
should target.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe include a match example here?

@@ -5,13 +5,23 @@

import json
from datetime import datetime, timedelta, timezone
from sre_constants import IN
Copy link
Contributor

Choose a reason for hiding this comment

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

I bet this was Tab-oriented-programming + auto-import 😆

Suggested change
from sre_constants import IN

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was more desperation, but this is a draft after all :P

@github-actions github-actions bot added the part:docs Affects the documentation label May 27, 2025
@Marenz Marenz marked this pull request as ready for review May 27, 2025 11:30
@Marenz Marenz requested review from a team as code owners May 27, 2025 11:30
@Marenz Marenz requested review from stefan-brus-frequenz, shsms and llucax and removed request for shsms and stefan-brus-frequenz May 27, 2025 11:30
@Marenz Marenz force-pushed the api_update branch 2 times, most recently from b5f513a to 722b878 Compare May 27, 2025 13:06
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.

Pretty cool!

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
* `TargetComponents` was reworked. It now is a type alias for `TargetIds | TargetCategories`:
* `TargetIds` can be used to specify one or more specific target IDs:
* `TargetIds(1, 2, 3)` or
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless we have some other situation like the one @ela-kotulska-frequenz mentioned and we want this only as a transitional step, I wouldn't allow raw ints, the whole point of introducing ComponentId is that you can't accidentally pass some random int (or some ID for other class of object) where a specific ID is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, we're not introducing it in this PR though

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see, so we can keep the conversion to int until this repo starts using ComponentId (when it is added to client-common. Then we only accept ComponentId.

* `TargetComponents` was reworked. It now is a type alias for `TargetIds | TargetCategories`:
* `TargetIds` can be used to specify one or more specific target IDs:
* `TargetIds(1, 2, 3)` or
* `TargetIds(ComponentIds(1), ComponentIds(2), ComponentIds(3))`
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, but this seems to be fake news, right? This one is not supported yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is specifically supported (if the type can be cast to int)!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is wrong. It should only accept ComponentId, we created that type as a safety measure, we don't want to accept any int crap as a CompentId unless someone explicitly converts that int into a ComponentId.

This is a frozen set, so it is immutable.
"""

def __new__(cls, *ids: SupportsInt) -> "TargetIds":
Copy link
Contributor

Choose a reason for hiding this comment

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

😱 you can't define __init__ becuase it is frozen? 🥶

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess? THe init ctor doesn't take parameters :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Even weirder.

@Marenz Marenz requested a review from llucax May 28, 2025 09:57
@Marenz Marenz force-pushed the api_update branch 2 times, most recently from 53a74f2 to 4ccb8e7 Compare May 28, 2025 10:35
Renames a few fields, but stays compatible otherwise.

Signed-off-by: Mathias L. Baumann <[email protected]>
llucax
llucax previously approved these changes May 28, 2025
..and support the latest CategoryAndType target type.

This implements extra classes for each target component case:
* List of Ids `TargetIds`
* List of categories: `TargetCategories`
* List of categories + subtypes: `TargetCategoriesAndTypes`

This was easier to do together as the addition of the new type
increased the places where it
was difficult to find out what the actual target type/ids is/are.

Signed-off-by: Mathias L. Baumann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:cli Affects the command-line interface part:dispatcher part:docs Affects the documentation part:test-utils Affects the test utilities 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.

Improve how to get different types of Dispatch.target
3 participants