Deprecate ElectricalComponentCategory and XxxType enums#222
Conversation
|
Converting to draft as it is based on #221. |
|
The But well, is a one time thing, adding more components should be easy even if the code is scary. |
71ce484 to
5bac2c1
Compare
ElectricalComponentCategory and XxxType enumsElectricalComponentCategory and XxxType enums
0cde2f6 to
f3c89a7
Compare
This enum and file should have been removed by frequenz-floss#220 but it was forgotten. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Add these four concrete leaf electrical components: `Plc`, `StaticTransferSwitch`, `UninterruptiblePowerSupply` and `CapacitorBank`. Follow the same shape as the other simple leaves (e.g. `Chp`, `Hvac`): each one only fixes its `category` default and adds no extra fields. They are exported from the package and added to the `ElectricalComponentTypes` union, so they become part of the public type surface. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
This got unordered when `SolarInverter` was renamed to `PvInverter`. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The proto dispatcher now maps the PLC, static transfer switch, uninterruptible power supply and capacitor bank categories to their dedicated `Plc`, `StaticTransferSwitch`, `UninterruptiblePowerSupply` and `CapacitorBank` classes. Until now these four categories were added to the enum but were converted to `UnrecognizedElectricalComponent` as the classes were never added. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
These converters allow mapping the `ElectricalComponent` class hierarchy to protobuf `(category, type)` enum tuples, to be able to send the protobuf enum values to the protocol without the need to expose the enums themselves, avoiding having two ways to express the same on the high-level wrappers. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The type alias was using `ProblematicElectricalComponentTypes` but that also includes problematic batteries, EV chargers and inverters, which are included by BatteryTypes, EvChargerTypes and InverterTypes too. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The next commit will deprecate the enums, so we need to deprecate the attributes using them. To do this we rename attributes to make them private and to represent them with raw `int`s, and add a deprecated property to access them returning the deprecated enum, so we can silence the internal deprecation message when we do the conversion. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
f3c89a7 to
8f1320d
Compare
`ElectricalComponentCategory`, `BatteryType`, `InverterType` and `EvChargerType` are all replaced by the electrical component class hierarchy plus the typed `electrical_component_class_to_proto()` / `electrical_component_class_from_proto()` converters added earlier in this phase. Callers should use `isinstance` checks on concrete classes (e.g. `LiIonBattery`, `PvInverter`, `AcEvCharger`) instead of comparing to a category/type enum member. Mark each enum and its members as deprecated: * Each class switches from `enum.Enum` to `frequenz.core.enum.Enum` and gains `@typing_extensions.deprecated(...)` so calling `XxxType(value)` or `XxxType['NAME']` warns. * Every member is wrapped in `core_enum.deprecated_member(value, msg)` so attribute and subscript lookups warn too. Iteration is left warning-free (a verified property of `frequenz.core.enum`) so the parity tests can list all member names without spurious noise. Mark the matching `*_from_proto` / `*_to_proto` converter pairs as deprecated too. Their bodies wrap the inner enum lookup or `enum_from_proto()` call in `warnings.catch_warnings()` with a `DeprecationWarning` filter so the converter itself only emits the function-level warning the caller sees; the internal enum-member access stays silent. The parity test subclasses pin `deprecated_members = frozenset(m.name for m in <Enum>)`, which makes `EnumParityTest._maybe_ignore_deprecation` silence the parity checks while `test_deprecated_members_warn` keeps asserting each member still warns. A new `test_enum_deprecation.py` locks in the public contract: member access warns, the deprecated converters warn, and `electrical_component_class_to_proto()` (the replacement) stays warning-clean. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
The previous commit introduced some mappings that were useful not only for the new class converters but are also useful for the existing message converters. We reuse them and remove the old similar mapping we had for the message converter. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
8f1320d to
559a364
Compare
|
Ready for review. |
|
Maybe it is a good idea to look at the release notes changes first to have a better idea of where this is going. |
Marenz
left a comment
There was a problem hiding this comment.
Clean deprecation with thorough tests, proper warning hygiene, and a clear migration path. The class-hierarchy approach is a better fit for the domain than enum switches. The 11 @overload signatures are verbose but necessary for mypy — worth the type safety.
…nz-floss#233) The earlier deprecation PR frequenz-floss#222 deprecated `ElectricalComponentCategory` and the `XxxType` enums and `.category` and `.type` attributes, but most of those symbols were yet unreleased, so deprecating them makes no sense. This PR remove the unreleased deprecated symbols: - `ElectricalComponent.category` and `(Battery|Inverter|EvCharger).type` attributes, except for `Unrecognized*` classes and `MismatchesCategoryElectricalComponent`, as they carry the raw protobuf value that could be used for forward compatibility. - `BatteryType`, `InverterType`, `EvChargerType` enums, and their protobuf conversion functions. `ElectricalComponentCategory` and its proto converters are kept as deprecated because they were already released and still present in v0.4.0. Part of frequenz-floss#223.
This PR removes the electrical component category and type enums and leaves the
ElectricalComponentclass hierarchy as the canonical representation of electrical components and single source of truth for electrical component types.It basically:
ElectricalComponentCategoryandElectricalComponentTypewrapper enums.BatteryType,EvChargerTypeandInverterTypewrapper enums.categoryof theElectricalComponentclass.typeforBattery,EvChargerandInverterclasses.electrical_component_class_from_proto()andelectrical_component_class_to_proto()functions to convert between theElectricalComponentclass hierarchy and the protobuf enum representation of electrical component categiries and types so client implementers have an easy way to replace the deprecated wrapper enums with the new class hierarchy.It also adds some missing electrical component classes so they are not wrapped as unrecognized electrical components.
Part of #223.