|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
6 | 6 | import asyncio |
| 7 | +import xml.etree.ElementTree as ET |
| 8 | +from enum import IntEnum |
7 | 9 | from pathlib import Path |
8 | 10 | from typing import TYPE_CHECKING, cast |
9 | 11 |
|
10 | 12 | import click |
11 | 13 |
|
| 14 | +from pyomnilogic_local.api.constants import XML_ENCODING, XML_NAMESPACE |
12 | 15 | from pyomnilogic_local.cli.pcap_utils import parse_pcap_file, process_pcap_messages |
| 16 | +from pyomnilogic_local.util import PrettyEnum |
13 | 17 |
|
14 | 18 | if TYPE_CHECKING: |
15 | 19 | from pyomnilogic_local import OmniLogic |
16 | 20 | from pyomnilogic_local.models.telemetry import TelemetryChlorinator |
| 21 | + from pyomnilogic_local.omnitypes import MessageType |
17 | 22 |
|
18 | 23 |
|
19 | 24 | @click.group() |
@@ -350,3 +355,36 @@ def set_csad_orp(ctx: click.Context, bow_id: int, csad_id: int, target: int) -> |
350 | 355 | except Exception as e: |
351 | 356 | click.echo(f"Error setting CSAD ORP target: {e}", err=True) |
352 | 357 | raise click.Abort from e |
| 358 | + |
| 359 | + |
| 360 | +@debug.command() |
| 361 | +@click.argument("bow_id", type=int) |
| 362 | +@click.argument("csad_id", type=int) |
| 363 | +@click.argument("opid", type=int) |
| 364 | +@click.argument("is_on") |
| 365 | +@click.pass_context |
| 366 | +def set_csad_enable(ctx: click.Context, bow_id: int, csad_id: int, opid: int, is_on: bool) -> None: |
| 367 | + """Attempt to enable or disable a CSAD (Chemical Sense and Dispense) device.""" |
| 368 | + omnilogic: OmniLogic = ctx.obj["OMNILOGIC"] |
| 369 | + |
| 370 | + body_element = ET.Element("Request", {"xmlns": XML_NAMESPACE}) |
| 371 | + |
| 372 | + name_element = ET.SubElement(body_element, "Name") |
| 373 | + name_element.text = "UISetCSADEnabled" |
| 374 | + |
| 375 | + parameters_element = ET.SubElement(body_element, "Parameters") |
| 376 | + parameter = ET.SubElement(parameters_element, "Parameter", name="poolId", dataType="int") |
| 377 | + parameter.text = str(bow_id) |
| 378 | + parameter = ET.SubElement(parameters_element, "Parameter", name="CSADID", dataType="int", alias="EquipmentID") |
| 379 | + parameter.text = str(csad_id) |
| 380 | + parameter = ET.SubElement(parameters_element, "Parameter", name="Enabled", dataType="bool", alias="Data") |
| 381 | + parameter.text = str(int(is_on)) |
| 382 | + |
| 383 | + req_body = ET.tostring(body_element, xml_declaration=True, encoding=XML_ENCODING) |
| 384 | + |
| 385 | + class CustomMessageType(PrettyEnum, IntEnum): |
| 386 | + SET_CSAD_ENABLE = opid |
| 387 | + |
| 388 | + click.echo(f"Sending UISetCSADEnabled with op ID: {opid}; body: {req_body}") |
| 389 | + |
| 390 | + asyncio.run(omnilogic._api.async_send(cast("MessageType", CustomMessageType.SET_CSAD_ENABLE), req_body)) |
0 commit comments