Skip to content
Draft
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
34 changes: 34 additions & 0 deletions tests/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,3 +997,37 @@ async def test_entityless_cluster_binds_via_virtual_entity(
await zha_gateway.async_block_till_done(wait_background_tasks=True)

assert len(philips_cluster.bind.mock_calls) == 1


async def test_entity_creation_failure_is_skipped(
zha_gateway: Gateway,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test discovery skips (and logs) an entity that fails to instantiate."""
zigpy_device = create_mock_zigpy_device(
zha_gateway,
{
1: {
SIG_EP_INPUT: [
zigpy.zcl.clusters.general.Basic.cluster_id,
zigpy.zcl.clusters.general.OnOff.cluster_id,
],
SIG_EP_OUTPUT: [],
SIG_EP_TYPE: zigpy.profiles.zha.DeviceType.ON_OFF_SWITCH,
SIG_EP_PROFILE: zigpy.profiles.zha.PROFILE_ID,
}
},
)
Comment on lines +1007 to +1020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We instead want to create zigpy device from diagnostics files, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally just find it to be a simpler pattern to read, since the diagnostics JSON contains more data to fully initialize a ZHA device. If you think manually creating a device is easier, let's do it.


with mock.patch(
"zha.application.platforms.switch.Switch.__init__",
side_effect=RuntimeError("boom"),
):
zha_device = await join_zigpy_device(zha_gateway, zigpy_device)

# The broad except logged the failure and let discovery continue.
assert "Failed to create Switch entity" in caplog.text

# The switch entity was skipped, but the device still joined.
with pytest.raises(KeyError):
get_entity(zha_device, platform=Platform.SWITCH)
Loading