Solve modbus shutdown racing condition (#55373)

This commit is contained in:
jan iversen 2021-08-28 23:04:33 +02:00 committed by GitHub
parent 13cc671844
commit f91cc21bbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -292,13 +292,13 @@ class ModbusHub:
for call in self.entity_timers: for call in self.entity_timers:
call() call()
self.entity_timers = [] self.entity_timers = []
if self._client: async with self._lock:
async with self._lock: if self._client:
try: try:
self._client.close() self._client.close()
except ModbusException as exception_error: except ModbusException as exception_error:
self._log_error(str(exception_error)) self._log_error(str(exception_error))
self._client = None self._client = None
def _pymodbus_connect(self): def _pymodbus_connect(self):
"""Connect client.""" """Connect client."""
@ -327,9 +327,9 @@ class ModbusHub:
"""Convert async to sync pymodbus call.""" """Convert async to sync pymodbus call."""
if self._config_delay: if self._config_delay:
return None return None
if not self._client:
return None
async with self._lock: async with self._lock:
if not self._client:
return None
result = await self.hass.async_add_executor_job( result = await self.hass.async_add_executor_job(
self._pymodbus_call, unit, address, value, use_call self._pymodbus_call, unit, address, value, use_call
) )