From dad9e9eee0cb071f46e530481b1ef2b2d42f426c Mon Sep 17 00:00:00 2001 From: tropxy Date: Tue, 28 Dec 2021 13:52:37 +0000 Subject: [PATCH] changed physical value restrictions after comments by Marc --- iso15118/shared/messages/enums.py | 1 - iso15118/shared/messages/iso15118_2/datatypes.py | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iso15118/shared/messages/enums.py b/iso15118/shared/messages/enums.py index a98535979..776421801 100644 --- a/iso15118/shared/messages/enums.py +++ b/iso15118/shared/messages/enums.py @@ -11,7 +11,6 @@ UINT_32_MAX = 2**32 - 1 INT_16_MAX = 2**15 - 1 -INT_16_MIN = -2**15 class AuthEnum(str, Enum): diff --git a/iso15118/shared/messages/iso15118_2/datatypes.py b/iso15118/shared/messages/iso15118_2/datatypes.py index cc3bcc401..a8773c80f 100644 --- a/iso15118/shared/messages/iso15118_2/datatypes.py +++ b/iso15118/shared/messages/iso15118_2/datatypes.py @@ -52,8 +52,9 @@ class PhysicalValue(BaseModel): that can go below that value. """ _max_limit: int = 0 - # XSD int16 range [-32768, 32767] - value: int = Field(..., ge=INT_16_MIN, le=INT_16_MAX, alias="Value") + # XSD int16 range is [-32768, 32767], but there are no physical types which + # have values below 0, so we enforce the limit here. + value: int = Field(..., ge=0, le=INT_16_MAX, alias="Value") # XSD type byte with value range [-3..3] multiplier: int = Field(..., ge=-3, le=3, alias="Multiplier") @@ -68,7 +69,7 @@ def validate_value_range(cls, values): value = values.get("value") multiplier = values.get("multiplier") calculated_value = value * 10 ** multiplier - if calculated_value > cls._max_limit or calculated_value < 0: + if calculated_value > cls._max_limit: raise ValueError( f'{cls.__name__[2:]} value limit exceeded: {calculated_value} \n' f'Max: {cls._max_limit} \n'