-
Notifications
You must be signed in to change notification settings - Fork 196
feat: add ha_remove_entity tool (closes #874) #876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sergeykad
merged 9 commits into
homeassistant-ai:master
from
Patch76:feat/ha-remove-entity
Apr 5, 2026
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f00ab72
feat: add ha_remove_entity tool (closes #874)
7e691fd
chore: regenerate tools.json and README table
3e42df8
fix: improve ha_remove_entity docstring and add general failure test
e6dcbc2
fix: add suggestions to error responses and happy-path E2E test
Patch76 6067a0d
fix: set idempotentHint to true and improve error message parsing
Patch76 e572294
fix: revert idempotentHint to false — second call raises ToolError (n…
Patch76 8e9c355
fix: correct idempotentHint for ha_remove_entity and restore ha_set_e…
Patch76 eabf7f4
fix: set idempotentHint true for ha_remove_entity per codebase conven…
Patch76 630f5d5
chore: revert tools.json to upstream — auto-generated on merge via sy…
Patch76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """E2E tests for ha_remove_entity tool.""" | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.src.e2e.utilities.assertions import assert_mcp_success, safe_call_tool | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.registry | ||
| class TestEntityRemove: | ||
| """Test ha_remove_entity tool.""" | ||
|
|
||
| async def test_remove_entity_success(self, mcp_client): | ||
| """Happy path: create a helper entity, remove it, verify it is gone.""" | ||
| # Create a temporary input_boolean to remove | ||
| create_result = await mcp_client.call_tool( | ||
| "ha_config_set_helper", | ||
| { | ||
| "helper_type": "input_boolean", | ||
| "name": "E2E Remove Entity Test", | ||
| "icon": "mdi:test-tube", | ||
| }, | ||
| ) | ||
| data = assert_mcp_success(create_result, "Create test helper") | ||
| entity_id = data.get("entity_id") or f"input_boolean.{data['helper_data']['id']}" | ||
| logger.info(f"Created test entity: {entity_id}") | ||
|
|
||
| # Remove the entity | ||
| remove_result = await mcp_client.call_tool( | ||
| "ha_remove_entity", | ||
| {"entity_id": entity_id}, | ||
| ) | ||
| remove_data = assert_mcp_success(remove_result, "Remove entity") | ||
| assert remove_data.get("success") is True, f"Expected success, got: {remove_data}" | ||
| assert remove_data.get("entity_id") == entity_id | ||
|
|
||
| logger.info(f"Entity removed successfully: {entity_id}") | ||
|
|
||
| # Verify entity is gone — second removal should fail | ||
| verify_data = await safe_call_tool( | ||
| mcp_client, | ||
| "ha_remove_entity", | ||
| {"entity_id": entity_id}, | ||
| ) | ||
| assert not verify_data.get("success"), ( | ||
| f"Entity should be gone after removal, got: {verify_data}" | ||
| ) | ||
| logger.info("Entity removal verified — entity no longer exists") | ||
|
|
||
| async def test_remove_entity_nonexistent(self, mcp_client): | ||
| """Removing a non-existent entity should fail gracefully.""" | ||
| data = await safe_call_tool( | ||
| mcp_client, | ||
| "ha_remove_entity", | ||
| {"entity_id": "sensor.definitely_not_real_12345"}, | ||
| ) | ||
| assert not data.get("success"), ( | ||
| f"Expected failure for non-existent entity, got: {data}" | ||
| ) | ||
| logger.info("Non-existent entity removal error handling verified") | ||
|
Patch76 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.