Skip to content

Relay config#416

Open
dirixmjm wants to merge 15 commits intomainfrom
relay_config
Open

Relay config#416
dirixmjm wants to merge 15 commits intomainfrom
relay_config

Conversation

@dirixmjm
Copy link
Contributor

@dirixmjm dirixmjm commented Mar 9, 2026

Add try/except around self.coordinator.data.get and raise UpdateFailed

Summary by CodeRabbit

  • Chores

    • Bumped release to 0.59.2a0 and updated plugwise_usb to v0.47.5
    • Added an "Ongoing" changelog entry
  • Bug Fixes

    • Improved defensive error handling across sensors, switches, numbers, selects and events to reduce update failures
  • Refactor

    • Adjusted relay_init attribute mapping for compatibility with the updated library

@dirixmjm dirixmjm requested a review from a team as a code owner March 9, 2026 19:11
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

Warning

Rate limit exceeded

@bouwew has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6b012297-7dca-41bd-9352-15e94baed2c1

📥 Commits

Reviewing files that changed from the base of the PR and between 9b08c26 and 35db760.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • custom_components/plugwise_usb/binary_sensor.py
  • custom_components/plugwise_usb/coordinator.py
  • custom_components/plugwise_usb/event.py
  • custom_components/plugwise_usb/manifest.json
  • custom_components/plugwise_usb/number.py
  • custom_components/plugwise_usb/select.py
  • custom_components/plugwise_usb/sensor.py
  • custom_components/plugwise_usb/switch.py
  • pyproject.toml

Walkthrough

Version bumped to 0.59.2a0 and plugwise-usb requirement updated to 0.47.5. Multiple entity update handlers now catch AttributeError when accessing coordinator.data and raise UpdateFailed. Coordinator exception handling consolidated to raise UpdateFailed for Node/Stick errors and timeouts. relay_init API attribute changed to init_state.

Changes

Cohort / File(s) Summary
Version & Changelog
CHANGELOG.md, pyproject.toml, custom_components/plugwise_usb/manifest.json
Bumped integration version to 0.59.2a0 and plugwise-usb requirement to 0.47.5; added "Ongoing" entry in changelog.
Entity update defensive handling
custom_components/plugwise_usb/binary_sensor.py, custom_components/plugwise_usb/event.py, custom_components/plugwise_usb/select.py, custom_components/plugwise_usb/sensor.py, custom_components/plugwise_usb/number.py
Wrapped self.coordinator.data access in try/except AttributeError and raise UpdateFailed on failure; imported UpdateFailed where needed.
Switch entity change
custom_components/plugwise_usb/switch.py
Updated relay_init attribute reference from "state" to "init_state" and added the same AttributeError → UpdateFailed defensive handling.
Coordinator exceptions
custom_components/plugwise_usb/coordinator.py
Replaced multiple granular exception branches with a unified catch that raises UpdateFailed for NodeError, NodeTimeout, StickError, and StickTimeout.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • CoMPaTech
  • bouwew

Poem

🐇 Hopping through the coordinator glen,
I catch AttributeErrors now and then.
Unified failures, tidy and spry,
Versions bumped — we leap sky-high! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Relay config' is vague and does not clearly summarize the main change, which is adding try/except error handling around coordinator data access across multiple entity files. Consider a more descriptive title that captures the primary intent, such as 'Add UpdateFailed exception handling for coordinator data access' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch relay_config

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Around line 3-5: Update the changelog entry: remove the markdownlint-offending
heading colon by changing "## Ongoing:" to "## Ongoing" (or the project's
preferred section header), and correct the bullet text from "Link to
plugwise_usb v0.47.4" to reference the actual shipped package version
"plugwise-usb==0.47.5" and keep the note about "change relay_init api_attribute"
so the entry matches the manifest.json package version.

In `@custom_components/plugwise_usb/coordinator.py`:
- Around line 78-79: The except block catching NodeError, NodeTimeout,
StickError, and StickTimeout should raise UpdateFailed including the backend
error text so the message logged by DataUpdateCoordinator._async_refresh() is
informative; update the exception raised in the except clause (around the code
that currently does "raise UpdateFailed from err") to construct an UpdateFailed
with a descriptive string that incorporates err (e.g., f"backend error: {err}")
while still using "from err" to preserve the chain, so callers of the
coordinator (and logs) show the backend error details.

In `@custom_components/plugwise_usb/switch.py`:
- Around line 177-180: The exception handler in _handle_coordinator_update
catches AttributeError and raises UpdateFailed, but UpdateFailed is not imported
and the try/except block uses inconsistent 3-space indentation; add the missing
import "from homeassistant.helpers.update_coordinator import UpdateFailed" at
the top of the file and correct the indentation in the
_handle_coordinator_update method so the try/except and the line accessing
self.coordinator.data.get(self.entity_description.node_feature, None) use the
standard 4-space indentation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 099422fe-7a00-4cda-9de4-e8b822107a87

📥 Commits

Reviewing files that changed from the base of the PR and between db802e8 and 2cb9b36.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • custom_components/plugwise_usb/binary_sensor.py
  • custom_components/plugwise_usb/coordinator.py
  • custom_components/plugwise_usb/event.py
  • custom_components/plugwise_usb/manifest.json
  • custom_components/plugwise_usb/select.py
  • custom_components/plugwise_usb/sensor.py
  • custom_components/plugwise_usb/switch.py
  • pyproject.toml

CHANGELOG.md Outdated
Comment on lines +3 to +5
## Ongoing:

- Link to plugwise_usb v0.47.4, change relay_init api_attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the release note entry before merging.

This hunk currently does two wrong things: ## Ongoing: is the markdownlint failure from CI, and the bullet still says v0.47.4 while this PR ships plugwise-usb==0.47.5 in custom_components/plugwise_usb/manifest.json.

📝 Proposed fix
-## Ongoing:
+## Ongoing
 
-- Link to plugwise_usb v0.47.4, change relay_init api_attribute
+- Link to plugwise_usb v0.47.5, change relay_init api_attribute
📝 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
## Ongoing:
- Link to plugwise_usb v0.47.4, change relay_init api_attribute
## Ongoing
- Link to plugwise_usb v0.47.5, change relay_init api_attribute
🧰 Tools
🪛 GitHub Actions: Test against HA-core

[error] 3-3: markdownlint: MD026/no-trailing-punctuation Trailing punctuation in heading: trailing ':' should be removed from the heading.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 3 - 5, Update the changelog entry: remove the
markdownlint-offending heading colon by changing "## Ongoing:" to "## Ongoing"
(or the project's preferred section header), and correct the bullet text from
"Link to plugwise_usb v0.47.4" to reference the actual shipped package version
"plugwise-usb==0.47.5" and keep the note about "change relay_init api_attribute"
so the entry matches the manifest.json package version.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
CHANGELOG.md (1)

3-5: ⚠️ Potential issue | 🟡 Minor

Update the version number to match manifest.json.

The markdownlint issue has been resolved (heading no longer has trailing colon), but the version number still needs correction. Line 5 references "v0.47.4" while the PR ships "plugwise-usb==0.47.5" in manifest.json.

📝 Proposed fix
 ## Ongoing
 
-- Link to plugwise_usb v0.47.4, change relay_init api_attribute
+- Link to plugwise_usb v0.47.5, change relay_init api_attribute
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 3 - 5, Update the version string in the changelog
entry that currently reads "v0.47.4" to match the package version in
manifest.json ("plugwise-usb==0.47.5"); specifically edit the line containing
"Link to plugwise_usb v0.47.4, change relay_init api_attribute" (or the "Link to
plugwise_usb" changelog entry) so it references v0.47.5 instead of v0.47.4.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@custom_components/plugwise_usb/number.py`:
- Around line 244-247: In _handle_coordinator_update callbacks (e.g., the method
_handle_coordinator_update in number.py, switch.py, sensor.py, select.py,
event.py, binary_sensor.py) remove the try/except that raises UpdateFailed from
listener callbacks; instead perform a null-check on
self.coordinator.data.get(self.entity_description.node_feature) and if the value
is None log a debug/warning via the entity's logger and return early (do not
raise UpdateFailed), and also fix the 3-space indentation to the project
standard (use 4-space indentation) so the code block is consistently formatted.
Ensure you keep references to self.coordinator.data and
self.entity_description.node_feature and do not modify
coordinator.async_update() behavior.

In `@custom_components/plugwise_usb/select.py`:
- Around line 117-120: The listener _handle_coordinator_update should not raise
UpdateFailed from inside the callback; instead catch AttributeError when
accessing self.coordinator.data (e.g.,
self.coordinator.data.get(self.entity_description.node_feature, None)), log the
error and return early so the exception does not escape the listener and bypass
coordinator retry logic; also fix the inconsistent 3-space indentation to match
the surrounding 4-space style for the try/except block.

In `@custom_components/plugwise_usb/sensor.py`:
- Around line 224-227: In _handle_coordinator_update (the listener callback)
avoid raising UpdateFailed when self.coordinator.data is missing; instead catch
AttributeError around accessing self.coordinator.data and log the exception (or
a warning including self.entity_description.node_feature) and return early so
the listener does not propagate an unhandled exception; also fix the indentation
to 4 spaces for the try/except block and reference the exact symbols
self.coordinator.data and self.entity_description.node_feature when making the
change.

---

Duplicate comments:
In `@CHANGELOG.md`:
- Around line 3-5: Update the version string in the changelog entry that
currently reads "v0.47.4" to match the package version in manifest.json
("plugwise-usb==0.47.5"); specifically edit the line containing "Link to
plugwise_usb v0.47.4, change relay_init api_attribute" (or the "Link to
plugwise_usb" changelog entry) so it references v0.47.5 instead of v0.47.4.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6badad9b-5d92-40b0-bb70-9d388ad9ddbe

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb9b36 and 9b08c26.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • custom_components/plugwise_usb/binary_sensor.py
  • custom_components/plugwise_usb/event.py
  • custom_components/plugwise_usb/number.py
  • custom_components/plugwise_usb/select.py
  • custom_components/plugwise_usb/sensor.py
  • custom_components/plugwise_usb/switch.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • custom_components/plugwise_usb/switch.py
  • custom_components/plugwise_usb/binary_sensor.py
  • custom_components/plugwise_usb/event.py

@sonarqubecloud
Copy link

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants