Test broad except when entity creation fails during discovery#822
Draft
TheJulianJES wants to merge 1 commit into
Draft
Test broad except when entity creation fails during discovery#822TheJulianJES wants to merge 1 commit into
except when entity creation fails during discovery#822TheJulianJES wants to merge 1 commit into
Conversation
`discover_entities_for_endpoint` wraps each entity instantiation in a broad `except` so one broken entity is skipped (and logged) rather than aborting discovery for the whole endpoint. This path was previously only exercised incidentally; #821 removed the `BinarySensor._state = self.is_on` init call that used to trip it, leaving discovery.py:355-357 uncovered. Add an explicit test: patch `Switch.__init__` to raise, join the device, and assert the failure is logged and the switch entity skipped while the device still joins.
TheJulianJES
commented
Jul 9, 2026
Comment on lines
+1007
to
+1020
| 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, | ||
| } | ||
| }, | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
We instead want to create zigpy device from diagnostics files, right?
Contributor
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #822 +/- ##
==========================================
+ Coverage 97.27% 97.30% +0.02%
==========================================
Files 55 55
Lines 10930 10930
==========================================
+ Hits 10632 10635 +3
+ Misses 298 295 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses comment in:
_stateattribute from binary sensors #821 (comment)What
Adds a test for the broad
exceptindiscover_entities_for_endpointthat skips (and logs) an entity whose instantiation raises, instead of aborting discovery for the rest of the endpoint.Why
discover_entities_for_endpointwraps each entity instantiation in a broadexcept(discovery.py:355-357, logging"Failed to create %s entity"). This path used to be exercised incidentally:BinarySensor.__init__calledself._state = self.is_on, which could raise and trip the except. #821 removed that dead_stateassignment, so the except was no longer covered by the suite (entities that would fail are now filtered out earlier via_is_supported).The test creates an on/off switch device, patches
Switch.__init__to raise, joins the device, and asserts the failure is logged and the switch entity is skipped while the device still joins.