diff --git a/homeassistant/components/modbus/modbus.py b/homeassistant/components/modbus/modbus.py index e81afc968ca..e5c08b2e1ed 100644 --- a/homeassistant/components/modbus/modbus.py +++ b/homeassistant/components/modbus/modbus.py @@ -293,22 +293,18 @@ class ModbusHub: func = getattr(self._client, entry.func_name) 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: if not await self.hass.async_add_executor_job(self._pymodbus_connect): err = f"{self.name} connect failed, retry in pymodbus" self._log_error(err, error_state=False) - return + return False # Start counting down to allow modbus requests. if self._config_delay: self._async_cancel_listener = async_call_later( self.hass, self._config_delay, self.async_end_delay ) + return True @callback def async_end_delay(self, args: Any) -> None: @@ -341,10 +337,8 @@ class ModbusHub: def _pymodbus_connect(self) -> bool: """Connect client.""" - if not self._client: - return False try: - self._client.connect() + self._client.connect() # type: ignore[union-attr] except ModbusException as exception_error: self._log_error(str(exception_error), error_state=False) return False