fix: float value precision (#1485)

This commit is contained in:
Li Shuzhen
2025-11-07 10:19:01 +08:00
committed by GitHub
parent 1ec325c9c7
commit a1a216aea6

View File

@@ -66,7 +66,7 @@ class MIoTSpecValueRange:
"""MIoT SPEC value range class.""" """MIoT SPEC value range class."""
min_: int min_: int
max_: int max_: int
step: int step: int | float
def __init__(self, value_range: Union[dict, list]) -> None: def __init__(self, value_range: Union[dict, list]) -> None:
if isinstance(value_range, dict): if isinstance(value_range, dict):
@@ -567,9 +567,8 @@ class MIoTSpecProperty(_MIoTSpecBase):
return return
self._value_range = MIoTSpecValueRange(value_range=value) self._value_range = MIoTSpecValueRange(value_range=value)
if isinstance(value, list): if isinstance(value, list):
self.precision = len(str( step_: str = format(value[2], '.10f').rstrip('0').rstrip('.')
value[2]).split('.')[1].rstrip('0')) if '.' in str( self.precision = len(step_.split('.')[1]) if '.' in step_ else 0
value[2]) else 0
@property @property
def value_list(self) -> Optional[MIoTSpecValueList]: def value_list(self) -> Optional[MIoTSpecValueList]: