Skip to content

fix: update switch for JSON path syntax in async_setup_entry for array handling, refs #386#387

Merged
geertmeersman merged 1 commit into
mainfrom
dev-current
Jul 6, 2026
Merged

fix: update switch for JSON path syntax in async_setup_entry for array handling, refs #386#387
geertmeersman merged 1 commit into
mainfrom
dev-current

Conversation

@geertmeersman

@geertmeersman geertmeersman commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Fixed timer switch handling for devices that use array-based REST paths, improving reliability when loading and creating related switches.
    • Updated path handling so indexed values are resolved correctly during setup, helping ensure the expected switches appear and function properly.

@github-actions github-actions Bot added the patch A change requiring a patch version bump label Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The REST array-handling logic in the timer switch setup was updated to use bracket-style index placeholders ([0], [{idx}]) instead of dot-index placeholders (.0, .{idx}) when deriving arrays and rewriting rest and rest_attrs paths for each generated switch entity.

Changes

Placeholder Syntax Update

Layer / File(s) Summary
Bracket-index placeholder rewrite
custom_components/robonect/switch.py
Array derivation and per-item path rewriting for rest/rest_attrs now use [0]/[{idx}] instead of .0/.{idx}.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • geertmeersman/robonect#384: Same change to per-index REST JSON-path placeholder handling from dot-based to bracket-based format in async_setup_entry.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the async_setup_entry JSON path syntax change for array handling.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-current

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@geertmeersman geertmeersman changed the title fix: update switch for JSON path syntax in async_setup_entry for array handling fix: update switch for JSON path syntax in async_setup_entry for array handling, refs #386 Jul 6, 2026
@geertmeersman geertmeersman merged commit 2e9e77e into main Jul 6, 2026
9 of 10 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@custom_components/robonect/switch.py`:
- Around line 128-132: The switch setup logic in the robonect switch handling
should guard the result of get_json_dict_path() before iterating. In the code
that builds items from description.array, add the same missing-path check used
elsewhere so that if the array lookup returns None, the setup skips that entry
instead of calling enumerate on it. Use the existing description.array block and
the array variable in this switch path to place the guard immediately before the
loop.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22ddb6b8-ba3e-43be-bca3-b3c882d903bd

📥 Commits

Reviewing files that changed from the base of the PR and between f50b545 and ffbb78f.

📒 Files selected for processing (1)
  • custom_components/robonect/switch.py

Comment on lines 128 to 132
if description.array:
array = get_json_dict_path(
coordinator.data, description.rest_attrs.replace(".0", "")
coordinator.data, description.rest_attrs.replace("[0]", "")
)
for idx, item in enumerate(array):

Copy link
Copy Markdown

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## File sizes\n'
wc -l custom_components/robonect/utils.py custom_components/robonect/sensor.py custom_components/robonect/switch.py

printf '\n## utils.py: get_json_dict_path\n'
rg -n "def get_json_dict_path|return None|matches" custom_components/robonect/utils.py -A6 -B4

printf '\n## sensor.py: array handling\n'
rg -n "array = get_json_dict_path|if array is None|enumerate\\(array\\)" custom_components/robonect/sensor.py -A6 -B6

printf '\n## switch.py: array handling\n'
rg -n "array = get_json_dict_path|if array is None|enumerate\\(array\\)" custom_components/robonect/switch.py -A6 -B6

Repository: geertmeersman/robonect

Length of output: 3991


Guard array before iterating

get_json_dict_path() returns None when the array path is missing, so enumerate(array) can raise a TypeError here and abort switch setup. The sensor path already skips this case; add the same if array is None: continue check before the loop.

🐛 Proposed fix
                 if description.array:
                     array = get_json_dict_path(
                         coordinator.data, description.rest_attrs.replace("[0]", "")
                     )
+                    if array is None:
+                        continue
                     for idx, item in enumerate(array):
📝 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
if description.array:
array = get_json_dict_path(
coordinator.data, description.rest_attrs.replace(".0", "")
coordinator.data, description.rest_attrs.replace("[0]", "")
)
for idx, item in enumerate(array):
if description.array:
array = get_json_dict_path(
coordinator.data, description.rest_attrs.replace("[0]", "")
)
if array is None:
continue
for idx, item in enumerate(array):
🤖 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/robonect/switch.py` around lines 128 - 132, The switch
setup logic in the robonect switch handling should guard the result of
get_json_dict_path() before iterating. In the code that builds items from
description.array, add the same missing-path check used elsewhere so that if the
array lookup returns None, the setup skips that entry instead of calling
enumerate on it. Use the existing description.array block and the array variable
in this switch path to place the guard immediately before the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A change requiring a patch version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant