Skip to content

Commit a578342

Browse files
authored
Merge pull request #137 from cryptk/feat_csad_enable_disable
feat(cli): add debug command to try and work out CSAD enable/disable
2 parents d5306e2 + 833190d commit a578342

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

pyomnilogic_local/cli/debug/commands.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
from __future__ import annotations
55

66
import asyncio
7+
import xml.etree.ElementTree as ET
8+
from enum import IntEnum
79
from pathlib import Path
810
from typing import TYPE_CHECKING, cast
911

1012
import click
1113

14+
from pyomnilogic_local.api.constants import XML_ENCODING, XML_NAMESPACE
1215
from pyomnilogic_local.cli.pcap_utils import parse_pcap_file, process_pcap_messages
16+
from pyomnilogic_local.util import PrettyEnum
1317

1418
if TYPE_CHECKING:
1519
from pyomnilogic_local import OmniLogic
1620
from pyomnilogic_local.models.telemetry import TelemetryChlorinator
21+
from pyomnilogic_local.omnitypes import MessageType
1722

1823

1924
@click.group()
@@ -350,3 +355,36 @@ def set_csad_orp(ctx: click.Context, bow_id: int, csad_id: int, target: int) ->
350355
except Exception as e:
351356
click.echo(f"Error setting CSAD ORP target: {e}", err=True)
352357
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

Comments
 (0)