Skip to content

Commit 4af5e84

Browse files
authored
Add supported features to device client (#8)
1 parent 1920fd8 commit 4af5e84

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

letpot/converters.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from aiomqtt.types import PayloadType
99

1010
from letpot.exceptions import LetPotException
11-
from letpot.models import LetPotDeviceStatus
11+
from letpot.models import DeviceFeature, LetPotDeviceStatus
1212

1313
_LOGGER = logging.getLogger(__name__)
1414

@@ -40,6 +40,10 @@ def supports_type(device_type: str) -> bool:
4040
def get_device_model(self) -> tuple[str, str] | None:
4141
"""Returns the device model name and code."""
4242

43+
@abstractmethod
44+
def supported_features(self) -> DeviceFeature:
45+
"""Returns the device supported feature(s)."""
46+
4347
@abstractmethod
4448
def get_current_status_message(self) -> list[int]:
4549
"""Returns the message content for getting the current device status."""
@@ -91,6 +95,12 @@ def get_device_model(self) -> tuple[str, str] | None:
9195
else:
9296
return None
9397

98+
def supported_features(self) -> DeviceFeature:
99+
features = DeviceFeature.PUMP_STATUS
100+
if self._device_type in ["LPH21", "LPH31"]:
101+
features |= DeviceFeature.LIGHT_BRIGHTNESS_LOW_HIGH
102+
return features
103+
94104
def get_current_status_message(self) -> list[int]:
95105
return [97, 1]
96106

@@ -157,6 +167,9 @@ def get_device_model(self) -> tuple[str, str] | None:
157167
else:
158168
return None
159169

170+
def supported_features(self) -> DeviceFeature:
171+
return DeviceFeature(0)
172+
160173
def get_current_status_message(self) -> list[int]:
161174
return [11, 1]
162175

@@ -212,6 +225,17 @@ def supports_type(device_type: str) -> bool:
212225
def get_device_model(self) -> tuple[str, str] | None:
213226
return MODEL_MAX
214227

228+
def supported_features(self) -> DeviceFeature:
229+
features = (
230+
DeviceFeature.LIGHT_BRIGHTNESS_LEVELS
231+
| DeviceFeature.PUMP_AUTO
232+
| DeviceFeature.TEMPERATURE
233+
| DeviceFeature.WATER_LEVEL
234+
)
235+
if self._device_type != "LPH60":
236+
features |= DeviceFeature.NUTRIENT_BUTTON
237+
return features
238+
215239
def get_current_status_message(self) -> list[int]:
216240
return [13, 1]
217241

@@ -278,6 +302,16 @@ def supports_type(device_type: str) -> bool:
278302
def get_device_model(self) -> tuple[str, str] | None:
279303
return MODEL_MAX
280304

305+
def supported_features(self) -> DeviceFeature:
306+
return (
307+
DeviceFeature.LIGHT_BRIGHTNESS_LEVELS
308+
| DeviceFeature.NUTRIENT_BUTTON
309+
| DeviceFeature.PUMP_AUTO
310+
| DeviceFeature.PUMP_STATUS
311+
| DeviceFeature.TEMPERATURE
312+
| DeviceFeature.WATER_LEVEL
313+
)
314+
281315
def get_current_status_message(self) -> list[int]:
282316
return [101, 1]
283317

letpot/deviceclient.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from letpot.converters import CONVERTERS, LetPotDeviceConverter
1515
from letpot.exceptions import LetPotAuthenticationException, LetPotException
16-
from letpot.models import AuthenticationInfo, LetPotDeviceStatus
16+
from letpot.models import AuthenticationInfo, DeviceFeature, LetPotDeviceStatus
1717

1818
_LOGGER = logging.getLogger(__name__)
1919

@@ -44,6 +44,7 @@ class LetPotDeviceClient:
4444
_email: str
4545
_device_serial: str
4646
device_type: str
47+
device_features: DeviceFeature = DeviceFeature(0)
4748
device_model_name: str | None = None
4849
device_model_code: str | None = None
4950

@@ -61,6 +62,7 @@ def __init__(self, info: AuthenticationInfo, device_serial: str) -> None:
6162
for converter in CONVERTERS:
6263
if converter.supports_type(device_type):
6364
self._converter = converter(device_type)
65+
self.device_features = self._converter.supported_features()
6466
device_model = self._converter.get_device_model()
6567
if device_model is not None:
6668
self.device_model_name = device_model[0]

letpot/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
from dataclasses import dataclass
44
from datetime import time
5+
from enum import IntFlag, auto
56
import time as systime
67

78

9+
class DeviceFeature(IntFlag):
10+
"""Features that a LetPot device can support."""
11+
12+
LIGHT_BRIGHTNESS_LOW_HIGH = auto()
13+
LIGHT_BRIGHTNESS_LEVELS = auto()
14+
NUTRIENT_BUTTON = auto()
15+
PUMP_AUTO = auto()
16+
PUMP_STATUS = auto()
17+
TEMPERATURE = auto()
18+
WATER_LEVEL = auto()
19+
20+
821
@dataclass
922
class AuthenticationInfo:
1023
"""Authentication info model."""

0 commit comments

Comments
 (0)