mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Improve cast test for removing device (#67385)
This commit is contained in:
parent
e891df0ff3
commit
148762ce3f
@ -633,8 +633,10 @@ async def test_entity_availability(hass: HomeAssistant):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("port,entry_type", ((8009, None), (12345, None)))
|
@pytest.mark.parametrize("port,entry_type", ((8009, None), (12345, None)))
|
||||||
async def test_device_registry(hass: HomeAssistant, port, entry_type):
|
async def test_device_registry(hass: HomeAssistant, hass_ws_client, port, entry_type):
|
||||||
"""Test device registry integration."""
|
"""Test device registry integration."""
|
||||||
|
assert await async_setup_component(hass, "config", {})
|
||||||
|
|
||||||
entity_id = "media_player.speaker"
|
entity_id = "media_player.speaker"
|
||||||
reg = er.async_get(hass)
|
reg = er.async_get(hass)
|
||||||
dev_reg = dr.async_get(hass)
|
dev_reg = dr.async_get(hass)
|
||||||
@ -657,19 +659,32 @@ async def test_device_registry(hass: HomeAssistant, port, entry_type):
|
|||||||
assert state.state == "off"
|
assert state.state == "off"
|
||||||
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid))
|
assert entity_id == reg.async_get_entity_id("media_player", "cast", str(info.uuid))
|
||||||
entity_entry = reg.async_get(entity_id)
|
entity_entry = reg.async_get(entity_id)
|
||||||
assert entity_entry.device_id is not None
|
|
||||||
device_entry = dev_reg.async_get(entity_entry.device_id)
|
device_entry = dev_reg.async_get(entity_entry.device_id)
|
||||||
|
assert entity_entry.device_id == device_entry.id
|
||||||
assert device_entry.entry_type == entry_type
|
assert device_entry.entry_type == entry_type
|
||||||
|
|
||||||
# Check that the chromecast object is torn down when the device is removed
|
# Check that the chromecast object is torn down when the device is removed
|
||||||
chromecast.disconnect.assert_not_called()
|
chromecast.disconnect.assert_not_called()
|
||||||
dev_reg.async_update_device(
|
|
||||||
device_entry.id, remove_config_entry_id=cast_entry.entry_id
|
client = await hass_ws_client(hass)
|
||||||
|
await client.send_json(
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"type": "config/device_registry/remove_config_entry",
|
||||||
|
"config_entry_id": cast_entry.entry_id,
|
||||||
|
"device_id": device_entry.id,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
response = await client.receive_json()
|
||||||
|
assert response["success"]
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
chromecast.disconnect.assert_called_once()
|
chromecast.disconnect.assert_called_once()
|
||||||
|
|
||||||
|
assert reg.async_get(entity_id) is None
|
||||||
|
assert dev_reg.async_get(entity_entry.device_id) is None
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_cast_status(hass: HomeAssistant):
|
async def test_entity_cast_status(hass: HomeAssistant):
|
||||||
"""Test handling of cast status."""
|
"""Test handling of cast status."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user