1616from ..errors import ErrorCode , create_error_response
1717from .helpers import exception_to_structured_error , log_tool_usage , raise_tool_error
1818from .util_helpers import (
19+ apply_entity_category ,
1920 coerce_bool_param ,
2021 parse_string_list_param ,
2122 wait_for_entity_registered ,
@@ -653,8 +654,8 @@ async def ha_config_set_helper(
653654 except Exception as e :
654655 helper_data ["warning" ] = f"Helper created but verification failed: { e } "
655656
656- # Update entity registry if area_id, labels, or category specified
657- if (area_id or labels or category ) and entity_id :
657+ # Update entity registry if area_id or labels specified
658+ if (area_id or labels ) and entity_id :
658659 update_message : dict [str , Any ] = {
659660 "type" : "config/entity_registry/update" ,
660661 "entity_id" : entity_id ,
@@ -663,24 +664,26 @@ async def ha_config_set_helper(
663664 update_message ["area_id" ] = area_id
664665 if labels :
665666 update_message ["labels" ] = labels
666- if category :
667- update_message ["categories" ] = {"helpers" : category }
668667
669668 update_result = await client .send_websocket_message (
670669 update_message
671670 )
672671 if update_result .get ("success" ):
673672 helper_data ["area_id" ] = area_id
674673 helper_data ["labels" ] = labels
675- if category :
676- helper_data ["category" ] = category
677674 else :
678675 error_detail = update_result .get ("error" , {})
679676 error_msg = error_detail .get ("message" , "Unknown error" ) if isinstance (error_detail , dict ) else str (error_detail )
680677 helper_data ["warning" ] = (
681678 f"Helper created but entity registry update failed: { error_msg } "
682679 )
683680
681+ # Apply category via shared helper (consistent with automations/scripts)
682+ if category and entity_id :
683+ await apply_entity_category (
684+ client , entity_id , category , "helpers" , helper_data , "helper"
685+ )
686+
684687 return {
685688 "success" : True ,
686689 "action" : "create" ,
@@ -898,8 +901,8 @@ async def ha_config_set_helper(
898901 ))
899902 updated_data = result .get ("result" , {})
900903
901- # Also update entity registry for icon, area, labels, and category
902- if icon or area_id or labels or category :
904+ # Also update entity registry for icon, area, and labels
905+ if icon or area_id or labels :
903906 registry_update : dict [str , Any ] = {
904907 "type" : "config/entity_registry/update" ,
905908 "entity_id" : entity_id ,
@@ -910,8 +913,6 @@ async def ha_config_set_helper(
910913 registry_update ["area_id" ] = area_id
911914 if labels :
912915 registry_update ["labels" ] = labels
913- if category :
914- registry_update ["categories" ] = {"helpers" : category }
915916 reg_result = await client .send_websocket_message (registry_update )
916917 if not reg_result .get ("success" ):
917918 error_detail = reg_result .get ("error" , {})
@@ -921,6 +922,12 @@ async def ha_config_set_helper(
921922 f"Config updated but entity registry update failed: { error_msg } "
922923 )
923924
925+ # Apply category via shared helper
926+ if category :
927+ await apply_entity_category (
928+ client , entity_id , category , "helpers" , updated_data , "helper"
929+ )
930+
924931 else :
925932 # Standard helpers: entity registry update only
926933 update_msg = {
@@ -936,8 +943,6 @@ async def ha_config_set_helper(
936943 update_msg ["area_id" ] = area_id
937944 if labels :
938945 update_msg ["labels" ] = labels
939- if category :
940- update_msg ["categories" ] = {"helpers" : category }
941946
942947 result = await client .send_websocket_message (update_msg )
943948
@@ -950,6 +955,12 @@ async def ha_config_set_helper(
950955 context = {"helper_type" : helper_type , "entity_id" : entity_id },
951956 ))
952957
958+ # Apply category via shared helper
959+ if category :
960+ await apply_entity_category (
961+ client , entity_id , category , "helpers" , updated_data , "helper"
962+ )
963+
953964 # Wait for entity to reflect the update
954965 wait_bool = coerce_bool_param (wait , "wait" , default = True )
955966 response : dict [str , Any ] = {
0 commit comments