|
| 1 | +# License: MIT |
| 2 | +# Copyright © 2024 Frequenz Energy-as-a-Service GmbH |
| 3 | + |
| 4 | +"""Electric vehicle (EV) charger component.""" |
| 5 | + |
| 6 | +import dataclasses |
| 7 | +import enum |
| 8 | +from typing import Any, Literal, Self, TypeAlias |
| 9 | + |
| 10 | +from frequenz.api.common.v1.microgrid.components import ev_charger_pb2 |
| 11 | + |
| 12 | +from ._category import ComponentCategory |
| 13 | +from ._component import Component |
| 14 | + |
| 15 | + |
| 16 | +@enum.unique |
| 17 | +class EvChargerType(enum.Enum): |
| 18 | + """The known types of electric vehicle (EV) chargers.""" |
| 19 | + |
| 20 | + UNSPECIFIED = ev_charger_pb2.EV_CHARGER_TYPE_UNSPECIFIED |
| 21 | + """The type of the EV charger is unspecified.""" |
| 22 | + |
| 23 | + AC = ev_charger_pb2.EV_CHARGER_TYPE_AC |
| 24 | + """The EV charging station supports AC charging only.""" |
| 25 | + |
| 26 | + DC = ev_charger_pb2.EV_CHARGER_TYPE_DC |
| 27 | + """The EV charging station supports DC charging only.""" |
| 28 | + |
| 29 | + HYBRID = ev_charger_pb2.EV_CHARGER_TYPE_HYBRID |
| 30 | + """The EV charging station supports both AC and DC.""" |
| 31 | + |
| 32 | + |
| 33 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 34 | +class EvCharger(Component): |
| 35 | + """An abstract EV charger component.""" |
| 36 | + |
| 37 | + category: Literal[ComponentCategory.EV_CHARGER] = ComponentCategory.EV_CHARGER |
| 38 | + """The category of this component. |
| 39 | +
|
| 40 | + Note: |
| 41 | + This should not be used normally, you should test if a component |
| 42 | + [`isinstance`][] of a concrete EV charger class instead. |
| 43 | +
|
| 44 | + It is only provided for using with a newer version of the API where the client |
| 45 | + doesn't know about a new category yet (i.e. for use with |
| 46 | + [`UnrecognizedComponent`][frequenz.client.microgrid.component.UnrecognizedComponent]) |
| 47 | + and in case some low level code needs to know the category of a component. |
| 48 | + """ |
| 49 | + |
| 50 | + type: EvChargerType | int |
| 51 | + """The type of this EV charger. |
| 52 | +
|
| 53 | + Note: |
| 54 | + This should not be used normally, you should test if a EV charger |
| 55 | + [`isinstance`][] of a concrete component class instead. |
| 56 | +
|
| 57 | + It is only provided for using with a newer version of the API where the client |
| 58 | + doesn't know about the new EV charger type yet (i.e. for use with |
| 59 | + [`UnrecognizedEvCharger`][frequenz.client.microgrid.component.UnrecognizedEvCharger]). |
| 60 | + """ |
| 61 | + |
| 62 | + # pylint: disable-next=unused-argument |
| 63 | + def __new__(cls, *args: Any, **kwargs: Any) -> Self: |
| 64 | + """Prevent instantiation of this class.""" |
| 65 | + if cls is EvCharger: |
| 66 | + raise TypeError(f"Cannot instantiate {cls.__name__} directly") |
| 67 | + return super().__new__(cls) |
| 68 | + |
| 69 | + |
| 70 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 71 | +class UnspecifiedEvCharger(EvCharger): |
| 72 | + """An EV charger of an unspecified type.""" |
| 73 | + |
| 74 | + type: Literal[EvChargerType.UNSPECIFIED] = EvChargerType.UNSPECIFIED |
| 75 | + """The type of this EV charger. |
| 76 | +
|
| 77 | + Note: |
| 78 | + This should not be used normally, you should test if a EV charger |
| 79 | + [`isinstance`][] of a concrete component class instead. |
| 80 | +
|
| 81 | + It is only provided for using with a newer version of the API where the client |
| 82 | + doesn't know about the new EV charger type yet (i.e. for use with |
| 83 | + [`UnrecognizedEvCharger`][frequenz.client.microgrid.component.UnrecognizedEvCharger]). |
| 84 | + """ |
| 85 | + |
| 86 | + |
| 87 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 88 | +class AcEvCharger(EvCharger): |
| 89 | + """An EV charger that supports AC charging only.""" |
| 90 | + |
| 91 | + type: Literal[EvChargerType.AC] = EvChargerType.AC |
| 92 | + """The type of this EV charger. |
| 93 | +
|
| 94 | + Note: |
| 95 | + This should not be used normally, you should test if a EV charger |
| 96 | + [`isinstance`][] of a concrete component class instead. |
| 97 | +
|
| 98 | + It is only provided for using with a newer version of the API where the client |
| 99 | + doesn't know about the new EV charger type yet (i.e. for use with |
| 100 | + [`UnrecognizedEvCharger`][frequenz.client.microgrid.component.UnrecognizedEvCharger]). |
| 101 | + """ |
| 102 | + |
| 103 | + |
| 104 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 105 | +class DcEvCharger(EvCharger): |
| 106 | + """An EV charger that supports DC charging only.""" |
| 107 | + |
| 108 | + type: Literal[EvChargerType.DC] = EvChargerType.DC |
| 109 | + """The type of this EV charger. |
| 110 | +
|
| 111 | + Note: |
| 112 | + This should not be used normally, you should test if a EV charger |
| 113 | + [`isinstance`][] of a concrete component class instead. |
| 114 | +
|
| 115 | + It is only provided for using with a newer version of the API where the client |
| 116 | + doesn't know about the new EV charger type yet (i.e. for use with |
| 117 | + [`UnrecognizedEvCharger`][frequenz.client.microgrid.component.UnrecognizedEvCharger]). |
| 118 | + """ |
| 119 | + |
| 120 | + |
| 121 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 122 | +class HybridEvCharger(EvCharger): |
| 123 | + """An EV charger that supports both AC and DC charging.""" |
| 124 | + |
| 125 | + type: Literal[EvChargerType.HYBRID] = EvChargerType.HYBRID |
| 126 | + """The type of this EV charger. |
| 127 | +
|
| 128 | + Note: |
| 129 | + This should not be used normally, you should test if a EV charger |
| 130 | + [`isinstance`][] of a concrete component class instead. |
| 131 | +
|
| 132 | + It is only provided for using with a newer version of the API where the client |
| 133 | + doesn't know about the new EV charger type yet (i.e. for use with |
| 134 | + [`UnrecognizedEvCharger`][frequenz.client.microgrid.component.UnrecognizedEvCharger]). |
| 135 | + """ |
| 136 | + |
| 137 | + |
| 138 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 139 | +class UnrecognizedEvCharger(EvCharger): |
| 140 | + """An EV charger of an unrecognized type.""" |
| 141 | + |
| 142 | + type: int |
| 143 | + """The unrecognized type of this EV charger.""" |
| 144 | + |
| 145 | + |
| 146 | +EvChargerTypes: TypeAlias = ( |
| 147 | + UnspecifiedEvCharger |
| 148 | + | AcEvCharger |
| 149 | + | DcEvCharger |
| 150 | + | HybridEvCharger |
| 151 | + | UnrecognizedEvCharger |
| 152 | +) |
| 153 | +"""All possible EV charger types.""" |
0 commit comments