mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix race setting up homekit controller triggers (#83166)
fixes https://github.com/home-assistant/core/issues/83165
This commit is contained in:
parent
144f1b918b
commit
cc105e5c27
@ -21,7 +21,7 @@ from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .config_flow import normalize_hkid
|
||||
from .connection import HKDevice
|
||||
from .const import KNOWN_DEVICES, TRIGGERS
|
||||
from .const import KNOWN_DEVICES
|
||||
from .utils import async_get_controller
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -59,7 +59,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
await async_get_controller(hass)
|
||||
|
||||
hass.data[KNOWN_DEVICES] = {}
|
||||
hass.data[TRIGGERS] = {}
|
||||
|
||||
async def _async_stop_homekit_controller(event: Event) -> None:
|
||||
await asyncio.gather(
|
||||
|
@ -224,7 +224,7 @@ async def async_setup_triggers_for_entry(
|
||||
# They have to be different accessories (they can be on the same bridge)
|
||||
# In practice, this is inline with what iOS actually supports AFAWCT.
|
||||
device_id = conn.devices[aid]
|
||||
if device_id in hass.data[TRIGGERS]:
|
||||
if TRIGGERS in hass.data and device_id in hass.data[TRIGGERS]:
|
||||
return False
|
||||
|
||||
# Just because we recognize the service type doesn't mean we can actually
|
||||
@ -246,15 +246,18 @@ def async_get_or_create_trigger_source(
|
||||
hass: HomeAssistant, device_id: str
|
||||
) -> TriggerSource:
|
||||
"""Get or create a trigger source for a device id."""
|
||||
if not (source := hass.data[TRIGGERS].get(device_id)):
|
||||
trigger_sources: dict[str, TriggerSource] = hass.data.setdefault(TRIGGERS, {})
|
||||
if not (source := trigger_sources.get(device_id)):
|
||||
source = TriggerSource(hass)
|
||||
hass.data[TRIGGERS][device_id] = source
|
||||
trigger_sources[device_id] = source
|
||||
return source
|
||||
|
||||
|
||||
def async_fire_triggers(conn: HKDevice, events: dict[tuple[int, int], dict[str, Any]]):
|
||||
"""Process events generated by a HomeKit accessory into automation triggers."""
|
||||
trigger_sources: dict[str, TriggerSource] = conn.hass.data[TRIGGERS]
|
||||
trigger_sources: dict[str, TriggerSource] = conn.hass.data.get(TRIGGERS, {})
|
||||
if not trigger_sources:
|
||||
return
|
||||
for (aid, iid), ev in events.items():
|
||||
if aid in conn.devices:
|
||||
device_id = conn.devices[aid]
|
||||
|
Loading…
x
Reference in New Issue
Block a user