FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Keep hub children when the child component list is missing by Richardtristan · Pull Request #1797 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 16 additions & 2 deletions kasa/smart/smartdevice.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,23 @@ async def _create_delete_children(
can't be created to avoid spamming the logs on every update.
"""
changed = False
if (
child_component_list := child_device_components_resp.get(
"child_component_list"
)
) is None:
# Some hubs intermittently return the component list without the
# list itself, e.g. an H200 without children. Keep the known children
# instead of deleting them, the next update will reconcile.
_LOGGER.debug(
"No child component list for device %s, response: %s",
self.host,
child_device_components_resp,
)
return changed

smart_children_components = {
child["device_id"]: child
for child in child_device_components_resp["child_component_list"]
child["device_id"]: child for child in child_component_list
}
children = self._children
child_ids: set[str] = set()
Expand Down
27 changes: 27 additions & 0 deletions tests/smart/test_smartdevice.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,19 @@ def mock_get_child_device_queries(method, params):
expected_new_length -= 1
assert len(dev.children) == expected_new_length

# Test component list response without the list keeps the known children

saved_child_device_components = mock_child_device_components
mock_child_device_components = {}

with patch.object(
transport, "get_child_device_queries", side_effect=mock_get_child_device_queries
):
await dev.update()

assert len(dev.children) == expected_new_length
mock_child_device_components = saved_child_device_components

# Test no child devices

mock_child_device_info["child_device_list"] = []
Expand All @@ -890,6 +903,20 @@ def mock_get_child_device_queries(method, params):

assert len(dev.children) == 0

# Test component list response without the list on a hub without children,
# as returned intermittently by some hubs (e.g. H200 firmware 1.7.7)

saved_child_device_components = mock_child_device_components
mock_child_device_components = {}

with patch.object(
transport, "get_child_device_queries", side_effect=mock_get_child_device_queries
):
await dev.update()

assert len(dev.children) == 0
mock_child_device_components = saved_child_device_components

# Logging tests are only for smartcam hubs as smart hubs do not test categories
if not isinstance(dev, SmartCamDevice):
return
Expand Down
Loading

Back | FazBrowse Home | New Git URL