-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: v0.x.x
Are you sure you want to change the base?
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.
LGTM in general, although not completely convinced about the current approach with CategoryAndType
, looks a bit too low-level for the "high-level interface".
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.""" |
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.
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. |
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.
Maybe include a match
example here?
@@ -5,13 +5,23 @@ | |||
|
|||
import json | |||
from datetime import datetime, timedelta, timezone | |||
from sre_constants import IN |
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.
I bet this was Tab-oriented-programming + auto-import 😆
from sre_constants import IN |
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.
it was more desperation, but this is a draft after all :P
b5f513a
to
722b878
Compare
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.
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 |
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.
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 int
s, 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.
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.
I mean, we're not introducing it in this PR though
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.
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))` |
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.
Oh, but this seems to be fake news, right? This one is not supported yet?
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.
This is specifically supported (if the type can be cast to int)!
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.
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": |
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.
😱 you can't define __init__
becuase it is frozen
? 🥶
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.
I guess? THe init ctor doesn't take parameters :)
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.
Even weirder.
53a74f2
to
4ccb8e7
Compare
Renames a few fields, but stays compatible otherwise. Signed-off-by: Mathias L. Baumann <[email protected]>
..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]>
Fixes #139