mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Allow erroring modules to recover (#1080)
Re-query failed modules after some delay instead of immediately disabling them. Changes to features so they can still be created when modules are erroring.
This commit is contained in:
@@ -10,6 +10,7 @@ from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..smartprotocol import SmartProtocol, _ChildProtocolWrapper
|
||||
from .smartdevice import SmartDevice
|
||||
from .smartmodule import SmartModule
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -49,13 +50,21 @@ class SmartChildDevice(SmartDevice):
|
||||
Internal implementation to allow patching of public update in the cli
|
||||
or test framework.
|
||||
"""
|
||||
now = time.monotonic()
|
||||
module_queries: list[SmartModule] = []
|
||||
req: dict[str, Any] = {}
|
||||
for module in self.modules.values():
|
||||
if mod_query := module.query():
|
||||
if module.disabled is False and (mod_query := module.query()):
|
||||
module_queries.append(module)
|
||||
req.update(mod_query)
|
||||
if req:
|
||||
self._last_update = await self.protocol.query(req)
|
||||
self._last_update_time = time.time()
|
||||
|
||||
for module in self.modules.values():
|
||||
self._handle_module_post_update(
|
||||
module, now, had_query=module in module_queries
|
||||
)
|
||||
self._last_update_time = now
|
||||
|
||||
@classmethod
|
||||
async def create(cls, parent: SmartDevice, child_info, child_components):
|
||||
|
Reference in New Issue
Block a user