Conversation
Adds a new HA service that returns the complete integration configuration (merged config_entry.data and options) directly as a service response, rendered as YAML in Developer Tools. Area configs are reordered so area_id appears first for readability. Closes #287 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughThe PR introduces a new "export_config" service that allows exporting the complete integration configuration in YAML format. The implementation includes a service handler in the service module and a corresponding service declaration in the services manifest. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
custom_components/area_occupancy/service.py (2)
187-188: Consider expanding the docstring to include Args and Returns.Per coding guidelines, function docstrings should document parameters and return values.
📝 Proposed docstring expansion
async def _export_config(hass: HomeAssistant, call: ServiceCall) -> dict[str, Any]: - """Export the complete integration configuration as YAML.""" + """Export the complete integration configuration as YAML. + + Args: + hass: Home Assistant instance + call: Service call data (unused, required by service handler pattern) + + Returns: + Dictionary containing merged config_entry.data and config_entry.options + + Raises: + HomeAssistantError: If coordinator not found or config export fails + """🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@custom_components/area_occupancy/service.py` around lines 187 - 188, The docstring for async function _export_config(hass: HomeAssistant, call: ServiceCall) is minimal; update it to include an Args section listing hass (HomeAssistant) and call (ServiceCall) with brief descriptions, and a Returns section describing the returned dict[str, Any] (exported YAML/config structure or error shape), keeping the one-line summary intact and following the project's docstring style/convention.
204-207: Use specific exceptions and include stack traces in error logging.Per coding guidelines, catch specific exceptions rather than generic
Exception, and includeexc_info=Truefor stack traces. Theget_coordinatorhelper already raisesHomeAssistantError, and dict operations can raiseKeyError/TypeError.♻️ Proposed improvement for exception handling
- except Exception as err: - error_msg = f"Failed to export config: {err}" - _LOGGER.error(error_msg) + except (HomeAssistantError, KeyError, TypeError) as err: + error_msg = f"Failed to export config: {err}" + _LOGGER.error(error_msg, exc_info=True) raise HomeAssistantError(error_msg) from errAs per coding guidelines: "Use specific exceptions over generic Exception and include stack traces in logging."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@custom_components/area_occupancy/service.py` around lines 204 - 207, The catch-all except block should be replaced with specific exception handling: catch HomeAssistantError separately (re-raise it unchanged), and catch likely runtime exceptions such as KeyError and TypeError from dict ops and serialization, log them with the stack trace by calling _LOGGER.error(...) with exc_info=True and a clear message (use the same error_msg pattern), then raise a new HomeAssistantError(error_msg) from the original exception; ensure references to get_coordinator, error_msg, _LOGGER.error, and HomeAssistantError remain and are used when locating and implementing the changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@custom_components/area_occupancy/service.py`:
- Around line 187-188: The docstring for async function _export_config(hass:
HomeAssistant, call: ServiceCall) is minimal; update it to include an Args
section listing hass (HomeAssistant) and call (ServiceCall) with brief
descriptions, and a Returns section describing the returned dict[str, Any]
(exported YAML/config structure or error shape), keeping the one-line summary
intact and following the project's docstring style/convention.
- Around line 204-207: The catch-all except block should be replaced with
specific exception handling: catch HomeAssistantError separately (re-raise it
unchanged), and catch likely runtime exceptions such as KeyError and TypeError
from dict ops and serialization, log them with the stack trace by calling
_LOGGER.error(...) with exc_info=True and a clear message (use the same
error_msg pattern), then raise a new HomeAssistantError(error_msg) from the
original exception; ensure references to get_coordinator, error_msg,
_LOGGER.error, and HomeAssistantError remain and are used when locating and
implementing the changes.
Summary
area_occupancy.export_configHA service that returns the complete integration configuration (mergedconfig_entry.dataandconfig_entry.options) as a service responsearea_idappears as the first key for readabilityrun_analysisserviceTest plan
area_occupancy.export_configfrom Developer Tools > Services and verify output contains the full configarea_idappears first in each area blockrun_analysisservice still worksCloses #287
🤖 Generated with Claude Code
Summary by CodeRabbit