Remove ESPHome legacy entity naming (#123436)
* Remove ESPHome legacy entity naming * Update test entity_ids to use sanitized name instead of object_id
This commit is contained in:
parent
f8e1c2cfd4
commit
84d6f5ed07
23 changed files with 275 additions and 322 deletions
|
@ -69,10 +69,10 @@ async def test_entities_removed(
|
|||
entry = mock_device.entry
|
||||
entry_id = entry.entry_id
|
||||
storage_key = f"esphome.{entry_id}"
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
@ -81,13 +81,13 @@ async def test_entities_removed(
|
|||
|
||||
assert len(hass_storage[storage_key]["data"]["binary_sensor"]) == 2
|
||||
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.attributes[ATTR_RESTORED] is True
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is not None
|
||||
reg_entry = entity_registry.async_get(
|
||||
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||
"binary_sensor.test_my_binary_sensor_to_be_removed"
|
||||
)
|
||||
assert reg_entry is not None
|
||||
assert state.attributes[ATTR_RESTORED] is True
|
||||
|
@ -111,13 +111,13 @@ async def test_entities_removed(
|
|||
entry=entry,
|
||||
)
|
||||
assert mock_device.entry.entry_id == entry_id
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is None
|
||||
reg_entry = entity_registry.async_get(
|
||||
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||
"binary_sensor.test_my_binary_sensor_to_be_removed"
|
||||
)
|
||||
assert reg_entry is None
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
@ -164,15 +164,15 @@ async def test_entities_removed_after_reload(
|
|||
entry = mock_device.entry
|
||||
entry_id = entry.entry_id
|
||||
storage_key = f"esphome.{entry_id}"
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
reg_entry = entity_registry.async_get(
|
||||
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||
"binary_sensor.test_my_binary_sensor_to_be_removed"
|
||||
)
|
||||
assert reg_entry is not None
|
||||
|
||||
|
@ -181,15 +181,15 @@ async def test_entities_removed_after_reload(
|
|||
|
||||
assert len(hass_storage[storage_key]["data"]["binary_sensor"]) == 2
|
||||
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.attributes[ATTR_RESTORED] is True
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is not None
|
||||
assert state.attributes[ATTR_RESTORED] is True
|
||||
|
||||
reg_entry = entity_registry.async_get(
|
||||
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||
"binary_sensor.test_my_binary_sensor_to_be_removed"
|
||||
)
|
||||
assert reg_entry is not None
|
||||
|
||||
|
@ -198,14 +198,14 @@ async def test_entities_removed_after_reload(
|
|||
|
||||
assert len(hass_storage[storage_key]["data"]["binary_sensor"]) == 2
|
||||
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert ATTR_RESTORED not in state.attributes
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is not None
|
||||
assert ATTR_RESTORED not in state.attributes
|
||||
reg_entry = entity_registry.async_get(
|
||||
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||
"binary_sensor.test_my_binary_sensor_to_be_removed"
|
||||
)
|
||||
assert reg_entry is not None
|
||||
|
||||
|
@ -236,23 +236,23 @@ async def test_entities_removed_after_reload(
|
|||
on_future.set_result(None)
|
||||
|
||||
async_track_state_change_event(
|
||||
hass, ["binary_sensor.test_mybinary_sensor"], _async_wait_for_on
|
||||
hass, ["binary_sensor.test_my_binary_sensor"], _async_wait_for_on
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
async with asyncio.timeout(2):
|
||||
await on_future
|
||||
|
||||
assert mock_device.entry.entry_id == entry_id
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor_to_be_removed")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor_to_be_removed")
|
||||
assert state is None
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
reg_entry = entity_registry.async_get(
|
||||
"binary_sensor.test_mybinary_sensor_to_be_removed"
|
||||
"binary_sensor.test_my_binary_sensor_to_be_removed"
|
||||
)
|
||||
assert reg_entry is None
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
@ -260,35 +260,6 @@ async def test_entities_removed_after_reload(
|
|||
assert len(hass_storage[storage_key]["data"]["binary_sensor"]) == 1
|
||||
|
||||
|
||||
async def test_entity_info_object_ids(
|
||||
hass: HomeAssistant,
|
||||
mock_client: APIClient,
|
||||
mock_esphome_device: Callable[
|
||||
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
|
||||
Awaitable[MockESPHomeDevice],
|
||||
],
|
||||
) -> None:
|
||||
"""Test how object ids affect entity id."""
|
||||
entity_info = [
|
||||
BinarySensorInfo(
|
||||
object_id="object_id_is_used",
|
||||
key=1,
|
||||
name="my binary_sensor",
|
||||
unique_id="my_binary_sensor",
|
||||
)
|
||||
]
|
||||
states = []
|
||||
user_service = []
|
||||
await mock_esphome_device(
|
||||
mock_client=mock_client,
|
||||
entity_info=entity_info,
|
||||
user_service=user_service,
|
||||
states=states,
|
||||
)
|
||||
state = hass.states.get("binary_sensor.test_object_id_is_used")
|
||||
assert state is not None
|
||||
|
||||
|
||||
async def test_deep_sleep_device(
|
||||
hass: HomeAssistant,
|
||||
mock_client: APIClient,
|
||||
|
@ -326,7 +297,7 @@ async def test_deep_sleep_device(
|
|||
states=states,
|
||||
device_info={"has_deep_sleep": True},
|
||||
)
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
|
@ -335,7 +306,7 @@ async def test_deep_sleep_device(
|
|||
|
||||
await mock_device.mock_disconnect(False)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
|
@ -345,7 +316,7 @@ async def test_deep_sleep_device(
|
|||
await mock_device.mock_connect()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
|
@ -359,7 +330,7 @@ async def test_deep_sleep_device(
|
|||
mock_device.set_state(BinarySensorState(key=1, state=False, missing_state=False))
|
||||
mock_device.set_state(SensorState(key=3, state=56, missing_state=False))
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
|
@ -368,7 +339,7 @@ async def test_deep_sleep_device(
|
|||
|
||||
await mock_device.mock_disconnect(True)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
|
@ -379,7 +350,7 @@ async def test_deep_sleep_device(
|
|||
await hass.async_block_till_done()
|
||||
await mock_device.mock_disconnect(False)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
state = hass.states.get("sensor.test_my_sensor")
|
||||
|
@ -388,14 +359,14 @@ async def test_deep_sleep_device(
|
|||
|
||||
await mock_device.mock_connect()
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
|
||||
await hass.async_block_till_done()
|
||||
# Verify we do not dispatch any more state updates or
|
||||
# availability updates after the stop event is fired
|
||||
state = hass.states.get("binary_sensor.test_mybinary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
@ -430,6 +401,6 @@ async def test_esphome_device_without_friendly_name(
|
|||
states=states,
|
||||
device_info={"friendly_name": None},
|
||||
)
|
||||
state = hass.states.get("binary_sensor.my_binary_sensor")
|
||||
state = hass.states.get("binary_sensor.test_my_binary_sensor")
|
||||
assert state is not None
|
||||
assert state.state == STATE_ON
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue