Skip to content

Commit

Permalink
adding deprecation warnings for enums IdTokenType and UnitOfMeasureTy…
Browse files Browse the repository at this point in the history
…pe. eliminates breaking change.
  • Loading branch information
ajmirsky committed Nov 26, 2024
1 parent ef2907a commit e53d73c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ocpp/v201/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ class StrEnum(str, Enum): # pragma: no cover
pass # pragma: no cover


class DeprecatedEnumWrapper:
"""
Since enums can't be subclassed in order to add a deprecation warning,
this class is included to help warn users of deprecated enums.
"""

def __init__(self, enum_class, alias_name):
self.enum_class = enum_class
self.alias_name = alias_name

def __getattr__(self, name):
warn(
(
f"Enum '{self.alias_name}' is deprecated, "
+ "instead use '{self.enum_class.__name__}'"
)
)
return getattr(self.enum_class, name)


class Action(StrEnum):
"""An Action is a required part of a Call message."""

Expand Down Expand Up @@ -736,6 +756,9 @@ class IdTokenEnumType(StrEnum):
no_authorization = "NoAuthorization"


IdTokenType = DeprecatedEnumWrapper(IdTokenEnumType, "IdTokenType")


class InstallCertificateStatusType(StrEnum):
"""
InstallCertificateStatusEnumType is used by
Expand Down Expand Up @@ -1364,6 +1387,11 @@ class StandardizedUnitsOfMeasureType(StrEnum):
k = "K"


UnitOfMeasureType = DeprecatedEnumWrapper(
StandardizedUnitsOfMeasureType, "UnitOfMeasureType"
)


class StatusInfoReasonType(StrEnum):
"""
Standardized reason codes for StatusInfo defined in Appendix 5. v1.3
Expand Down

0 comments on commit e53d73c

Please sign in to comment.