Files
ha-solaredge-optimizers/tests/test_frontend.py
T
jensandClaude Opus 5.5 ce03c05d84 Add 3D roof view card for optimizer power
The integration now serves solaredge-roof-card and loads it in every
frontend session. The card shows the building in 3D with the current
power in W and the Panel-Position on every panel; the colour runs from
dark (0 W) to bright (Skalenmaximum, default 460 W). Failed panels are
grey and hatched, a tap opens the more-info dialog.

scripts/convert_portal_layout.py turns the SolarEdge portal's physical
layout and site model into the card's layout once, so nothing depends
on the portal at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 13:25:47 +01:00

34 lines
1.3 KiB
Python

"""Tests for serving the solaredge-roof-card."""
from __future__ import annotations
from unittest.mock import AsyncMock, MagicMock, patch
from homeassistant.core import HomeAssistant
from custom_components.solaredge_optimizers import frontend
async def test_card_is_served_and_loaded(hass: HomeAssistant) -> None:
"""Register the bundle as static path and as extra frontend module."""
hass.http = MagicMock(async_register_static_paths=AsyncMock())
hass.config.components.add("frontend")
with patch.object(frontend, "add_extra_js_url") as add_url:
await frontend.async_register_card(hass)
(paths,), _ = hass.http.async_register_static_paths.call_args
assert paths[0].url_path == "/solaredge_optimizers/solaredge-roof-card.js"
assert paths[0].path.endswith("frontend/solaredge-roof-card.js")
(_, url), _ = add_url.call_args
assert url.startswith("/solaredge_optimizers/solaredge-roof-card.js?v=")
async def test_card_is_skipped_without_frontend(hass: HomeAssistant) -> None:
"""Do nothing when Home Assistant runs without frontend."""
hass.http = MagicMock(async_register_static_paths=AsyncMock())
with patch.object(frontend, "add_extra_js_url") as add_url:
await frontend.async_register_card(hass)
hass.http.async_register_static_paths.assert_not_called()
add_url.assert_not_called()