Skip to content

Commit c0b2fb8

Browse files
julienldclaude
andcommitted
refactor: Improve label operation messages and performance
Applied Gemini Code Assist suggestions: 1. Changed success messages to reflect final state (total labels) instead of operation count for better clarity 2. Optimized label removal with set conversion for O(1) lookup (O(N+M) instead of O(N*M)) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 506c4b7 commit c0b2fb8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/ha_mcp/tools/tools_labels.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ async def _add_labels_single(entity_id: str, labels: list[str]) -> dict[str, Any
406406
"entity_id": entity_id,
407407
"labels": final_labels,
408408
"entity_data": entity_entry,
409-
"message": f"Successfully added {len(labels)} label(s) to {entity_id}",
409+
"message": f"Successfully updated labels for {entity_id}. It now has {len(final_labels)} label(s).",
410410
}
411411
else:
412412
return {
@@ -444,8 +444,8 @@ async def _remove_labels_single(entity_id: str, labels: list[str]) -> dict[str,
444444
# Fetch current labels
445445
current_labels = await _get_entity_labels(entity_id)
446446

447-
# Remove specified labels
448-
final_labels = [lbl for lbl in current_labels if lbl not in labels]
447+
# Remove specified labels (convert to set for O(1) lookup)
448+
final_labels = [lbl for lbl in current_labels if lbl not in set(labels)]
449449

450450
# Update entity registry
451451
message: dict[str, Any] = {
@@ -463,7 +463,7 @@ async def _remove_labels_single(entity_id: str, labels: list[str]) -> dict[str,
463463
"entity_id": entity_id,
464464
"labels": final_labels,
465465
"entity_data": entity_entry,
466-
"message": f"Successfully removed {len(labels)} label(s) from {entity_id}",
466+
"message": f"Successfully updated labels for {entity_id}. It now has {len(final_labels)} label(s).",
467467
}
468468
else:
469469
return {

0 commit comments

Comments
 (0)