|
1 | 1 | from pyomnilogic_local._base import OmniEquipment |
| 2 | +from pyomnilogic_local.decorators import dirties_state |
2 | 3 | from pyomnilogic_local.models.mspconfig import MSPChlorinator |
3 | 4 | from pyomnilogic_local.models.telemetry import TelemetryChlorinator |
4 | | -from pyomnilogic_local.omnitypes import ChlorinatorOperatingMode, ChlorinatorStatus |
| 5 | +from pyomnilogic_local.omnitypes import ( |
| 6 | + ChlorinatorCellType, |
| 7 | + ChlorinatorOperatingMode, |
| 8 | + ChlorinatorStatus, |
| 9 | +) |
| 10 | +from pyomnilogic_local.util import OmniEquipmentNotInitializedError |
5 | 11 |
|
6 | 12 |
|
7 | 13 | class Chlorinator(OmniEquipment[MSPChlorinator, TelemetryChlorinator]): |
@@ -54,7 +60,7 @@ def dispenser_type(self) -> str: |
54 | 60 | return self.mspconfig.dispenser_type |
55 | 61 |
|
56 | 62 | @property |
57 | | - def cell_type(self) -> str: |
| 63 | + def cell_type(self) -> ChlorinatorCellType: |
58 | 64 | """Type of T-Cell installed (e.g., T3, T5, T9, T15).""" |
59 | 65 | return self.mspconfig.cell_type |
60 | 66 |
|
@@ -321,3 +327,71 @@ def is_ready(self) -> bool: |
321 | 327 |
|
322 | 328 | # Then check chlorinator-specific readiness |
323 | 329 | return self.is_authenticated and not self.has_error |
| 330 | + |
| 331 | + # Control methods |
| 332 | + @dirties_state() |
| 333 | + async def turn_on(self) -> None: |
| 334 | + """Turn the chlorinator on (enable it). |
| 335 | +
|
| 336 | + Raises: |
| 337 | + OmniEquipmentNotInitializedError: If bow_id is None. |
| 338 | + """ |
| 339 | + if self.bow_id is None: |
| 340 | + raise OmniEquipmentNotInitializedError("Cannot turn on chlorinator: bow_id is None") |
| 341 | + await self._api.async_set_chlorinator_enable(self.bow_id, True) |
| 342 | + |
| 343 | + @dirties_state() |
| 344 | + async def turn_off(self) -> None: |
| 345 | + """Turn the chlorinator off (disable it). |
| 346 | +
|
| 347 | + Raises: |
| 348 | + OmniEquipmentNotInitializedError: If bow_id is None. |
| 349 | + """ |
| 350 | + if self.bow_id is None: |
| 351 | + raise OmniEquipmentNotInitializedError("Cannot turn off chlorinator: bow_id is None") |
| 352 | + await self._api.async_set_chlorinator_enable(self.bow_id, False) |
| 353 | + |
| 354 | + @dirties_state() |
| 355 | + async def set_timed_percent(self, percent: int) -> None: |
| 356 | + """Set the timed percent for chlorine generation. |
| 357 | +
|
| 358 | + Args: |
| 359 | + percent: The chlorine generation percentage (0-100) |
| 360 | +
|
| 361 | + Raises: |
| 362 | + OmniEquipmentNotInitializedError: If bow_id or system_id is None. |
| 363 | + ValueError: If percent is outside the valid range (0-100). |
| 364 | +
|
| 365 | + Note: |
| 366 | + This method uses the async_set_chlorinator_params API which requires |
| 367 | + all chlorinator configuration parameters. The current values from |
| 368 | + mspconfig are used for unchanged parameters. |
| 369 | + """ |
| 370 | + if self.bow_id is None or self.system_id is None: |
| 371 | + raise OmniEquipmentNotInitializedError("Cannot set timed percent: bow_id or system_id is None") |
| 372 | + |
| 373 | + if not 0 <= percent <= 100: |
| 374 | + raise ValueError(f"Timed percent {percent} is outside valid range [0, 100]") |
| 375 | + |
| 376 | + # Get the parent Bow to determine bow_type |
| 377 | + # We need to find our bow in the backyard |
| 378 | + if (bow := self._omni.backyard.bow.get(self.bow_id)) is None: |
| 379 | + raise OmniEquipmentNotInitializedError(f"Cannot find bow with id {self.bow_id}") |
| 380 | + |
| 381 | + # Map equipment type to numeric bow_type value |
| 382 | + # BOW_POOL = 0, BOW_SPA = 1 (based on typical protocol values) |
| 383 | + bow_type = 0 if bow.equip_type == "BOW_POOL" else 1 |
| 384 | + |
| 385 | + # Get operating mode from telemetry (it's already an int or enum with .value) |
| 386 | + op_mode = self.telemetry.operating_mode if isinstance(self.telemetry.operating_mode, int) else self.telemetry.operating_mode.value |
| 387 | + |
| 388 | + await self._api.async_set_chlorinator_params( |
| 389 | + pool_id=self.bow_id, |
| 390 | + equipment_id=self.system_id, |
| 391 | + timed_percent=percent, |
| 392 | + cell_type=self.mspconfig.cell_type.value, # ChlorinatorCellType is now IntEnum, use .value |
| 393 | + op_mode=op_mode, |
| 394 | + sc_timeout=self.mspconfig.superchlor_timeout, |
| 395 | + bow_type=bow_type, |
| 396 | + orp_timeout=self.mspconfig.orp_timeout, |
| 397 | + ) |
0 commit comments