Skip to content

Commit 3ab2b36

Browse files
refactor(c901): clear final 6 files, delete emptied grandfather list (closes #925) (#1964)
Claude-Session: https://claude.ai/code/session_01DxGQhYBQg7681uCdr9w9qB Co-authored-by: kingpanther13 <kingpanther13@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 83ef578 commit 3ab2b36

7 files changed

Lines changed: 1579 additions & 1150 deletions

File tree

pyproject.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,6 @@ ignore = [
163163
[tool.ruff.lint.per-file-ignores]
164164
"__init__.py" = ["F401"]
165165
"tests/**/*" = ["E501", "B011"]
166-
# C901 (mccabe complexity) grandfathered debt: newly enabled rule, these files
167-
# already exceeded the threshold. Remove a line once its functions are
168-
# refactored below threshold -- do not add new files here.
169-
"src/ha_mcp/tools/tools_config_automations.py" = ["C901"]
170-
"src/ha_mcp/tools/tools_config_scenes.py" = ["C901"]
171-
"src/ha_mcp/tools/tools_config_scripts.py" = ["C901"]
172-
"src/ha_mcp/tools/tools_dev.py" = ["C901"]
173-
"src/ha_mcp/tools/tools_system.py" = ["C901"]
174-
"tests/src/unit/test_advanced_settings_coverage.py" = ["C901"]
175166

176167
[tool.pytest.ini_options]
177168
testpaths = ["tests"]

src/ha_mcp/tools/tools_config_automations.py

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -839,39 +839,7 @@ async def ha_config_set_automation(
839839
and e.status_code == 404
840840
):
841841
await self._raise_automation_not_found(identifier)
842-
error_text = str(e)
843-
suggestions = [
844-
"Check automation configuration format",
845-
"Ensure required fields: alias, triggers, actions",
846-
"Use entity_id format: automation.morning_routine or unique_id",
847-
"Use ha_search(domain_filter='automation') to find automations",
848-
"Use ha_get_skill_guide for automation examples",
849-
]
850-
if isinstance(e, HomeAssistantAPIError):
851-
if "'service'" in error_text and "not allowed" in error_text:
852-
suggestions.insert(
853-
0,
854-
"Use 'action:' not 'service:' for service calls in action steps "
855-
"(renamed in HA 2024.8).",
856-
)
857-
elif "unexpected keyword argument" in error_text.lower():
858-
suggestions.insert(
859-
0,
860-
"An action step contains a field that belongs at the automation root "
861-
"(e.g. alias, trigger, condition). Each action step should only contain "
862-
"action/target/data/delay/choose/if/repeat/parallel keys.",
863-
)
864-
elif "'variables'" in error_text and "dictionary" in error_text:
865-
suggestions.insert(
866-
0,
867-
"variables must be a dict mapping names to values, "
868-
'e.g. {"variables": {"my_var": 42}}',
869-
)
870-
if bp_warnings:
871-
suggestions.append(
872-
"Config had best-practice issues that may be related: "
873-
+ "; ".join(bp_warnings)
874-
)
842+
suggestions = self._build_set_automation_suggestions(e, bp_warnings)
875843
error = exception_to_structured_error(
876844
e,
877845
context={"identifier": identifier},
@@ -881,6 +849,51 @@ async def ha_config_set_automation(
881849
augment_error_dict_with_skill_content(error, bp_warnings)
882850
raise_tool_error(error)
883851

852+
@staticmethod
853+
def _build_set_automation_suggestions(
854+
e: Exception, bp_warnings: BestPracticeCheckResult
855+
) -> list[str]:
856+
"""Build the ordered suggestion list for a failed config-replacement set.
857+
858+
Extracted verbatim from ``ha_config_set_automation``'s exception
859+
handler: HA-API messages get a targeted lead suggestion inserted, and
860+
any best-practice warnings are appended.
861+
"""
862+
error_text = str(e)
863+
suggestions = [
864+
"Check automation configuration format",
865+
"Ensure required fields: alias, triggers, actions",
866+
"Use entity_id format: automation.morning_routine or unique_id",
867+
"Use ha_search(domain_filter='automation') to find automations",
868+
"Use ha_get_skill_guide for automation examples",
869+
]
870+
if isinstance(e, HomeAssistantAPIError):
871+
if "'service'" in error_text and "not allowed" in error_text:
872+
suggestions.insert(
873+
0,
874+
"Use 'action:' not 'service:' for service calls in action steps "
875+
"(renamed in HA 2024.8).",
876+
)
877+
elif "unexpected keyword argument" in error_text.lower():
878+
suggestions.insert(
879+
0,
880+
"An action step contains a field that belongs at the automation root "
881+
"(e.g. alias, trigger, condition). Each action step should only contain "
882+
"action/target/data/delay/choose/if/repeat/parallel keys.",
883+
)
884+
elif "'variables'" in error_text and "dictionary" in error_text:
885+
suggestions.insert(
886+
0,
887+
"variables must be a dict mapping names to values, "
888+
'e.g. {"variables": {"my_var": 42}}',
889+
)
890+
if bp_warnings:
891+
suggestions.append(
892+
"Config had best-practice issues that may be related: "
893+
+ "; ".join(bp_warnings)
894+
)
895+
return suggestions
896+
884897
async def _upsert_automation(
885898
self,
886899
config: dict[str, Any],

0 commit comments

Comments
 (0)