|
| 1 | +# Need to figure out how to resolve the 'Untyped decorator makes function "..." untyped' errors in mypy when using click decorators |
| 2 | +# mypy: disable-error-code="misc" |
| 3 | +import asyncio |
| 4 | +from typing import Literal, overload |
| 5 | + |
| 6 | +import click |
| 7 | + |
| 8 | +from pyomnilogic_local.api import OmniLogicAPI |
| 9 | +from pyomnilogic_local.cli.utils import async_get_mspconfig, async_get_telemetry |
| 10 | +from pyomnilogic_local.models.filter_diagnostics import FilterDiagnostics |
| 11 | + |
| 12 | + |
| 13 | +@click.group() |
| 14 | +@click.option("--raw/--no-raw", default=False, help="Output the raw XML from the OmniLogic, do not parse the response") |
| 15 | +@click.pass_context |
| 16 | +def debug(ctx: click.Context, raw: bool) -> None: |
| 17 | + # Container for all get commands |
| 18 | + |
| 19 | + ctx.ensure_object(dict) |
| 20 | + ctx.obj["RAW"] = raw |
| 21 | + |
| 22 | + |
| 23 | +@debug.command() |
| 24 | +@click.pass_context |
| 25 | +def get_mspconfig(ctx: click.Context) -> None: |
| 26 | + mspconfig = asyncio.run(async_get_mspconfig(ctx.obj["OMNI"], ctx.obj["RAW"])) |
| 27 | + click.echo(mspconfig) |
| 28 | + |
| 29 | + |
| 30 | +@debug.command() |
| 31 | +@click.pass_context |
| 32 | +def get_telemetry(ctx: click.Context) -> None: |
| 33 | + telemetry = asyncio.run(async_get_telemetry(ctx.obj["OMNI"], ctx.obj["RAW"])) |
| 34 | + click.echo(telemetry) |
| 35 | + |
| 36 | + |
| 37 | +@debug.command() |
| 38 | +@click.pass_context |
| 39 | +def get_alarm_list(ctx: click.Context) -> None: |
| 40 | + alarm_list = asyncio.run(async_get_alarm_list(ctx.obj["OMNI"])) |
| 41 | + click.echo(alarm_list) |
| 42 | + |
| 43 | + |
| 44 | +async def async_get_alarm_list(omni: OmniLogicAPI) -> str: |
| 45 | + alarm_list = await omni.async_get_alarm_list() |
| 46 | + return alarm_list |
| 47 | + |
| 48 | + |
| 49 | +@debug.command() |
| 50 | +@click.option("--pool-id", help="System ID of the Body Of Water the filter is associated with") |
| 51 | +@click.option("--filter-id", help="System ID of the filter to request diagnostics for") |
| 52 | +@click.pass_context |
| 53 | +def get_filter_diagnostics(ctx: click.Context, pool_id: int, filter_id: int) -> None: |
| 54 | + filter_diags = asyncio.run(async_get_filter_diagnostics(ctx.obj["OMNI"], pool_id, filter_id, ctx.obj["RAW"])) |
| 55 | + if ctx.obj["RAW"]: |
| 56 | + click.echo(filter_diags) |
| 57 | + else: |
| 58 | + drv1 = chr(filter_diags.get_param_by_name("DriveFWRevisionB1")) |
| 59 | + drv2 = chr(filter_diags.get_param_by_name("DriveFWRevisionB2")) |
| 60 | + drv3 = chr(filter_diags.get_param_by_name("DriveFWRevisionB3")) |
| 61 | + drv4 = chr(filter_diags.get_param_by_name("DriveFWRevisionB4")) |
| 62 | + dfw1 = chr(filter_diags.get_param_by_name("DisplayFWRevisionB1")) |
| 63 | + dfw2 = chr(filter_diags.get_param_by_name("DisplayFWRevisionB2")) |
| 64 | + dfw3 = chr(filter_diags.get_param_by_name("DisplayFWRevisionB3")) |
| 65 | + dfw4 = chr(filter_diags.get_param_by_name("DisplayFWRevisionB4")) |
| 66 | + pow1 = filter_diags.get_param_by_name("PowerMSB") |
| 67 | + pow2 = filter_diags.get_param_by_name("PowerLSB") |
| 68 | + errs = filter_diags.get_param_by_name("ErrorStatus") |
| 69 | + click.echo( |
| 70 | + f"DRIVE FW REV: {drv1}{drv2}.{drv3}{drv4}\n" |
| 71 | + f"DISPLAY FW REV: {dfw1}{dfw2}.{dfw3}.{dfw4}\n" |
| 72 | + f"POWER: {pow1:x}{pow2:x}W\n" |
| 73 | + f"ERROR STATUS: {errs}" |
| 74 | + ) |
| 75 | + |
| 76 | + |
| 77 | +@overload |
| 78 | +async def async_get_filter_diagnostics(omni: OmniLogicAPI, pool_id: int, filter_id: int, raw: Literal[True]) -> str: ... |
| 79 | +@overload |
| 80 | +async def async_get_filter_diagnostics(omni: OmniLogicAPI, pool_id: int, filter_id: int, raw: Literal[False]) -> FilterDiagnostics: ... |
| 81 | +async def async_get_filter_diagnostics(omni: OmniLogicAPI, pool_id: int, filter_id: int, raw: bool) -> FilterDiagnostics | str: |
| 82 | + filter_diags = await omni.async_get_filter_diagnostics(pool_id, filter_id, raw=raw) |
| 83 | + return filter_diags |
| 84 | + |
| 85 | + |
| 86 | +@debug.command() |
| 87 | +@click.pass_context |
| 88 | +def get_log_config(ctx: click.Context) -> None: |
| 89 | + log_config = asyncio.run(async_get_log_config(ctx.obj["OMNI"])) |
| 90 | + click.echo(log_config) |
| 91 | + |
| 92 | + |
| 93 | +async def async_get_log_config(omni: OmniLogicAPI) -> str: |
| 94 | + log_config = await omni.async_get_log_config() |
| 95 | + return log_config |
0 commit comments