Skip to content

Commit

Permalink
2025.02.2b2
Browse files Browse the repository at this point in the history
  • Loading branch information
wills106 authored Feb 25, 2025
1 parent d5c8646 commit b523f78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions custom_components/solax_modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from weakref import ref as WeakRef

from pymodbus.client import AsyncModbusSerialClient, AsyncModbusTcpClient
from pymodbus.exceptions import ModbusException

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
Expand Down Expand Up @@ -254,18 +255,18 @@ def __init__(
parity="N",
stopbits=1,
bytesize=8,
timeout=10,
timeout=15,
retries=6,
)
elif interface == "tcp":
if tcp_type == "rtu":
self._client = AsyncModbusTcpClient(host=host, port=port, timeout=10, framer=FramerType.RTU, retries=6)
self._client = AsyncModbusTcpClient(host=host, port=port, timeout=15, framer=FramerType.RTU, retries=6)
elif tcp_type == "ascii":
self._client = AsyncModbusTcpClient(
host=host, port=port, timeout=10, framer=FramerType.ASCII, retries=6
host=host, port=port, timeout=15, framer=FramerType.ASCII, retries=6
)
else:
self._client = AsyncModbusTcpClient(host=host, port=port, timeout=10, retries=6)
self._client = AsyncModbusTcpClient(host=host, port=port, timeout=15, retries=6)
self._lock = asyncio.Lock()
self._name = name
self.inverterNameSuffix = config.get(CONF_INVERTER_NAME_SUFFIX)
Expand Down Expand Up @@ -542,15 +543,25 @@ async def async_read_holding_registers(self, unit, address, count):
kwargs = {"slave": unit} if unit else {}
async with self._lock:
await self._check_connection()
resp = await self._client.read_holding_registers(address=address, count=count, **kwargs)
try:
resp = await self._client.read_holding_registers(address=address, count=count, **kwargs)
except ModbusException as exception_error:
error = f"Error: device: {unit} address: {address} -> {exception_error!s}"
self._log_error(error)
return None
return resp

async def async_read_input_registers(self, unit, address, count):
"""Read input registers."""
kwargs = {"slave": unit} if unit else {}
async with self._lock:
await self._check_connection()
resp = await self._client.read_input_registers(address=address, count=count, **kwargs)
try:
resp = await self._client.read_input_registers(address=address, count=count, **kwargs)
except ModbusException as exception_error:
error = f"Error: device: {unit} address: {address} -> {exception_error!s}"
self._log_error(error)
return None
return resp

async def async_lowlevel_write_register(self, unit, address, payload):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solax_modbus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/wills106/homsassistant-solax-modbus/issues",
"requirements": ["pymodbus==3.8.3"],
"version": "2025.02.1b1"
"version": "2025.02.1b2"
}

0 comments on commit b523f78

Please sign in to comment.