Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 7 additions & 13 deletions custom_components/daikin_onecta/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,19 @@ async def async_setup_entry(
coordinator = onecta_data.coordinator

entities: list[DaikinFirmwareUpdateEntity] = []
supported_management_point_types = {
"gateway",
"userInterface",
"outdoorUnit",
"indoorUnitHydro",
}
required_version_fields = {
"firmwareVersion",
"softwareVersion",
}

for device in onecta_data.devices.values():
for mp_type in supported_management_point_types:
management_point = _get_management_point(device, mp_type)
if management_point is not None:
for field in required_version_fields:
if _get_value(management_point, field) is not None:
entities.append(DaikinFirmwareUpdateEntity(coordinator, device, management_point, mp_type))
break
management_points = device.daikin_data.get("managementPoints", [])
for management_point in management_points:
management_point_type = management_point["managementPointType"]

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Guard managementPointType access to avoid setup crashes.

Line 57 can raise KeyError if a malformed management point lacks managementPointType, which would fail async_setup_entry for the whole device batch. Use .get() and skip invalid points.

Proposed fix
     for device in onecta_data.devices.values():
         management_points = device.daikin_data.get("managementPoints", [])
         for management_point in management_points:
-            management_point_type = management_point["managementPointType"]
+            management_point_type = management_point.get("managementPointType")
+            if not management_point_type:
+                continue
             for field in required_version_fields:
                 if _get_value(management_point, field) is not None:
                     entities.append(DaikinFirmwareUpdateEntity(coordinator, device, management_point, management_point_type))
                     break
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
management_point_type = management_point["managementPointType"]
management_point_type = management_point.get("managementPointType")
if not management_point_type:
continue
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@custom_components/daikin_onecta/update.py` at line 57, The management point
parsing in async_setup_entry can crash if a point is missing
managementPointType. Update the management_point handling in update.py to use
management_point.get("managementPointType") instead of direct indexing, and skip
any invalid entries before they reach the setup flow. Use the management_point
variable and the async_setup_entry/update logic to locate the fix.

for field in required_version_fields:
if _get_value(management_point, field) is not None:
entities.append(DaikinFirmwareUpdateEntity(coordinator, device, management_point, management_point_type))
break

async_add_entities(entities)

Expand Down
Loading
Loading