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