mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Streamline modbus before 100% coverage. (#57478)
This commit is contained in:
parent
48c2cfa6f8
commit
6a39119ccc
@ -293,22 +293,18 @@ class ModbusHub:
|
|||||||
func = getattr(self._client, entry.func_name)
|
func = getattr(self._client, entry.func_name)
|
||||||
self._pb_call[entry.call_type] = RunEntry(entry.attr, func)
|
self._pb_call[entry.call_type] = RunEntry(entry.attr, func)
|
||||||
|
|
||||||
await self.async_connect_task()
|
|
||||||
return True
|
|
||||||
|
|
||||||
async def async_connect_task(self) -> None:
|
|
||||||
"""Try to connect, and retry if needed."""
|
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
if not await self.hass.async_add_executor_job(self._pymodbus_connect):
|
if not await self.hass.async_add_executor_job(self._pymodbus_connect):
|
||||||
err = f"{self.name} connect failed, retry in pymodbus"
|
err = f"{self.name} connect failed, retry in pymodbus"
|
||||||
self._log_error(err, error_state=False)
|
self._log_error(err, error_state=False)
|
||||||
return
|
return False
|
||||||
|
|
||||||
# Start counting down to allow modbus requests.
|
# Start counting down to allow modbus requests.
|
||||||
if self._config_delay:
|
if self._config_delay:
|
||||||
self._async_cancel_listener = async_call_later(
|
self._async_cancel_listener = async_call_later(
|
||||||
self.hass, self._config_delay, self.async_end_delay
|
self.hass, self._config_delay, self.async_end_delay
|
||||||
)
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_end_delay(self, args: Any) -> None:
|
def async_end_delay(self, args: Any) -> None:
|
||||||
@ -341,10 +337,8 @@ class ModbusHub:
|
|||||||
|
|
||||||
def _pymodbus_connect(self) -> bool:
|
def _pymodbus_connect(self) -> bool:
|
||||||
"""Connect client."""
|
"""Connect client."""
|
||||||
if not self._client:
|
|
||||||
return False
|
|
||||||
try:
|
try:
|
||||||
self._client.connect()
|
self._client.connect() # type: ignore[union-attr]
|
||||||
except ModbusException as exception_error:
|
except ModbusException as exception_error:
|
||||||
self._log_error(str(exception_error), error_state=False)
|
self._log_error(str(exception_error), error_state=False)
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user