@@ -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