Ensure it's safe to call Entity.__repr__ on non added entity (#106032)
This commit is contained in:
parent
c83388fd2d
commit
c1f1b5c50b
3 changed files with 19 additions and 14 deletions
|
@ -1392,8 +1392,8 @@ async def test_translation_key(hass: HomeAssistant) -> None:
|
|||
assert mock_entity2.translation_key == "from_entity_description"
|
||||
|
||||
|
||||
async def test_repr_using_stringify_state() -> None:
|
||||
"""Test that repr uses stringify state."""
|
||||
async def test_repr(hass) -> None:
|
||||
"""Test Entity.__repr__."""
|
||||
|
||||
class MyEntity(MockEntity):
|
||||
"""Mock entity."""
|
||||
|
@ -1403,9 +1403,20 @@ async def test_repr_using_stringify_state() -> None:
|
|||
"""Return the state."""
|
||||
raise ValueError("Boom")
|
||||
|
||||
platform = MockEntityPlatform(hass, domain="hello")
|
||||
my_entity = MyEntity(entity_id="test.test", available=False)
|
||||
|
||||
# Not yet added
|
||||
assert str(my_entity) == "<entity test.test=unknown>"
|
||||
|
||||
# Added
|
||||
await platform.async_add_entities([my_entity])
|
||||
assert str(my_entity) == "<entity test.test=unavailable>"
|
||||
|
||||
# Removed
|
||||
await platform.async_remove_entity(my_entity.entity_id)
|
||||
assert str(my_entity) == "<entity test.test=unknown>"
|
||||
|
||||
|
||||
async def test_warn_using_async_update_ha_state(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue