mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Add tests of legacy entity without platform writing state (#148109)
This commit is contained in:
parent
cde17fc0ca
commit
8ce30d9559
@ -2713,6 +2713,41 @@ async def test_platform_state(
|
||||
assert hass.states.get("test.test") is None
|
||||
|
||||
|
||||
async def test_platform_state_no_platform(hass: HomeAssistant) -> None:
|
||||
"""Test platform state for entities which are not added by an entity platform."""
|
||||
|
||||
class MockEntity(entity.Entity):
|
||||
entity_id = "test.test"
|
||||
|
||||
def async_set_state(self, state: str) -> None:
|
||||
self._attr_state = state
|
||||
self.async_write_ha_state()
|
||||
|
||||
ent = MockEntity()
|
||||
ent.hass = hass
|
||||
assert hass.states.get("test.test") is None
|
||||
|
||||
# The attempt to write when in state NOT_ADDED should be allowed
|
||||
assert ent._platform_state == entity.EntityPlatformState.NOT_ADDED
|
||||
ent.async_set_state("not_added")
|
||||
assert hass.states.get("test.test").state == "not_added"
|
||||
|
||||
# The attempt to write when in state ADDING should be allowed
|
||||
ent._platform_state = entity.EntityPlatformState.ADDING
|
||||
ent.async_set_state("adding")
|
||||
assert hass.states.get("test.test").state == "adding"
|
||||
|
||||
# The attempt to write when in state ADDED should be allowed
|
||||
ent._platform_state = entity.EntityPlatformState.ADDED
|
||||
ent.async_set_state("added")
|
||||
assert hass.states.get("test.test").state == "added"
|
||||
|
||||
# The attempt to write when in state REMOVED should be ignored
|
||||
ent._platform_state = entity.EntityPlatformState.REMOVED
|
||||
ent.async_set_state("removed")
|
||||
assert hass.states.get("test.test").state == "added"
|
||||
|
||||
|
||||
async def test_platform_state_fail_to_add(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user