mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Platforms cleanup when adding entity fails (#36742)
This commit is contained in:
@@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
from homeassistant.const import UNIT_PERCENTAGE
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.exceptions import HomeAssistantError, PlatformNotReady
|
||||
from homeassistant.helpers import entity_platform, entity_registry
|
||||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.entity_component import (
|
||||
@@ -359,6 +359,11 @@ async def test_raise_error_on_update(hass):
|
||||
assert len(updates) == 1
|
||||
assert 1 in updates
|
||||
|
||||
assert entity1.hass is None
|
||||
assert entity1.platform is None
|
||||
assert entity2.hass is not None
|
||||
assert entity2.platform is not None
|
||||
|
||||
|
||||
async def test_async_remove_with_platform(hass):
|
||||
"""Remove an entity from a platform."""
|
||||
@@ -380,10 +385,11 @@ async def test_not_adding_duplicate_entities_with_unique_id(hass):
|
||||
|
||||
assert len(hass.states.async_entity_ids()) == 1
|
||||
|
||||
await component.async_add_entities(
|
||||
[MockEntity(name="test2", unique_id="not_very_unique")]
|
||||
)
|
||||
ent2 = MockEntity(name="test2", unique_id="not_very_unique")
|
||||
await component.async_add_entities([ent2])
|
||||
|
||||
assert ent2.hass is None
|
||||
assert ent2.platform is None
|
||||
assert len(hass.states.async_entity_ids()) == 1
|
||||
|
||||
|
||||
@@ -792,6 +798,11 @@ async def test_entity_disabled_by_integration(hass):
|
||||
|
||||
await component.async_add_entities([entity_default, entity_disabled])
|
||||
|
||||
assert entity_default.hass is not None
|
||||
assert entity_default.platform is not None
|
||||
assert entity_disabled.hass is None
|
||||
assert entity_disabled.platform is None
|
||||
|
||||
registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
entry_default = registry.async_get_or_create(DOMAIN, DOMAIN, "default")
|
||||
@@ -889,3 +900,13 @@ async def test_platforms_sharing_services(hass):
|
||||
assert len(entities) == 2
|
||||
assert entity1 in entities
|
||||
assert entity2 in entities
|
||||
|
||||
|
||||
async def test_invalid_entity_id(hass):
|
||||
"""Test specifying an invalid entity id."""
|
||||
platform = MockEntityPlatform(hass)
|
||||
entity = MockEntity(entity_id="invalid_entity_id")
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await platform.async_add_entities([entity])
|
||||
assert entity.hass is None
|
||||
assert entity.platform is None
|
||||
|
||||
Reference in New Issue
Block a user