mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Change entity_timers to be a local variable. (#55258)
Ensure outstanding pymodbus calls are handled before closing.
This commit is contained in:
parent
0a07ff4d23
commit
2d5176eee9
@ -189,13 +189,12 @@ class ModbusHub:
|
|||||||
|
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
entity_timers: list[CALLBACK_TYPE] = []
|
|
||||||
|
|
||||||
def __init__(self, hass, client_config):
|
def __init__(self, hass, client_config):
|
||||||
"""Initialize the Modbus hub."""
|
"""Initialize the Modbus hub."""
|
||||||
|
|
||||||
# generic configuration
|
# generic configuration
|
||||||
self._client = None
|
self._client = None
|
||||||
|
self.entity_timers: list[CALLBACK_TYPE] = []
|
||||||
self._async_cancel_listener = None
|
self._async_cancel_listener = None
|
||||||
self._in_error = False
|
self._in_error = False
|
||||||
self._lock = asyncio.Lock()
|
self._lock = asyncio.Lock()
|
||||||
@ -294,11 +293,12 @@ class ModbusHub:
|
|||||||
call()
|
call()
|
||||||
self.entity_timers = []
|
self.entity_timers = []
|
||||||
if self._client:
|
if self._client:
|
||||||
try:
|
async with self._lock:
|
||||||
self._client.close()
|
try:
|
||||||
except ModbusException as exception_error:
|
self._client.close()
|
||||||
self._log_error(str(exception_error))
|
except ModbusException as exception_error:
|
||||||
self._client = None
|
self._log_error(str(exception_error))
|
||||||
|
self._client = None
|
||||||
|
|
||||||
def _pymodbus_connect(self):
|
def _pymodbus_connect(self):
|
||||||
"""Connect client."""
|
"""Connect client."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user