mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Cleanup map references in lovelace (#136314)
* Cleanup map references in lovelace * Cleanup fixtures
This commit is contained in:
parent
8172afd9f4
commit
10cfef1f3e
@ -4,7 +4,7 @@ import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import frontend, onboarding, websocket_api
|
||||
from homeassistant.components import frontend, websocket_api
|
||||
from homeassistant.config import (
|
||||
async_hass_config_yaml,
|
||||
async_process_component_and_handle_errors,
|
||||
@ -14,7 +14,6 @@ from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import collection, config_validation as cv
|
||||
from homeassistant.helpers.service import async_register_admin_service
|
||||
from homeassistant.helpers.translation import async_get_translations
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import async_get_integration
|
||||
|
||||
@ -211,9 +210,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
# Process storage dashboards
|
||||
dashboards_collection = dashboard.DashboardsCollection(hass)
|
||||
|
||||
# This can be removed when the map integration is removed
|
||||
hass.data[DOMAIN]["dashboards_collection"] = dashboards_collection
|
||||
|
||||
dashboards_collection.async_add_listener(storage_dashboard_changed)
|
||||
await dashboards_collection.async_load()
|
||||
|
||||
@ -225,12 +221,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
STORAGE_DASHBOARD_UPDATE_FIELDS,
|
||||
).async_setup(hass)
|
||||
|
||||
def create_map_dashboard():
|
||||
hass.async_create_task(_create_map_dashboard(hass))
|
||||
|
||||
if not onboarding.async_is_onboarded(hass):
|
||||
onboarding.async_add_listener(hass, create_map_dashboard)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@ -268,25 +258,3 @@ def _register_panel(hass, url_path, mode, config, update):
|
||||
kwargs["sidebar_icon"] = config.get(CONF_ICON, DEFAULT_ICON)
|
||||
|
||||
frontend.async_register_built_in_panel(hass, DOMAIN, **kwargs)
|
||||
|
||||
|
||||
async def _create_map_dashboard(hass: HomeAssistant):
|
||||
translations = await async_get_translations(
|
||||
hass, hass.config.language, "dashboard", {onboarding.DOMAIN}
|
||||
)
|
||||
title = translations["component.onboarding.dashboard.map.title"]
|
||||
|
||||
dashboards_collection: dashboard.DashboardsCollection = hass.data[DOMAIN][
|
||||
"dashboards_collection"
|
||||
]
|
||||
await dashboards_collection.async_create_item(
|
||||
{
|
||||
CONF_ALLOW_SINGLE_WORD: True,
|
||||
CONF_ICON: "mdi:map",
|
||||
CONF_TITLE: title,
|
||||
CONF_URL_PATH: "map",
|
||||
}
|
||||
)
|
||||
|
||||
map_store: dashboard.LovelaceStorage = hass.data[DOMAIN]["dashboards"]["map"]
|
||||
await map_store.async_save({"strategy": {"type": "map"}})
|
||||
|
@ -12,16 +12,6 @@ from homeassistant.setup import async_setup_component
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_onboarding_not_done() -> Generator[MagicMock]:
|
||||
"""Mock that Home Assistant is currently onboarding."""
|
||||
with patch(
|
||||
"homeassistant.components.onboarding.async_is_onboarded",
|
||||
return_value=False,
|
||||
) as mock_onboarding:
|
||||
yield mock_onboarding
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_onboarding_done() -> Generator[MagicMock]:
|
||||
"""Mock that Home Assistant is currently onboarding."""
|
||||
@ -32,15 +22,6 @@ def mock_onboarding_done() -> Generator[MagicMock]:
|
||||
yield mock_onboarding
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_add_onboarding_listener() -> Generator[MagicMock]:
|
||||
"""Mock that Home Assistant is currently onboarding."""
|
||||
with patch(
|
||||
"homeassistant.components.onboarding.async_add_listener",
|
||||
) as mock_add_onboarding_listener:
|
||||
yield mock_add_onboarding_listener
|
||||
|
||||
|
||||
async def test_create_dashboards_when_onboarded(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
@ -57,42 +38,3 @@ async def test_create_dashboards_when_onboarded(
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == []
|
||||
|
||||
|
||||
async def test_create_dashboards_when_not_onboarded(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
hass_storage: dict[str, Any],
|
||||
mock_add_onboarding_listener,
|
||||
mock_onboarding_not_done,
|
||||
) -> None:
|
||||
"""Test we automatically create dashboards when not onboarded."""
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
assert await async_setup_component(hass, "lovelace", {})
|
||||
|
||||
# Call onboarding listener
|
||||
mock_add_onboarding_listener.mock_calls[0][1][1]()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# List dashboards
|
||||
await client.send_json_auto_id({"type": "lovelace/dashboards/list"})
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == [
|
||||
{
|
||||
"icon": "mdi:map",
|
||||
"id": "map",
|
||||
"mode": "storage",
|
||||
"require_admin": False,
|
||||
"show_in_sidebar": True,
|
||||
"title": "Map",
|
||||
"url_path": "map",
|
||||
}
|
||||
]
|
||||
|
||||
# List map dashboard config
|
||||
await client.send_json_auto_id({"type": "lovelace/config", "url_path": "map"})
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == {"strategy": {"type": "map"}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user