Defer xiaomi ble polling until after startup (#83074)

fixes https://github.com/home-assistant/core/issues/77178
pull/83077/head
J. Nick Koston 2022-12-01 11:37:22 -10:00 committed by GitHub
parent 18e4c065eb
commit e23007322d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -17,7 +17,7 @@ from homeassistant.components.bluetooth.active_update_coordinator import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import CoreState, HomeAssistant
from .const import DOMAIN
@ -60,7 +60,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
def _needs_poll(
service_info: BluetoothServiceInfoBleak, last_poll: float | None
) -> bool:
return data.poll_needed(service_info, last_poll)
# Only poll if hass is running, we need to poll,
# and we actually have a way to connect to the device
return (
hass.state == CoreState.running
and data.poll_needed(service_info, last_poll)
and bool(
async_ble_device_from_address(
hass, service_info.device.address, connectable=True
)
)
)
async def _async_poll(service_info: BluetoothServiceInfoBleak):
# BluetoothServiceInfoBleak is defined in HA, otherwise would just pass it