Removed asyncio locks

This commit is contained in:
Tomaae 2023-08-09 02:24:49 +02:00
parent 009d8c6085
commit 7c2e61e4d6
No known key found for this signature in database
GPG key ID: 2F97770867DAA4E6

View file

@ -156,8 +156,8 @@ class MikrotikCoordinator(DataUpdateCoordinator):
self.notified_flags = [] self.notified_flags = []
# self.listeners = [] # self.listeners = []
self.lock = asyncio.Lock() # self.lock = asyncio.Lock()
self.lock_ping = asyncio.Lock() # self.lock_ping = asyncio.Lock()
self.api = MikrotikAPI( self.api = MikrotikAPI(
config_entry.data[CONF_HOST], config_entry.data[CONF_HOST],
@ -481,10 +481,10 @@ class MikrotikCoordinator(DataUpdateCoordinator):
# --------------------------- # ---------------------------
async def async_hwinfo_update(self): async def async_hwinfo_update(self):
"""Update Mikrotik hardware info""" """Update Mikrotik hardware info"""
try: # try:
await asyncio.wait_for(self.lock.acquire(), timeout=30) # await asyncio.wait_for(self.lock.acquire(), timeout=30)
except Exception as error: # except Exception as error:
raise UpdateFailed(error) from error # raise UpdateFailed(error) from error
await self.hass.async_add_executor_job(self.get_access) await self.hass.async_add_executor_job(self.get_access)
@ -509,7 +509,7 @@ class MikrotikCoordinator(DataUpdateCoordinator):
if self.api.connected(): if self.api.connected():
await self.hass.async_add_executor_job(self.get_dns) await self.hass.async_add_executor_job(self.get_dns)
self.lock.release() # self.lock.release()
# --------------------------- # ---------------------------
# force_fwupdate_check # force_fwupdate_check
@ -538,10 +538,10 @@ class MikrotikCoordinator(DataUpdateCoordinator):
if "test" not in self.data["access"]: if "test" not in self.data["access"]:
return return
try: # try:
await asyncio.wait_for(self.lock_ping.acquire(), timeout=3) # await asyncio.wait_for(self.lock_ping.acquire(), timeout=3)
except Exception: # except Exception:
return # return
for uid in list(self.data["host"]): for uid in list(self.data["host"]):
if not self.host_tracking_initialized: if not self.host_tracking_initialized:
@ -585,7 +585,7 @@ class MikrotikCoordinator(DataUpdateCoordinator):
self.data["host"][uid]["last-seen"] = utcnow() self.data["host"][uid]["last-seen"] = utcnow()
self.host_tracking_initialized = True self.host_tracking_initialized = True
self.lock_ping.release() # self.lock_ping.release()
# --------------------------- # ---------------------------
# _async_update_data # _async_update_data
@ -598,10 +598,10 @@ class MikrotikCoordinator(DataUpdateCoordinator):
if self.api.has_reconnected(): if self.api.has_reconnected():
await self.async_hwinfo_update() await self.async_hwinfo_update()
try: # try:
await asyncio.wait_for(self.lock.acquire(), timeout=10) # await asyncio.wait_for(self.lock.acquire(), timeout=10)
except Exception as error: # except Exception as error:
raise UpdateFailed(error) from error # raise UpdateFailed(error) from error
await self.hass.async_add_executor_job(self.get_system_resource) await self.hass.async_add_executor_job(self.get_system_resource)
@ -680,7 +680,7 @@ class MikrotikCoordinator(DataUpdateCoordinator):
if self.api.connected() and self.support_gps: if self.api.connected() and self.support_gps:
await self.hass.async_add_executor_job(self.get_gps) await self.hass.async_add_executor_job(self.get_gps)
self.lock.release() # self.lock.release()
# async_dispatcher_send(self.hass, "update_sensors", self) # async_dispatcher_send(self.hass, "update_sensors", self)
return self.data return self.data