mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-13 19:04:30 +02:00
run async_hwinfo_update after reconnect
This commit is contained in:
parent
345211570a
commit
19e7174446
2 changed files with 22 additions and 3 deletions
|
@ -245,10 +245,12 @@ class MikrotikControllerData:
|
||||||
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=10)
|
await asyncio.wait_for(self.lock.acquire(), timeout=30)
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
_LOGGER.warning("Running async_hwinfo_update")
|
||||||
|
|
||||||
await self.hass.async_add_executor_job(self.get_capabilities)
|
await self.hass.async_add_executor_job(self.get_capabilities)
|
||||||
await self.hass.async_add_executor_job(self.get_system_routerboard)
|
await self.hass.async_add_executor_job(self.get_system_routerboard)
|
||||||
await self.hass.async_add_executor_job(self.get_system_resource)
|
await self.hass.async_add_executor_job(self.get_system_resource)
|
||||||
|
@ -343,6 +345,9 @@ class MikrotikControllerData:
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update Mikrotik data"""
|
"""Update Mikrotik data"""
|
||||||
|
if self.api.has_reconnected():
|
||||||
|
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:
|
except:
|
||||||
|
|
|
@ -48,6 +48,7 @@ class MikrotikAPI:
|
||||||
|
|
||||||
self._connection = None
|
self._connection = None
|
||||||
self._connected = False
|
self._connected = False
|
||||||
|
self._reconnected = False
|
||||||
self._connection_epoch = 0
|
self._connection_epoch = 0
|
||||||
self._connection_retry_sec = 58
|
self._connection_retry_sec = 58
|
||||||
self.error = None
|
self.error = None
|
||||||
|
@ -58,6 +59,17 @@ class MikrotikAPI:
|
||||||
if not self._port:
|
if not self._port:
|
||||||
self._port = 8729 if self._use_ssl else 8728
|
self._port = 8729 if self._use_ssl else 8728
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# has_reconnected
|
||||||
|
# ---------------------------
|
||||||
|
def has_reconnected(self) -> bool:
|
||||||
|
"""Check if mikrotik has reconnected"""
|
||||||
|
if self._reconnected:
|
||||||
|
self._reconnected = False
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# connection_check
|
# connection_check
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -90,6 +102,7 @@ class MikrotikAPI:
|
||||||
|
|
||||||
self.connection_error_reported = True
|
self.connection_error_reported = True
|
||||||
|
|
||||||
|
self._reconnected = False
|
||||||
self._connected = False
|
self._connected = False
|
||||||
self._connection = None
|
self._connection = None
|
||||||
self._connection_epoch = 0
|
self._connection_epoch = 0
|
||||||
|
@ -100,7 +113,7 @@ class MikrotikAPI:
|
||||||
def connect(self) -> bool:
|
def connect(self) -> bool:
|
||||||
"""Connect to Mikrotik device."""
|
"""Connect to Mikrotik device."""
|
||||||
self.error = ""
|
self.error = ""
|
||||||
self._connected = None
|
self._connected = False
|
||||||
self._connection_epoch = time()
|
self._connection_epoch = time()
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
|
@ -161,6 +174,7 @@ class MikrotikAPI:
|
||||||
_LOGGER.debug("Mikrotik Connected to %s", self._host)
|
_LOGGER.debug("Mikrotik Connected to %s", self._host)
|
||||||
|
|
||||||
self._connected = True
|
self._connected = True
|
||||||
|
self._reconnected = True
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
return self._connected
|
return self._connected
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue