From cabc7eaa56732116f34dd7254db4466c306ca5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Matheson=20Wergeland?= Date: Thu, 29 Aug 2024 21:07:18 +0200 Subject: [PATCH] Support decimal numbers as floats. --- connectlife/appliance.py | 6 ++++-- connectlife/tests/test_appliance.py | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/connectlife/appliance.py b/connectlife/appliance.py index bef13d5..629541b 100644 --- a/connectlife/appliance.py +++ b/connectlife/appliance.py @@ -116,7 +116,7 @@ def room_name(self) -> str: return self._room_name @property - def status_list(self) -> Dict[str, str | int | dt.datetime]: + def status_list(self) -> Dict[str, str | int | float | dt.datetime]: return self._status_list @property @@ -140,7 +140,9 @@ def device_type(self) -> DeviceType: return self._device_type -def convert(value: str) -> int | str | dt.datetime: +def convert(value: str | float) -> float | int | str | dt.datetime: + if isinstance(value, float): + return value try: return int(value) except ValueError: diff --git a/connectlife/tests/test_appliance.py b/connectlife/tests/test_appliance.py index 5511b04..b321cd3 100644 --- a/connectlife/tests/test_appliance.py +++ b/connectlife/tests/test_appliance.py @@ -11,6 +11,9 @@ def test_convert_int(self): self.assertEqual(0, convert("0")) self.assertEqual(-1, convert("-1")) + def test_convert_float(self): + self.assertEqual(0.67, convert(0.67)) + def test_convert_datetime(self): self.assertEqual( dt.datetime(2024, 9, 12, 21, 25, 33, tzinfo=dt.UTC),