Fix up config flow

This commit is contained in:
puddly
2025-01-03 15:32:15 -05:00
parent d07ecd8899
commit 94f964cdd6
2 changed files with 32 additions and 25 deletions

View File

@@ -25,12 +25,14 @@ from homeassistant.data_entry_flow import AbortFlow
from homeassistant.helpers.hassio import is_hassio from homeassistant.helpers.hassio import is_hassio
from . import silabs_multiprotocol_addon from . import silabs_multiprotocol_addon
from .const import ZHA_DOMAIN from .const import OTBR_DOMAIN, ZHA_DOMAIN
from .util import ( from .util import (
ApplicationType, ApplicationType,
OwningAddon,
OwningIntegration,
get_otbr_addon_manager, get_otbr_addon_manager,
get_zha_device_path,
get_zigbee_flasher_addon_manager, get_zigbee_flasher_addon_manager,
guess_hardware_owners,
probe_silabs_firmware_type, probe_silabs_firmware_type,
) )
@@ -519,15 +521,11 @@ class BaseFirmwareOptionsFlow(BaseFirmwareInstallFlow, OptionsFlow):
) -> ConfigFlowResult: ) -> ConfigFlowResult:
"""Pick Zigbee firmware.""" """Pick Zigbee firmware."""
assert self._device is not None assert self._device is not None
owners = await guess_hardware_owners(self.hass, self._device)
if is_hassio(self.hass): for info in owners:
otbr_manager = get_otbr_addon_manager(self.hass) for owner in info.owners:
otbr_addon_info = await self._async_get_addon_info(otbr_manager) if info.source == OTBR_DOMAIN and isinstance(owner, OwningAddon):
if (
otbr_addon_info.state != AddonState.NOT_INSTALLED
and otbr_addon_info.options.get("device") == self._device
):
raise AbortFlow( raise AbortFlow(
"otbr_still_using_stick", "otbr_still_using_stick",
description_placeholders=self._get_translation_placeholders(), description_placeholders=self._get_translation_placeholders(),
@@ -541,12 +539,11 @@ class BaseFirmwareOptionsFlow(BaseFirmwareInstallFlow, OptionsFlow):
"""Pick Thread firmware.""" """Pick Thread firmware."""
assert self._device is not None assert self._device is not None
for zha_entry in self.hass.config_entries.async_entries( owners = await guess_hardware_owners(self.hass, self._device)
ZHA_DOMAIN,
include_ignore=False, for info in owners:
include_disabled=True, for owner in info.owners:
): if info.source == ZHA_DOMAIN and isinstance(owner, OwningIntegration):
if get_zha_device_path(zha_entry) == self._device:
raise AbortFlow( raise AbortFlow(
"zha_still_using_stick", "zha_still_using_stick",
description_placeholders=self._get_translation_placeholders(), description_placeholders=self._get_translation_placeholders(),

View File

@@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
import asyncio
from collections import defaultdict from collections import defaultdict
from collections.abc import Iterable from collections.abc import Iterable
from dataclasses import dataclass from dataclasses import dataclass
@@ -133,6 +134,14 @@ class FirmwareInfo:
source: str source: str
owners: list[OwningAddon | OwningIntegration] owners: list[OwningAddon | OwningIntegration]
async def is_running(self, hass: HomeAssistant) -> bool:
"""Check if the firmware owner is running."""
states = await asyncio.gather(*(o.is_running(hass) for o in self.owners))
if not states:
return False
return all(states)
async def get_zha_firmware_info( async def get_zha_firmware_info(
hass: HomeAssistant, config_entry: ConfigEntry hass: HomeAssistant, config_entry: ConfigEntry
@@ -155,7 +164,7 @@ async def get_zha_firmware_info(
if config_entry.data["radio_type"] != "ezsp": if config_entry.data["radio_type"] != "ezsp":
return None return None
device = config_entry.data.get("device", {}).get("device_path", None) device = config_entry.data.get("device", {}).get("path", None)
if device is None: if device is None:
return None return None
@@ -209,6 +218,7 @@ async def guess_hardware_owners(
if firmware_info is not None: if firmware_info is not None:
device_guesses[firmware_info.device].append(firmware_info) device_guesses[firmware_info.device].append(firmware_info)
# We assume that the OTBR integration will always be set up, even without the addon
for otbr_config_entry in hass.config_entries.async_entries(OTBR_DOMAIN): for otbr_config_entry in hass.config_entries.async_entries(OTBR_DOMAIN):
firmware_info = await get_otbr_firmware_info(hass, otbr_config_entry) firmware_info = await get_otbr_firmware_info(hass, otbr_config_entry)