Skip to content

Commit af0d1bb

Browse files
authored
Temperature unit improvements and feature (#11)
Use enum for temperature unit, setter for unit
1 parent 7754d3f commit af0d1bb

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

letpot/converters.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from aiomqtt.types import PayloadType
99

1010
from letpot.exceptions import LetPotException
11-
from letpot.models import DeviceFeature, LetPotDeviceErrors, LetPotDeviceStatus
11+
from letpot.models import (
12+
DeviceFeature,
13+
TemperatureUnit,
14+
LetPotDeviceErrors,
15+
LetPotDeviceStatus,
16+
)
1217

1318
_LOGGER = logging.getLogger(__name__)
1419

@@ -243,6 +248,7 @@ def supported_features(self) -> DeviceFeature:
243248
DeviceFeature.LIGHT_BRIGHTNESS_LEVELS
244249
| DeviceFeature.PUMP_AUTO
245250
| DeviceFeature.TEMPERATURE
251+
| DeviceFeature.TEMPERATURE_SET_UNIT
246252
| DeviceFeature.WATER_LEVEL
247253
)
248254
if self._device_type != "LPH60":
@@ -270,7 +276,7 @@ def get_update_status_message(self, status: LetPotDeviceStatus) -> list[int]:
270276
if status.light_brightness is not None
271277
else 0,
272278
status.light_brightness % 256 if status.light_brightness is not None else 0,
273-
status.temperature_unit if status.temperature_unit is not None else 0,
279+
1 if status.temperature_unit is TemperatureUnit.CELSIUS else 0,
274280
1 if status.system_sound is True else 0,
275281
1 if status.pump_nutrient is True else 0,
276282
]
@@ -299,7 +305,7 @@ def convert_hex_to_status(self, message: PayloadType) -> LetPotDeviceStatus | No
299305
low_nutrients=True if data[7] & 1 else False,
300306
refill_error=True if data[7] & 4 else False,
301307
),
302-
temperature_unit=data[24],
308+
temperature_unit=TemperatureUnit(data[24]),
303309
temperature_value=256 * data[22] + data[23],
304310
water_level=256 * data[20] + data[21],
305311
water_mode=data[17],
@@ -376,7 +382,7 @@ def convert_hex_to_status(self, message: PayloadType) -> LetPotDeviceStatus | No
376382
low_nutrients=True if data[7] & 1 else False,
377383
refill_error=True if data[7] & 4 else False,
378384
),
379-
temperature_unit=data[24],
385+
temperature_unit=TemperatureUnit(data[24]),
380386
temperature_value=256 * data[22] + data[23],
381387
water_level=256 * data[20] + data[21],
382388
water_mode=data[17],

letpot/deviceclient.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
LetPotConnectionException,
1818
LetPotException,
1919
)
20-
from letpot.models import AuthenticationInfo, DeviceFeature, LetPotDeviceStatus
20+
from letpot.models import (
21+
AuthenticationInfo,
22+
DeviceFeature,
23+
TemperatureUnit,
24+
LetPotDeviceStatus,
25+
)
2126

2227
_LOGGER = logging.getLogger(__name__)
2328

@@ -326,6 +331,11 @@ async def set_sound(self, on: bool) -> None:
326331
status = dataclasses.replace(self._get_publish_status(), system_sound=on)
327332
await self._publish_status(status)
328333

334+
async def set_temperature_unit(self, unit: TemperatureUnit) -> None:
335+
"""Set the temperature unit for this device (Celsius/Fahrenheit)."""
336+
status = dataclasses.replace(self._get_publish_status(), temperature_unit=unit)
337+
await self._publish_status(status)
338+
329339
async def set_water_mode(self, on: bool) -> None:
330340
"""Set the automatic water/nutrient mode for this device (on/off)."""
331341
status = dataclasses.replace(

letpot/models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from dataclasses import dataclass
44
from datetime import time
5-
from enum import IntFlag, auto
5+
from enum import IntEnum, IntFlag, auto
66
import time as systime
77

88

@@ -15,9 +15,17 @@ class DeviceFeature(IntFlag):
1515
PUMP_AUTO = auto()
1616
PUMP_STATUS = auto()
1717
TEMPERATURE = auto()
18+
TEMPERATURE_SET_UNIT = auto()
1819
WATER_LEVEL = auto()
1920

2021

22+
class TemperatureUnit(IntEnum):
23+
"""Device temperate sensor/display unit."""
24+
25+
FAHRENHEIT = 0
26+
CELSIUS = 1
27+
28+
2129
@dataclass
2230
class AuthenticationInfo:
2331
"""Authentication info model."""
@@ -73,7 +81,7 @@ class LetPotDeviceStatus:
7381
raw: list[int]
7482
system_on: bool
7583
system_sound: bool | None
76-
temperature_unit: int | None = None
84+
temperature_unit: TemperatureUnit | None = None
7785
temperature_value: int | None = None
7886
water_mode: int | None = None
7987
water_level: int | None = None

0 commit comments

Comments
 (0)