Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test covering all v2.0.1 datatypes and enums #684

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion ocpp/v201/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class IdTokenType:
"""

id_token: str
type: enums.IdTokenType
type: enums.IdTokenEnumType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's the value add of renaming enums

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compliance with the OCPP specs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross Checked this. This makes me question the whether the rest of the enums and datatypes are compliant or not. Will take a look at this soon.

Copy link
Contributor Author

@ajmirsky ajmirsky Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a double check when I came across this one and all of the others seemed compliant. But another set of eyes is always appreciated!

additional_info: Optional[List[AdditionalInfoType]] = None


Expand Down
32 changes: 30 additions & 2 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 @@ -721,7 +741,7 @@ class HashAlgorithmType(StrEnum):
sha512 = "SHA512"


class IdTokenType(StrEnum):
class IdTokenEnumType(StrEnum):
"""
Allowable values of the IdTokenType field.
"""
Expand All @@ -736,6 +756,9 @@ class IdTokenType(StrEnum):
no_authorization = "NoAuthorization"


IdTokenType = DeprecatedEnumWrapper(IdTokenEnumType, "IdTokenType")


class InstallCertificateStatusType(StrEnum):
"""
InstallCertificateStatusEnumType is used by
Expand Down Expand Up @@ -1321,7 +1344,7 @@ class VPNType(StrEnum):
# DataTypes


class UnitOfMeasureType(StrEnum):
class StandardizedUnitsOfMeasureType(StrEnum):
"""
Allowable values of the optional "unit" field of a Value element, as used
in MeterValues.req and StopTransaction.req messages. Default value of
Expand Down Expand Up @@ -1364,6 +1387,11 @@ class UnitOfMeasureType(StrEnum):
k = "K"


UnitOfMeasureType = DeprecatedEnumWrapper(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it worth the effort. Have these enums been part of any stable release.
Considering rc versions as API stable is unusual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm mixed on this one.

correct, there has been no official stable release.

But... since 0.26.0 has been in the wild for the past year, there are definitely people who are using/depending on the library

I leaned towards usability for the community in this case but I could be convinced otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerome-benoit actually, given that these OCPP 2.0 files are included in this library's 1.0 release (on pypi), I think it's better to be safe. I don't think the project has made it clear if the library's release version is tied to the OCPP version or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library version is totally independent from the OCPP version supported.

StandardizedUnitsOfMeasureType, "UnitOfMeasureType"
)


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