Skip to content

Commit

Permalink
Account for disabled ZHA discovery config entries when migrating SkyC…
Browse files Browse the repository at this point in the history
…onnect integration (#117800)

* Properly handle disabled ZHA discovery config entries

* Update tests/components/homeassistant_sky_connect/test_util.py

Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>

---------

Co-authored-by: TheJulianJES <TheJulianJES@users.noreply.github.com>
  • Loading branch information
puddly and TheJulianJES committed May 21, 2024
1 parent 7714f80 commit 4dc6700
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 10 additions & 8 deletions homeassistant/components/homeassistant_sky_connect/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def get_hardware_variant(config_entry: ConfigEntry) -> HardwareVariant:
return HardwareVariant.from_usb_product_name(config_entry.data["product"])


def get_zha_device_path(config_entry: ConfigEntry) -> str:
def get_zha_device_path(config_entry: ConfigEntry) -> str | None:
"""Get the device path from a ZHA config entry."""
return cast(str, config_entry.data["device"]["path"])
return cast(str | None, config_entry.data.get("device", {}).get("path", None))


@singleton(OTBR_ADDON_MANAGER_DATA)
Expand Down Expand Up @@ -94,13 +94,15 @@ async def guess_firmware_type(hass: HomeAssistant, device_path: str) -> Firmware

for zha_config_entry in hass.config_entries.async_entries(ZHA_DOMAIN):
zha_path = get_zha_device_path(zha_config_entry)
device_guesses[zha_path].append(
FirmwareGuess(
is_running=(zha_config_entry.state == ConfigEntryState.LOADED),
firmware_type=ApplicationType.EZSP,
source="zha",

if zha_path is not None:
device_guesses[zha_path].append(
FirmwareGuess(
is_running=(zha_config_entry.state == ConfigEntryState.LOADED),
firmware_type=ApplicationType.EZSP,
source="zha",
)
)
)

if is_hassio(hass):
otbr_addon_manager = get_otbr_addon_manager(hass)
Expand Down
12 changes: 12 additions & 0 deletions tests/components/homeassistant_sky_connect/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ def test_get_zha_device_path() -> None:
)


def test_get_zha_device_path_ignored_discovery() -> None:
"""Test extracting the ZHA device path from an ignored ZHA discovery."""
config_entry = MockConfigEntry(
domain="zha",
unique_id="some_unique_id",
data={},
version=4,
)

assert get_zha_device_path(config_entry) is None


async def test_guess_firmware_type_unknown(hass: HomeAssistant) -> None:
"""Test guessing the firmware type."""

Expand Down

0 comments on commit 4dc6700

Please sign in to comment.