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>
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
"""Serve the solaredge-roof-card from the integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
from pathlib import Path
|
|
|
|
from homeassistant.components.frontend import add_extra_js_url
|
|
from homeassistant.components.http import StaticPathConfig
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import DOMAIN, LOGGER
|
|
|
|
CARD_FILE = Path(__file__).parent / "frontend" / "solaredge-roof-card.js"
|
|
CARD_URL = f"/{DOMAIN}/solaredge-roof-card.js"
|
|
|
|
|
|
def _file_hash(path: Path) -> str:
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()[:12]
|
|
|
|
|
|
async def async_register_card(hass: HomeAssistant) -> None:
|
|
"""Serve the card and load it in every frontend session."""
|
|
if hass.http is None or "frontend" not in hass.config.components:
|
|
LOGGER.debug("Frontend not loaded, solaredge-roof-card is not registered")
|
|
return
|
|
if not CARD_FILE.is_file():
|
|
LOGGER.warning("solaredge-roof-card bundle missing at %s", CARD_FILE)
|
|
return
|
|
version = await hass.async_add_executor_job(_file_hash, CARD_FILE)
|
|
await hass.http.async_register_static_paths(
|
|
[StaticPathConfig(CARD_URL, str(CARD_FILE), cache_headers=True)]
|
|
)
|
|
# The hash in the URL makes browsers load a new bundle after an update.
|
|
add_extra_js_url(hass, f"{CARD_URL}?v={version}")
|