Skip to content

Commit

Permalink
feat: more improvements (#26)
Browse files Browse the repository at this point in the history
* feat: expose proper list of available light shows, ref: #23

* fix: telemetry parsing errors
  • Loading branch information
cryptk committed May 30, 2023
1 parent 0421099 commit 62a4af4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
10 changes: 10 additions & 0 deletions pyomnilogic_local/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class OmniLogicException(Exception):
pass


class OmniTimeoutException(OmniLogicException):
pass


class OmniParsingException(OmniLogicException):
pass
10 changes: 7 additions & 3 deletions pyomnilogic_local/models/mspconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
import sys
from typing import Any, Literal, TypeAlias

from ..types import OmniParsingException

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


from pydantic import BaseModel, Field, ValidationError
from xmltodict import parse as xml_parse

from ..exceptions import OmniParsingException
from ..types import (
BodyOfWaterType,
ColorLogicLightType,
ColorLogicShow,
FilterType,
HeaterType,
OmniType,
Expand Down Expand Up @@ -143,6 +142,11 @@ class MSPColorLogicLight(OmniBase):
omni_type: OmniType = OmniType.CL_LIGHT
type: ColorLogicLightType | str = Field(alias="Type")
v2_active: Literal["yes", "no"] | None = Field(alias="V2-Active")
effects: list[ColorLogicShow] | None

def __init__(self, **data: Any) -> None:
super().__init__(**data)
self.effects = list(ColorLogicShow) if self.v2_active == "yes" else [show for show in ColorLogicShow if show.value <= 16]


class MSPBoW(OmniBase):
Expand Down
10 changes: 6 additions & 4 deletions pyomnilogic_local/models/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pydantic import BaseModel, Field, ValidationError
from xmltodict import parse as xml_parse

from ..exceptions import OmniParsingException
from ..types import (
BackyardState,
ChlorinatorOperatingMode,
Expand All @@ -17,7 +18,6 @@
FilterWhyOn,
HeaterMode,
HeaterState,
OmniParsingException,
OmniType,
PumpState,
RelayState,
Expand Down Expand Up @@ -47,8 +47,9 @@ class TelemetryBackyard(BaseModel):
status_version: int = Field(alias="@statusVersion")
air_temp: int = Field(alias="@airTemp")
state: BackyardState | int = Field(alias="@state")
config_checksum: int = Field(alias="@ConfigChksum")
msp_version: str = Field(alias="@mspVersion")
# The below two fields are only available for telemetry with a status_version >= 11
config_checksum: int | None = Field(alias="@ConfigChksum")
msp_version: str | None = Field(alias="@mspVersion")


class TelemetryBoW(BaseModel):
Expand Down Expand Up @@ -115,7 +116,7 @@ class TelemetryPump(BaseModel):
omni_type: OmniType = OmniType.PUMP
system_id: int = Field(alias="@systemId")
state: PumpState | int = Field(alias="@pumpState")
speed: int = Field(alias="@pummpSpeed")
speed: int = Field(alias="@pumpSpeed")
last_speed: int = Field(alias="@lastSpeed")
why_on: int = Field(alias="@whyOn")

Expand Down Expand Up @@ -225,6 +226,7 @@ def xml_postprocessor(path: Any, key: Any, value: SupportsInt | Any) -> tuple[An
OmniType.PUMP,
OmniType.RELAY,
OmniType.VALVE_ACTUATOR,
OmniType.VIRT_HEATER,
),
)
try:
Expand Down
3 changes: 2 additions & 1 deletion pyomnilogic_local/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

from typing_extensions import Self

from .exceptions import OmniTimeoutException
from .models.leadmessage import LeadMessage
from .types import ClientType, MessageType, OmniTimeoutException
from .types import ClientType, MessageType

_LOGGER = logging.getLogger(__name__)

Expand Down
14 changes: 1 addition & 13 deletions pyomnilogic_local/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ColorLogicShow(PrettyEnum):
USA = 14
MARDI_GRAS = 15
COOL_CABARET = 16
#### THESE SHOW IN THE APP AFTER SETTING, BUT MAY NOT MATCH ALL LIGHTS
#### The below options only work on lights that support OmniDirect / V2-Active in MSPConfig
YELLOW = 17
ORANGE = 18
GOLD = 19
Expand Down Expand Up @@ -300,15 +300,3 @@ class SensorUnits(str, PrettyEnum):
class ValveActuatorState(PrettyEnum):
OFF = 0
ON = 1


class OmniLogicException(Exception):
pass


class OmniTimeoutException(OmniLogicException):
pass


class OmniParsingException(OmniLogicException):
pass

0 comments on commit 62a4af4

Please sign in to comment.