-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Allow changing entity ID #15637
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
Merged
Allow changing entity ID #15637
Changes from 1 commit
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| from unittest.mock import patch, Mock, MagicMock | ||
| from datetime import timedelta | ||
|
|
||
| import pytest | ||
|
|
||
| from homeassistant.exceptions import PlatformNotReady | ||
| import homeassistant.loader as loader | ||
| from homeassistant.helpers.entity import generate_entity_id | ||
|
|
@@ -487,7 +489,7 @@ def test_registry_respect_entity_disabled(hass): | |
| assert hass.states.async_entity_ids() == [] | ||
|
|
||
|
|
||
| async def test_entity_registry_updates(hass): | ||
| async def test_entity_registry_updates_name(hass): | ||
| """Test that updates on the entity registry update platform entities.""" | ||
| registry = mock_registry(hass, { | ||
| 'test_domain.world': entity_registry.RegistryEntry( | ||
|
|
@@ -602,3 +604,75 @@ def test_not_fails_with_adding_empty_entities_(hass): | |
| yield from component.async_add_entities([]) | ||
|
|
||
| assert len(hass.states.async_entity_ids()) == 0 | ||
|
|
||
|
|
||
| async def test_entity_registry_updates_entity_id(hass): | ||
| """Test that updates on the entity registry update platform entities.""" | ||
| registry = mock_registry(hass, { | ||
| 'test_domain.world': entity_registry.RegistryEntry( | ||
| entity_id='test_domain.world', | ||
| unique_id='1234', | ||
| # Using component.async_add_entities is equal to platform "domain" | ||
| platform='test_platform', | ||
| name='Some name' | ||
| ) | ||
| }) | ||
| platform = MockEntityPlatform(hass) | ||
| entity = MockEntity(unique_id='1234') | ||
| await platform.async_add_entities([entity]) | ||
|
|
||
| state = hass.states.get('test_domain.world') | ||
| assert state is not None | ||
| assert state.name == 'Some name' | ||
|
|
||
| registry.async_update_entity('test_domain.world', | ||
| new_entity_id='test_domain.planet') | ||
| await hass.async_block_till_done() | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert hass.states.get('test_domain.world') is None | ||
| state = hass.states.get('test_domain.planet') | ||
|
|
||
|
|
||
| async def test_entity_registry_updates_invalid_entity_id(hass): | ||
| """Test that we can't update to an invalid entity id.""" | ||
| registry = mock_registry(hass, { | ||
| 'test_domain.world': entity_registry.RegistryEntry( | ||
| entity_id='test_domain.world', | ||
| unique_id='1234', | ||
| # Using component.async_add_entities is equal to platform "domain" | ||
| platform='test_platform', | ||
| name='Some name' | ||
| ), | ||
| 'test_domain.existing': entity_registry.RegistryEntry( | ||
| entity_id='test_domain.existing', | ||
| unique_id='5678', | ||
| platform='test_platform', | ||
| ), | ||
| }) | ||
| platform = MockEntityPlatform(hass) | ||
| entity = MockEntity(unique_id='1234') | ||
| await platform.async_add_entities([entity]) | ||
|
|
||
| state = hass.states.get('test_domain.world') | ||
| assert state is not None | ||
| assert state.name == 'Some name' | ||
|
|
||
| with pytest.raises(ValueError): | ||
| registry.async_update_entity('test_domain.world', | ||
| new_entity_id='test_domain.existing') | ||
|
|
||
| with pytest.raises(ValueError): | ||
| registry.async_update_entity('test_domain.world', | ||
| new_entity_id='invalid_entity_id') | ||
|
|
||
| with pytest.raises(ValueError): | ||
| registry.async_update_entity('test_domain.world', | ||
| new_entity_id='diff_domain.world') | ||
|
|
||
| await hass.async_block_till_done() | ||
| await hass.async_block_till_done() | ||
|
|
||
| assert hass.states.get('test_domain.world') is not None | ||
| state = hass.states.get('invalid_entity_id') is None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks weird. Missing assertion? |
||
| state = hass.states.get('diff_domain.world') is None | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing assertion?