Do not close non existing clients in modbus (#49489)

* Only close if _client is present.

* Remove del.
This commit is contained in:
jan iversen
2021-04-21 11:46:40 +02:00
committed by GitHub
parent 6e22251e1d
commit c9bdc9609c

View File

@@ -209,11 +209,11 @@ class ModbusHub:
"""Disconnect client."""
with self._lock:
try:
self._client.close()
del self._client
self._client = None
if self._client:
self._client.close()
self._client = None
except ModbusException as exception_error:
self._log_error(exception_error, error_state=False)
self._log_error(exception_error)
return
def connect(self):