Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion letpot/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiomqtt.types import PayloadType

from letpot.exceptions import LetPotException
from letpot.models import LetPotDeviceStatus
from letpot.models import DeviceFeature, LetPotDeviceStatus

_LOGGER = logging.getLogger(__name__)

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

@abstractmethod
def supported_features(self) -> DeviceFeature:
"""Returns the device supported feature(s)."""

@abstractmethod
def get_current_status_message(self) -> list[int]:
"""Returns the message content for getting the current device status."""
Expand Down Expand Up @@ -91,6 +95,12 @@ def get_device_model(self) -> tuple[str, str] | None:
else:
return None

def supported_features(self) -> DeviceFeature:
features = DeviceFeature.PUMP_STATUS
if self._device_type in ["LPH21", "LPH31"]:
features |= DeviceFeature.LIGHT_BRIGHTNESS_LOW_HIGH
return features

def get_current_status_message(self) -> list[int]:
return [97, 1]

Expand Down Expand Up @@ -157,6 +167,9 @@ def get_device_model(self) -> tuple[str, str] | None:
else:
return None

def supported_features(self) -> DeviceFeature:
return DeviceFeature(0)

def get_current_status_message(self) -> list[int]:
return [11, 1]

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

def supported_features(self) -> DeviceFeature:
features = (
DeviceFeature.LIGHT_BRIGHTNESS_LEVELS
| DeviceFeature.PUMP_AUTO
| DeviceFeature.TEMPERATURE
| DeviceFeature.WATER_LEVEL
)
if self._device_type != "LPH60":
features |= DeviceFeature.NUTRIENT_BUTTON
return features

def get_current_status_message(self) -> list[int]:
return [13, 1]

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

def supported_features(self) -> DeviceFeature:
return (
DeviceFeature.LIGHT_BRIGHTNESS_LEVELS
| DeviceFeature.NUTRIENT_BUTTON
| DeviceFeature.PUMP_AUTO
| DeviceFeature.PUMP_STATUS
| DeviceFeature.TEMPERATURE
| DeviceFeature.WATER_LEVEL
)

def get_current_status_message(self) -> list[int]:
return [101, 1]

Expand Down
4 changes: 3 additions & 1 deletion letpot/deviceclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from letpot.converters import CONVERTERS, LetPotDeviceConverter
from letpot.exceptions import LetPotAuthenticationException, LetPotException
from letpot.models import AuthenticationInfo, LetPotDeviceStatus
from letpot.models import AuthenticationInfo, DeviceFeature, LetPotDeviceStatus

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,6 +44,7 @@ class LetPotDeviceClient:
_email: str
_device_serial: str
device_type: str
device_features: DeviceFeature = DeviceFeature(0)
device_model_name: str | None = None
device_model_code: str | None = None

Expand All @@ -61,6 +62,7 @@ def __init__(self, info: AuthenticationInfo, device_serial: str) -> None:
for converter in CONVERTERS:
if converter.supports_type(device_type):
self._converter = converter(device_type)
self.device_features = self._converter.supported_features()
device_model = self._converter.get_device_model()
if device_model is not None:
self.device_model_name = device_model[0]
Expand Down
13 changes: 13 additions & 0 deletions letpot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

from dataclasses import dataclass
from datetime import time
from enum import IntFlag, auto
import time as systime


class DeviceFeature(IntFlag):
"""Features that a LetPot device can support."""

LIGHT_BRIGHTNESS_LOW_HIGH = auto()
LIGHT_BRIGHTNESS_LEVELS = auto()
NUTRIENT_BUTTON = auto()
PUMP_AUTO = auto()
PUMP_STATUS = auto()
TEMPERATURE = auto()
WATER_LEVEL = auto()


@dataclass
class AuthenticationInfo:
"""Authentication info model."""
Expand Down