Skip to content

Commit

Permalink
changed physical value restrictions after comments by Marc
Browse files Browse the repository at this point in the history
  • Loading branch information
tropxy committed Dec 28, 2021
1 parent 22f3dd6 commit dad9e9e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 0 additions & 1 deletion iso15118/shared/messages/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions iso15118/shared/messages/iso15118_2/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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'
Expand Down

0 comments on commit dad9e9e

Please sign in to comment.