Also add entities to device diagnostics#614
Conversation
* custom_components/daikin_onecta/diagnostics.py:
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. WalkthroughA new helper function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🟠 MajorScope device diagnostics to the requested device.
async_get_device_diagnosticscurrently returns all entities from the config entry, which leaks unrelated entities when multiple devices exist under one entry. Filter byentity_entry.device_idand passdevice.idto 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 | 🟠 MajorRedact 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 toget_entitiesfor 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
* 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:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.