implement heartbeat command

This commit is contained in:
suaveolent 2024-02-13 08:43:16 +01:00
parent a06b3c39d3
commit 96860f6442
5 changed files with 24 additions and 5 deletions

View File

@ -36,7 +36,8 @@ commands:
turn-on,
turn-off,
get-information-data,
get-version-info
get-version-info,
heartbeat,
The `--as-json` option is optional and allows formatting the output as JSON.
```

View File

@ -177,6 +177,9 @@ async def async_get_version_info(inverter):
inverter_sw_version="V" + generate_sw_version_string(response.pv_info[0].pv_sw_version),
)
async def async_heatbeat(inverter):
return await inverter.async_heartbeat()
def print_invalid_command(command):
print(f"Invalid command: {command}")
@ -205,7 +208,8 @@ async def main():
"turn-on",
"turn-off",
"get-information-data",
"get-version-info"
"get-version-info",
"heartbeat",
],
help="Command to execute",
)
@ -230,6 +234,7 @@ async def main():
'turn-off': async_turn_off,
'get-information-data': async_get_information_data,
'get-version-info': async_get_version_info,
'heartbeat': async_heatbeat,
}
command_func = switch.get(args.command, print_invalid_command)

View File

@ -11,6 +11,7 @@ from hoymiles_wifi import logger
from hoymiles_wifi.utils import initialize_set_config
from hoymiles_wifi.protobuf import (
APPHeartbeatPB_pb2,
APPInfomationData_pb2,
AppGetHistPower_pb2,
CommandPB_pb2,
@ -42,6 +43,7 @@ from hoymiles_wifi.const import (
CMD_ACTION_TURN_ON,
CMD_ACTION_TURN_OFF,
DTU_FIRMWARE_URL_00_01_11,
CMD_HB_RES_DTO,
)
@ -211,6 +213,17 @@ class Inverter:
return await self.async_send_request(command, request, InfomationData_pb2.InfoDataReqDTO)
async def async_heartbeat(self) -> APPHeartbeatPB_pb2.HBReqDTO | None:
request = APPHeartbeatPB_pb2.HBResDTO
request.time_ymd_hms = datetime.now().strftime("%Y-%m-%d %H:%M:%S").encode("utf-8")
request.offset = 28800
request.time = int(time.time())
command = CMD_HB_RES_DTO
return await self.async_send_request(command, request, APPHeartbeatPB_pb2.HBReqDTO)
async def async_send_request(self, command: bytes, request: Any, response_type: Any, inverter_port: int = INVERTER_PORT):
self.sequence = (self.sequence + 1) & 0xFFFF

View File

@ -11,5 +11,5 @@ message HBReqDTO {
message HBResDTO {
int32 offset = 1; // Offset value
int32 time = 2; // Timestamp of the response
string ymd_hms = 3; // Timestamp in the format YMD_HMS
string time_ymd_hms = 3; // Timestamp in the format YMD_HMS
}

View File

@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x14\x41PPHeartbeatPB.proto\"n\n\x08HBReqDTO\x12\x0e\n\x06offset\x18\x01 \x01(\x05\x12\x0c\n\x04time\x18\x02 \x01(\x05\x12\x0b\n\x03\x63sq\x18\x03 \x01(\x05\x12\x19\n\x11\x64tu_serial_number\x18\x04 \x01(\t\x12\x1c\n\x14\x64\x65vice_serial_number\x18\x05 \x01(\t\"9\n\x08HBResDTO\x12\x0e\n\x06offset\x18\x01 \x01(\x05\x12\x0c\n\x04time\x18\x02 \x01(\x05\x12\x0f\n\x07ymd_hms\x18\x03 \x01(\tb\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x14\x41PPHeartbeatPB.proto\"n\n\x08HBReqDTO\x12\x0e\n\x06offset\x18\x01 \x01(\x05\x12\x0c\n\x04time\x18\x02 \x01(\x05\x12\x0b\n\x03\x63sq\x18\x03 \x01(\x05\x12\x19\n\x11\x64tu_serial_number\x18\x04 \x01(\t\x12\x1c\n\x14\x64\x65vice_serial_number\x18\x05 \x01(\t\">\n\x08HBResDTO\x12\x0e\n\x06offset\x18\x01 \x01(\x05\x12\x0c\n\x04time\x18\x02 \x01(\x05\x12\x14\n\x0ctime_ymd_hms\x18\x03 \x01(\tb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@ -24,5 +24,5 @@ if _descriptor._USE_C_DESCRIPTORS == False:
_globals['_HBREQDTO']._serialized_start=24
_globals['_HBREQDTO']._serialized_end=134
_globals['_HBRESDTO']._serialized_start=136
_globals['_HBRESDTO']._serialized_end=193
_globals['_HBRESDTO']._serialized_end=198
# @@protoc_insertion_point(module_scope)