Skip to content

Commit

Permalink
Support decimal numbers as floats (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindwe authored Aug 29, 2024
1 parent b8bfb2d commit ca761a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions connectlife/appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions connectlife/tests/test_appliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit ca761a2

Please sign in to comment.