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:
Steven B.
2024-07-30 19:23:07 +01:00
committed by GitHub
parent 445f74eed7
commit 7bba9926ed
23 changed files with 264 additions and 187 deletions

View File

@@ -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):