Skip to content

Also add entities to device diagnostics#614

Merged
jwillemsen merged 7 commits intomasterfrom
jwi-entitieslogging
Jan 30, 2026
Merged

Also add entities to device diagnostics#614
jwillemsen merged 7 commits intomasterfrom
jwi-entitieslogging

Conversation

@jwillemsen
Copy link
Copy Markdown
Owner

@jwillemsen jwillemsen commented Jan 30, 2026

* custom_components/daikin_onecta/diagnostics.py:

Summary by CodeRabbit

  • Chores
    • Enhanced diagnostic data collection to include more comprehensive entity information for improved troubleshooting support.

✏️ Tip: You can customize this high-level summary in your review settings.

    * custom_components/daikin_onecta/diagnostics.py:
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 30, 2026

Warning

Rate limit exceeded

@jwillemsen has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 46 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.

Walkthrough

A new helper function get_entitities() was introduced to centralize entity metadata collection (entity_id, unique_id, platform, original_name, disabled, translation_key, state, attributes) for a config entry. Both diagnostic functions now call this helper instead of inlining entity collection logic.

Changes

Cohort / File(s) Summary
Diagnostics Helper Extraction
custom_components/daikin_onecta/diagnostics.py
Introduced get_entitities() helper function to collect entity metadata. Refactored async_get_config_entry_diagnostics and async_get_device_diagnostics to use the helper for including entities in diagnostic payloads.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A helper hops in, code so neat,
Entities gathered, refactored sweet,
No more duplication, clean and tight,
Diagnostics now shine with diagnostic light! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Also add entities to device diagnostics' directly reflects the main change: extending device diagnostics to include entity information via the new get_entitities helper.

✏️ 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 jwi-entitieslogging

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.

    * custom_components/daikin_onecta/diagnostics.py:
Copy link
Copy Markdown
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
custom_components/daikin_onecta/diagnostics.py (2)

14-66: ⚠️ Potential issue | 🟠 Major

Scope device diagnostics to the requested device.

async_get_device_diagnostics currently returns all entities from the config entry, which leaks unrelated entities when multiple devices exist under one entry. Filter by entity_entry.device_id and pass device.id to the helper.

Proposed fix (device filter)
-def get_entitities(hass: HomeAssistant, config_entry: ConfigEntry):
+def get_entitities(
+    hass: HomeAssistant,
+    config_entry: ConfigEntry,
+    *,
+    device_id: str | None = None,
+):
     entity_registry = er.async_get(hass)
     entities_data: dict[str, dict[str, Any]] = {}
 
     for entity_entry in er.async_entries_for_config_entry(entity_registry, config_entry.entry_id):
+        if device_id and entity_entry.device_id != device_id:
+            continue
         entity_id = entity_entry.entity_id
-    data["entities"] = get_entitities(hass, config_entry)
+    data["entities"] = get_entitities(hass, config_entry, device_id=device.id)

14-35: ⚠️ Potential issue | 🟠 Major

Redact entity state/attributes before returning diagnostics.
Entity attributes often contain identifiers (serials, MACs, locations) that should not be exposed in diagnostics. Please pass attributes through Home Assistant’s diagnostics redaction helper and align keys with HA guidance/integration specifics.

🔒 Proposed fix (redact attributes)
+from homeassistant.components.diagnostics import async_redact_data
+
+# Populate with HA-recommended + integration-specific keys
+REDACT_KEYS = {
+    # e.g. "serial_number", "mac_address", "ip_address"
+}
+
 def get_entitities(hass: HomeAssistant, config_entry: ConfigEntry):
     entity_registry = er.async_get(hass)
     entities_data: dict[str, dict[str, Any]] = {}
@@
         if state:
             entity_info["state"] = state.state
-            entity_info["attributes"] = dict(state.attributes)
+            entity_info["attributes"] = async_redact_data(dict(state.attributes), REDACT_KEYS)
Home Assistant diagnostics redaction guidance async_redact_data DIAGNOSTICS_REDACT entity attributes
🧹 Nitpick comments (1)
custom_components/daikin_onecta/diagnostics.py (1)

14-50: Fix helper name typo for clarity (get_entitities).
Spelling looks accidental and will propagate in future call sites. Consider renaming to get_entities for readability.

♻️ Proposed rename
-def get_entitities(hass: HomeAssistant, config_entry: ConfigEntry):
+def get_entities(hass: HomeAssistant, config_entry: ConfigEntry):
@@
-        "entities": get_entitities(hass, config_entry),
+        "entities": get_entities(hass, config_entry),

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.92%. Comparing base (c2a91dd) to head (288189d).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #614   +/-   ##
=======================================
  Coverage   96.91%   96.92%           
=======================================
  Files          16       16           
  Lines        1782     1787    +5     
=======================================
+ Hits         1727     1732    +5     
  Misses         55       55           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

    * custom_components/daikin_onecta/diagnostics.py:
    * custom_components/daikin_onecta/diagnostics.py:
    * custom_components/daikin_onecta/diagnostics.py:
    * custom_components/daikin_onecta/diagnostics.py:
    * .github/workflows/precommit.yaml:
    * .github/workflows/tests.yaml:
@jwillemsen jwillemsen merged commit 063442c into master Jan 30, 2026
11 checks passed
@jwillemsen jwillemsen deleted the jwi-entitieslogging branch January 30, 2026 09:04
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.

1 participant