1
mirror of https://github.com/home-assistant/core synced 2024-09-06 10:29:55 +02:00

Change entity_timers to be a local variable. (#55258)

Ensure outstanding pymodbus calls are handled before closing.
This commit is contained in:
jan iversen 2021-08-26 15:23:00 +02:00 committed by GitHub
parent 0a07ff4d23
commit 2d5176eee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,13 +189,12 @@ class ModbusHub:
name: str
entity_timers: list[CALLBACK_TYPE] = []
def __init__(self, hass, client_config):
"""Initialize the Modbus hub."""
# generic configuration
self._client = None
self.entity_timers: list[CALLBACK_TYPE] = []
self._async_cancel_listener = None
self._in_error = False
self._lock = asyncio.Lock()
@ -294,11 +293,12 @@ class ModbusHub:
call()
self.entity_timers = []
if self._client:
try:
self._client.close()
except ModbusException as exception_error:
self._log_error(str(exception_error))
self._client = None
async with self._lock:
try:
self._client.close()
except ModbusException as exception_error:
self._log_error(str(exception_error))
self._client = None
def _pymodbus_connect(self):
"""Connect client."""