|
| 1 | +# License: MIT |
| 2 | +# Copyright © 2024 Frequenz Energy-as-a-Service GmbH |
| 3 | + |
| 4 | +"""Inverter 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 InverterType(enum.Enum): |
| 20 | + """The known types of inverters.""" |
| 21 | + |
| 22 | + UNSPECIFIED = electrical_components_pb2.INVERTER_TYPE_UNSPECIFIED |
| 23 | + """The type of the inverter is unspecified.""" |
| 24 | + |
| 25 | + BATTERY = electrical_components_pb2.INVERTER_TYPE_BATTERY |
| 26 | + """The inverter is a battery inverter.""" |
| 27 | + |
| 28 | + SOLAR = electrical_components_pb2.INVERTER_TYPE_PV |
| 29 | + """The inverter is a solar inverter.""" |
| 30 | + |
| 31 | + HYBRID = electrical_components_pb2.INVERTER_TYPE_HYBRID |
| 32 | + """The inverter is a hybrid inverter.""" |
| 33 | + |
| 34 | + |
| 35 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 36 | +class Inverter(ElectricalComponent): |
| 37 | + """An abstract inverter electrical component.""" |
| 38 | + |
| 39 | + category: Literal[ElectricalComponentCategory.INVERTER] = ( |
| 40 | + ElectricalComponentCategory.INVERTER |
| 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 electrical component 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 level |
| 51 | + code needs to know the category of an electrical component. |
| 52 | + """ |
| 53 | + |
| 54 | + type: InverterType | int |
| 55 | + """The type of this inverter. |
| 56 | +
|
| 57 | + Note: |
| 58 | + This should not be used normally, you should test if a inverter |
| 59 | + [`isinstance`][] of a concrete inverter 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 inverter type yet (i.e. for use with |
| 63 | + [`UnrecognizedInverter`][...UnrecognizedInverter]). |
| 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 Inverter: |
| 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 UnspecifiedInverter(Inverter): |
| 76 | + """An inverter of an unspecified type.""" |
| 77 | + |
| 78 | + type: Literal[InverterType.UNSPECIFIED] = InverterType.UNSPECIFIED |
| 79 | + """The type of this inverter. |
| 80 | +
|
| 81 | + Note: |
| 82 | + This should not be used normally, you should test if a inverter |
| 83 | + [`isinstance`][] of a concrete inverter 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 inverter type yet (i.e. for use with |
| 87 | + [`UnrecognizedInverter`][...UnrecognizedInverter]). |
| 88 | + """ |
| 89 | + |
| 90 | + |
| 91 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 92 | +class BatteryInverter(Inverter): |
| 93 | + """A battery inverter.""" |
| 94 | + |
| 95 | + type: Literal[InverterType.BATTERY] = InverterType.BATTERY |
| 96 | + """The type of this inverter. |
| 97 | +
|
| 98 | + Note: |
| 99 | + This should not be used normally, you should test if a inverter |
| 100 | + [`isinstance`][] of a concrete inverter 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 inverter type yet (i.e. for use with |
| 104 | + [`UnrecognizedInverter`][...UnrecognizedInverter]). |
| 105 | + """ |
| 106 | + |
| 107 | + |
| 108 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 109 | +class SolarInverter(Inverter): |
| 110 | + """A solar inverter.""" |
| 111 | + |
| 112 | + type: Literal[InverterType.SOLAR] = InverterType.SOLAR |
| 113 | + """The type of this inverter. |
| 114 | +
|
| 115 | + Note: |
| 116 | + This should not be used normally, you should test if a inverter |
| 117 | + [`isinstance`][] of a concrete inverter 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 inverter type yet (i.e. for use with |
| 121 | + [`UnrecognizedInverter`][...UnrecognizedInverter]). |
| 122 | + """ |
| 123 | + |
| 124 | + |
| 125 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 126 | +class HybridInverter(Inverter): |
| 127 | + """A hybrid inverter.""" |
| 128 | + |
| 129 | + type: Literal[InverterType.HYBRID] = InverterType.HYBRID |
| 130 | + """The type of this inverter. |
| 131 | +
|
| 132 | + Note: |
| 133 | + This should not be used normally, you should test if a inverter |
| 134 | + [`isinstance`][] of a concrete inverter 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 inverter type yet (i.e. for use with |
| 138 | + [`UnrecognizedInverter`][...UnrecognizedInverter]). |
| 139 | + """ |
| 140 | + |
| 141 | + |
| 142 | +@dataclasses.dataclass(frozen=True, kw_only=True) |
| 143 | +class UnrecognizedInverter(Inverter): |
| 144 | + """An inverter of an unrecognized type.""" |
| 145 | + |
| 146 | + type: int |
| 147 | + """The unrecognized type of this inverter.""" |
| 148 | + |
| 149 | + |
| 150 | +InverterTypes: TypeAlias = ( |
| 151 | + UnspecifiedInverter |
| 152 | + | BatteryInverter |
| 153 | + | SolarInverter |
| 154 | + | HybridInverter |
| 155 | + | UnrecognizedInverter |
| 156 | +) |
| 157 | +"""All possible inverter types.""" |
0 commit comments