-
Notifications
You must be signed in to change notification settings - 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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b3bc058
Add trivial subclasses of `Component`
llucax ff071aa
Add `Fuse` component
llucax b20c6c9
Add `GridConnectionPoint` component
llucax 052d90e
Add `VoltageTransformer` component
llucax 5a8f8ba
Add `Battery` component and sub-classes/types
llucax eecd8c4
Add `EvCharger` component and sub-classes/types
llucax 76f4c34
Add `Inverter` component and sub-classes/types
llucax 509ae9c
Add `ProblematicComponent` and sub-classes
llucax 8c21744
Add component types aliases
llucax cbfb317
Improve lifetime validation exception
llucax c43dafc
Add parsing of components from protobuf messages
llucax dad8574
Implement `ListComponents`
llucax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # License: MIT | ||
| # Copyright © 2024 Frequenz Energy-as-a-Service GmbH | ||
|
|
||
| """Battery component.""" | ||
|
|
||
| import dataclasses | ||
| import enum | ||
| from typing import Any, Literal, Self, TypeAlias | ||
|
|
||
| from frequenz.api.common.v1.microgrid.components import battery_pb2 | ||
|
|
||
| from ._category import ComponentCategory | ||
| from ._component import Component | ||
|
|
||
|
|
||
| @enum.unique | ||
| class BatteryType(enum.Enum): | ||
| """The known types of batteries.""" | ||
|
|
||
| UNSPECIFIED = battery_pb2.BATTERY_TYPE_UNSPECIFIED | ||
| """The battery type is unspecified.""" | ||
|
|
||
| LI_ION = battery_pb2.BATTERY_TYPE_LI_ION | ||
| """Lithium-ion (Li-ion) battery.""" | ||
|
|
||
| NA_ION = battery_pb2.BATTERY_TYPE_NA_ION | ||
| """Sodium-ion (Na-ion) battery.""" | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class Battery(Component): | ||
| """An abstract battery component.""" | ||
|
|
||
| category: Literal[ComponentCategory.BATTERY] = ComponentCategory.BATTERY | ||
| """The category of this component. | ||
|
|
||
| Note: | ||
| This should not be used normally, you should test if a component | ||
| [`isinstance`][] of a concrete component class instead. | ||
|
|
||
| It is only provided for using with a newer version of the API where the client | ||
| doesn't know about a new category yet (i.e. for use with | ||
| [`UnrecognizedComponent`][frequenz.client.microgrid.component.UnrecognizedComponent]) | ||
| and in case some low level code needs to know the category of a component. | ||
| """ | ||
|
|
||
| type: BatteryType | int | ||
| """The type of this battery. | ||
|
|
||
| Note: | ||
| This should not be used normally, you should test if a battery | ||
| [`isinstance`][] of a concrete battery class instead. | ||
|
|
||
| It is only provided for using with a newer version of the API where the client | ||
| doesn't know about the new battery type yet (i.e. for use with | ||
| [`UnrecognizedBattery`][frequenz.client.microgrid.component.UnrecognizedBattery]). | ||
| """ | ||
|
|
||
| # pylint: disable-next=unused-argument | ||
| def __new__(cls, *args: Any, **kwargs: Any) -> Self: | ||
| """Prevent instantiation of this class.""" | ||
| if cls is Battery: | ||
| raise TypeError(f"Cannot instantiate {cls.__name__} directly") | ||
| return super().__new__(cls) | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class UnspecifiedBattery(Battery): | ||
| """A battery of a unspecified type.""" | ||
|
|
||
| type: Literal[BatteryType.UNSPECIFIED] = BatteryType.UNSPECIFIED | ||
| """The type of this battery. | ||
|
|
||
| Note: | ||
| This should not be used normally, you should test if a battery | ||
| [`isinstance`][] of a concrete battery class instead. | ||
|
|
||
| It is only provided for using with a newer version of the API where the client | ||
| doesn't know about the new battery type yet (i.e. for use with | ||
| [`UnrecognizedBattery`][frequenz.client.microgrid.component.UnrecognizedBattery]). | ||
| """ | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class LiIonBattery(Battery): | ||
| """A Li-ion battery.""" | ||
|
|
||
| type: Literal[BatteryType.LI_ION] = BatteryType.LI_ION | ||
| """The type of this battery. | ||
|
|
||
| Note: | ||
| This should not be used normally, you should test if a battery | ||
| [`isinstance`][] of a concrete battery class instead. | ||
|
|
||
| It is only provided for using with a newer version of the API where the client | ||
| doesn't know about the new battery type yet (i.e. for use with | ||
| [`UnrecognizedBattery`][frequenz.client.microgrid.component.UnrecognizedBattery]). | ||
| """ | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class NaIonBattery(Battery): | ||
| """A Na-ion battery.""" | ||
|
|
||
| type: Literal[BatteryType.NA_ION] = BatteryType.NA_ION | ||
| """The type of this battery. | ||
|
|
||
| Note: | ||
| This should not be used normally, you should test if a battery | ||
| [`isinstance`][] of a concrete battery class instead. | ||
|
|
||
| It is only provided for using with a newer version of the API where the client | ||
| doesn't know about the new battery type yet (i.e. for use with | ||
| [`UnrecognizedBattery`][frequenz.client.microgrid.component.UnrecognizedBattery]). | ||
| """ | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class UnrecognizedBattery(Battery): | ||
| """A battery of an unrecognized type.""" | ||
|
|
||
| type: int | ||
| """The unrecognized type of this battery.""" | ||
|
|
||
|
|
||
| BatteryTypes: TypeAlias = ( | ||
| LiIonBattery | NaIonBattery | UnrecognizedBattery | UnspecifiedBattery | ||
| ) | ||
| """All possible battery types.""" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # License: MIT | ||
| # Copyright © 2024 Frequenz Energy-as-a-Service GmbH | ||
|
|
||
| """CHP component.""" | ||
|
|
||
| import dataclasses | ||
| from typing import Literal | ||
|
|
||
| from ._category import ComponentCategory | ||
| from ._component import Component | ||
|
|
||
|
|
||
| @dataclasses.dataclass(frozen=True, kw_only=True) | ||
| class Chp(Component): | ||
| """A combined heat and power (CHP) component.""" | ||
|
|
||
| category: Literal[ComponentCategory.CHP] = ComponentCategory.CHP | ||
| """The category of this component.""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.