Skip to content

Commit 4197b60

Browse files
authored
Merge pull request #140 from cryptk/fix_chlorinator_mode
fix(chlorinator): telemetry doesn't properly represent operating mode
2 parents 79c55b8 + 663ca42 commit 4197b60

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

pyomnilogic_local/chlorinator.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pyomnilogic_local.decorators import control_method
99
from pyomnilogic_local.models.mspconfig import MSPChlorinator
1010
from pyomnilogic_local.models.telemetry import TelemetryChlorinator
11-
from pyomnilogic_local.omnitypes import ChlorinatorStatus
11+
from pyomnilogic_local.omnitypes import ChlorinatorMSPConfigMode, ChlorinatorStatus
1212
from pyomnilogic_local.util import OmniEquipmentNotInitializedError
1313

1414
if TYPE_CHECKING:
@@ -98,10 +98,29 @@ def operating_state(self) -> int:
9898
"""Current operational state of the chlorinator (raw value)."""
9999
return self.telemetry.operating_state
100100

101+
@property
102+
def mode(self) -> ChlorinatorMSPConfigMode:
103+
"""Current operating mode from MSP Config (NOT_CONFIGURED, TIMED, ORP_AUTO).
104+
105+
TThis data appears to have some discrepancies with the mode reported in the Telemetry.
106+
The assumption is that the MSP Config mode represents the intended/configured mode, while the
107+
Telemetry operating mode represents the actual/current mode of operation. The reasons for
108+
discrepancies are not fully understood.
109+
110+
Returns:
111+
ChlorinatorMSPConfigMode: The operating mode enum value
112+
"""
113+
return self.mspconfig.mode
114+
101115
@property
102116
def operating_mode(self) -> ChlorinatorOperatingMode:
103117
"""Current operating mode (DISABLED, TIMED, ORP_AUTO, or ORP_TIMED_RW).
104118
119+
This data appears to have some discrepancies with the mode reported in the MSP Config.
120+
The assumption is that the MSP Config mode represents the intended/configured mode, while the
121+
Telemetry operating mode represents the actual/current mode of operation. The reasons for
122+
discrepancies are not fully understood.
123+
105124
Returns:
106125
ChlorinatorOperatingMode: The operating mode enum value
107126
"""
@@ -402,7 +421,7 @@ async def set_timed_percent(self, percent: int) -> None:
402421
)
403422

404423
@control_method
405-
async def set_op_mode(self, op_mode: ChlorinatorOperatingMode) -> None:
424+
async def set_op_mode(self, op_mode: ChlorinatorMSPConfigMode) -> None:
406425
"""Set the operating mode for chlorine generation.
407426
408427
Args:
@@ -432,12 +451,22 @@ async def set_op_mode(self, op_mode: ChlorinatorOperatingMode) -> None:
432451

433452
bow_type = 0 if bow.equip_type == "BOW_POOL" else 1
434453

454+
new_op_mode: int
455+
match op_mode:
456+
case ChlorinatorMSPConfigMode.TIMED:
457+
new_op_mode = 1
458+
case ChlorinatorMSPConfigMode.ORP_AUTO:
459+
new_op_mode = 2
460+
case _:
461+
msg = f"Unsupported operating mode: {op_mode}"
462+
raise ValueError(msg)
463+
435464
await self._api.async_set_chlorinator_params(
436465
pool_id=self.bow_id,
437466
equipment_id=self.system_id,
438467
timed_percent=self.timed_percent_telemetry,
439468
cell_type=self.mspconfig.cell_type.value,
440-
op_mode=op_mode.value,
469+
op_mode=new_op_mode,
441470
sc_timeout=self.superchlor_timeout,
442471
bow_type=bow_type,
443472
orp_timeout=self.orp_timeout,

pyomnilogic_local/models/mspconfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
BodyOfWaterType,
2121
ChlorinatorCellType,
2222
ChlorinatorDispenserType,
23+
ChlorinatorMSPConfigMode,
2324
ChlorinatorType,
2425
ColorLogicLightType,
2526
ColorLogicShow25,
@@ -217,6 +218,7 @@ class MSPChlorinator(OmniBase):
217218
omni_type: OmniType = OmniType.CHLORINATOR
218219

219220
enabled: bool = Field(alias="Enabled")
221+
mode: ChlorinatorMSPConfigMode = Field(alias="Mode")
220222
timed_percent: int = Field(alias="Timed-Percent")
221223
superchlor_timeout: int = Field(alias="SuperChlor-Timeout")
222224
orp_timeout: int = Field(alias="ORP-Timeout")

pyomnilogic_local/omnitypes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ class ChlorinatorError(PrettyEnum, Flag):
151151
AQUARITE_PCB_ERROR = 1 << 14
152152

153153

154+
class ChlorinatorMSPConfigMode(PrettyEnum, StrEnum):
155+
DISABLED = "CHLOR_OP_MODE_NOT_CONFIG_R"
156+
TIMED = "CHLOR_OP_MODE_TIMED"
157+
ORP_AUTO = "CHLOR_OP_MODE_ORP_AUTO"
158+
159+
154160
class ChlorinatorOperatingMode(PrettyEnum, IntEnum):
155161
DISABLED = 0
156162
TIMED = 1

0 commit comments

Comments
 (0)