From 93537a5f51879f116b95533df99e84a77a1ee224 Mon Sep 17 00:00:00 2001 From: suaveolent Date: Mon, 3 Jun 2024 14:05:46 +0200 Subject: [PATCH] add get-alarm-list command --- hoymiles_wifi/__main__.py | 8 ++++++++ hoymiles_wifi/const.py | 1 + hoymiles_wifi/dtu.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/hoymiles_wifi/__main__.py b/hoymiles_wifi/__main__.py index 453f3fb..c9f26a5 100644 --- a/hoymiles_wifi/__main__.py +++ b/hoymiles_wifi/__main__.py @@ -283,6 +283,12 @@ async def async_identify_inverters(dtu: DTU) -> list[str]: return inverter_models +async def async_get_alarm_list(dtu: DTU) -> None: + """Get alarm list from the dtu asynchronously.""" + + return await dtu.async_get_alarm_list() + + def print_invalid_command(command: str) -> None: """Print an invalid command message.""" @@ -325,6 +331,7 @@ async def main() -> None: "heartbeat", "identify-dtu", "identify-inverters", + "get-alarm-list", ], help="Command to execute", ) @@ -351,6 +358,7 @@ async def main() -> None: "heartbeat": async_heatbeat, "identify-dtu": async_identify_dtu, "identify-inverters": async_identify_inverters, + "get-alarm-list": async_get_alarm_list, } command_func = switch.get(args.command, print_invalid_command) diff --git a/hoymiles_wifi/const.py b/hoymiles_wifi/const.py index cc501bd..c2e14df 100644 --- a/hoymiles_wifi/const.py +++ b/hoymiles_wifi/const.py @@ -60,6 +60,7 @@ CMD_ACTION_REPEATER_NETWORKING = 0 CMD_ACTION_DTU_DEFAULT = 0 CMD_ACTION_GATEWAY_DEFAULT = 0 CMD_ACTION_METER_REVERSE = 49 +CMD_ACTION_ALARM_LIST = 50 CMD_ACTION_GW_REBOOT = 4096 CMD_ACTION_GW_RESET = 4097 CMD_ACTION_GW_STOP_RUN = 4098 diff --git a/hoymiles_wifi/dtu.py b/hoymiles_wifi/dtu.py index fceb25b..024eb12 100644 --- a/hoymiles_wifi/dtu.py +++ b/hoymiles_wifi/dtu.py @@ -13,6 +13,7 @@ from crcmod import mkCrcFun from hoymiles_wifi import logger from hoymiles_wifi.const import ( + CMD_ACTION_ALARM_LIST, CMD_ACTION_DTU_REBOOT, CMD_ACTION_DTU_UPGRADE, CMD_ACTION_LIMIT_POWER, @@ -310,6 +311,20 @@ class DTU: command, request, APPHeartbeatPB_pb2.HBReqDTO ) + async def async_get_alarm_list(self) -> CommandPB_pb2.CommandResDTO | None: + """Turn off DTU.""" + + request = CommandPB_pb2.CommandResDTO() + request.action = CMD_ACTION_ALARM_LIST + request.package_nub = 1 + request.dev_kind = 0 + request.tid = int(time.time()) + + command = CMD_COMMAND_RES_DTO + return await self.async_send_request( + command, request, CommandPB_pb2.CommandReqDTO + ) + async def async_send_request( self, command: bytes,