Skip to content

Reprioritize joining and initialization requests #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions zha/application/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asyncio
from collections.abc import AsyncGenerator
from contextlib import suppress
from contextlib import asynccontextmanager, suppress
from dataclasses import dataclass
from datetime import timedelta
from enum import Enum
Expand Down Expand Up @@ -275,6 +275,14 @@ async def async_initialize(self) -> None:
await self.shutdown()
raise

@asynccontextmanager
async def request_priority(
self, priority: t.PacketPriority | None
) -> AsyncGenerator[None, None]:
"""Context manager to request a priority for radio access."""
async with self.application_controller.request_priority(priority):
yield

def connection_lost(self, exc: Exception) -> None:
"""Handle connection lost event."""
_LOGGER.debug("Connection to the radio was lost: %r", exc)
Expand Down Expand Up @@ -371,7 +379,8 @@ async def async_initialize_devices_and_entities(self) -> None:
async def fetch_updated_state() -> None:
"""Fetch updated state for mains powered devices."""
if self.config.config.device_options.enable_mains_startup_polling:
await self.async_fetch_updated_state_mains()
async with self.request_priority(t.PacketPriority.LOW):
await self.async_fetch_updated_state_mains()
else:
_LOGGER.debug("Polling of mains powered devices at startup is disabled")
_LOGGER.debug("Allowing polled requests")
Expand Down Expand Up @@ -615,8 +624,9 @@ async def _async_device_joined(self, zha_device: Device) -> None:
zha_device.available = True
zha_device.on_network = True

await zha_device.async_configure()
await zha_device.async_initialize()
async with self.request_priority(t.PacketPriority.HIGH):
await zha_device.async_configure()
await zha_device.async_initialize()

self.emit(
ZHA_GW_MSG_DEVICE_FULL_INIT,
Expand Down
Loading