From 1f148857e670ac190ee8a0f52c480974197be665 Mon Sep 17 00:00:00 2001 From: David Rapan Date: Wed, 18 Dec 2024 20:33:36 +0100 Subject: [PATCH] feat: Implemented response to V5 HEARTBEAT --- custom_components/solarman/__init__.py | 2 +- custom_components/solarman/api.py | 45 ++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/custom_components/solarman/__init__.py b/custom_components/solarman/__init__.py index 0778ede..db585de 100644 --- a/custom_components/solarman/__init__.py +++ b/custom_components/solarman/__init__.py @@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__) -PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.SWITCH, Platform.NUMBER, Platform.SELECT, Platform.DATETIME, Platform.TIME, Platform.BUTTON] +PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.BINARY_SENSOR, Platform.NUMBER, Platform.SWITCH, Platform.BUTTON, Platform.SELECT, Platform.DATETIME, Platform.TIME] CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN) diff --git a/custom_components/solarman/api.py b/custom_components/solarman/api.py index 0606e50..775d09d 100644 --- a/custom_components/solarman/api.py +++ b/custom_components/solarman/api.py @@ -1,5 +1,6 @@ import time import errno +import struct import socket import logging import asyncio @@ -13,7 +14,7 @@ from .const import * from .common import * from .provider import * -from .include.pysolarmanv5 import PySolarmanV5Async +from .include.pysolarmanv5 import PySolarmanV5Async, NoSocketAvailableError _LOGGER = logging.getLogger(__name__) @@ -52,6 +53,45 @@ async def _tcp_send_receive_frame(self, mb_request_frame): async def _tcp_parse_response_adu(self, mb_request_frame): return parse_response_adu(await self._tcp_send_receive_frame(mb_request_frame), mb_request_frame) + async def _heartbeat_response(self): + v5_header = bytearray( + self.v5_start + + struct.pack("