mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Remove Home Assistant Cast user when removing entry (#44228)
* Remove Home Assistant Cast user when removing entry * Fix test * Fix test
This commit is contained in:
parent
3bb996c5b4
commit
dfde403937
@ -29,3 +29,8 @@ async def async_setup_entry(hass, entry: config_entries.ConfigEntry):
|
|||||||
hass.config_entries.async_forward_entry_setup(entry, "media_player")
|
hass.config_entries.async_forward_entry_setup(entry, "media_player")
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def async_remove_entry(hass, entry):
|
||||||
|
"""Remove Home Assistant Cast user."""
|
||||||
|
await home_assistant_cast.async_remove_user(hass, entry)
|
||||||
|
@ -72,3 +72,14 @@ async def async_setup_ha_cast(
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_remove_user(
|
||||||
|
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
|
||||||
|
):
|
||||||
|
"""Remove Home Assistant Cast user."""
|
||||||
|
user_id: Optional[str] = entry.data.get("user_id")
|
||||||
|
|
||||||
|
if user_id is not None:
|
||||||
|
user = await hass.auth.async_get_user(user_id)
|
||||||
|
await hass.auth.async_remove_user(user)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Test Home Assistant Cast."""
|
"""Test Home Assistant Cast."""
|
||||||
|
|
||||||
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.cast import home_assistant_cast
|
from homeassistant.components.cast import home_assistant_cast
|
||||||
from homeassistant.config import async_process_ha_core_config
|
from homeassistant.config import async_process_ha_core_config
|
||||||
|
|
||||||
@ -86,3 +87,32 @@ async def test_use_cloud_url(hass, mock_zeroconf):
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
controller = calls[0][0]
|
controller = calls[0][0]
|
||||||
assert controller.hass_url == "https://something.nabu.casa"
|
assert controller.hass_url == "https://something.nabu.casa"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_remove_entry(hass, mock_zeroconf):
|
||||||
|
"""Test removing config entry removes user."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||||
|
data={},
|
||||||
|
domain="cast",
|
||||||
|
title="Google Cast",
|
||||||
|
)
|
||||||
|
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.cast.media_player._async_setup_platform"
|
||||||
|
), patch(
|
||||||
|
"pychromecast.discovery.discover_chromecasts", return_value=(True, None)
|
||||||
|
), patch(
|
||||||
|
"pychromecast.discovery.stop_discovery"
|
||||||
|
):
|
||||||
|
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert "cast" in hass.config.components
|
||||||
|
|
||||||
|
user_id = entry.data.get("user_id")
|
||||||
|
assert await hass.auth.async_get_user(user_id)
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_remove(entry.entry_id)
|
||||||
|
assert not await hass.auth.async_get_user(user_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user