mirror of
https://github.com/home-assistant/frontend.git
synced 2026-07-28 08:56:19 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cc98e363cc | |||
| e34c1b9857 | |||
| 06580f3dbc | |||
| fe8f32423f | |||
| b14343b831 | |||
| f7d3ce7ba1 | |||
| 5ce9c479c9 | |||
| 4b4d05fd8c | |||
| 972ade22bf | |||
| 0e2a5e414b | |||
| 428a21175e |
@@ -44,3 +44,13 @@ http://localhost:8090/?demo=<second slug>#/energy/water
|
||||
- `src/configs/demo-configs.ts`: Registry of demo configurations and URL slug handling.
|
||||
- `src/stubs/`: Mocked WebSocket/REST APIs.
|
||||
- `script/develop_demo`, `script/build_demo`: Dev server and static build wrappers.
|
||||
|
||||
## The gallery imports these stubs too
|
||||
|
||||
`demo/src/stubs/` is shared, not demo-private: gallery pages import from it directly. Before changing or removing anything a stub does, grep for its callers across `gallery/` as well as `demo/`, and check the affected gallery pages, not just the demo.
|
||||
|
||||
```bash
|
||||
grep -rn "stubs/<name>" demo/src gallery/src
|
||||
```
|
||||
|
||||
The two consume a stub differently, so demo behavior does not predict gallery behavior. A gallery page calls stubs against the `hass` from `provideHass`, where `hass.config` is the shared `demoConfig` object, so a stub that mutates `hass.config` in place is visible to the page. `ha-demo.ts` copies `components` into a new array before the stubs run, so the same mutation never reaches the demo. A change can therefore look fine in the demo while quietly breaking a gallery page.
|
||||
|
||||
+6
-4
@@ -16,6 +16,8 @@ import { mockEntityRegistry } from "./stubs/entity_registry";
|
||||
import { mockEvents } from "./stubs/events";
|
||||
import { mockFloorRegistry, setDemoFloors } from "./stubs/floor_registry";
|
||||
import { mockFrontend } from "./stubs/frontend";
|
||||
import { mockHardware } from "./stubs/hardware";
|
||||
import { mockHassioSupervisor } from "./stubs/hassio_supervisor";
|
||||
import { mockIntegration } from "./stubs/integration";
|
||||
import { mockLabelRegistry } from "./stubs/label_registry";
|
||||
import { mockIcons } from "./stubs/icons";
|
||||
@@ -73,10 +75,6 @@ export class HaDemo extends HomeAssistantAppEl {
|
||||
// `contextMixin`, so let provideHass skip them to avoid duplicate providers.
|
||||
const hass = provideHass(this, initial, true, false);
|
||||
|
||||
// The cloud account page only fetches backup config and the webhook count
|
||||
// when those integrations are loaded. Enable them here (demo only) so the
|
||||
// mocked backup/config/info and webhook/list are queried. usage_prediction
|
||||
// is needed for common-controls sections in strategy dashboards.
|
||||
hass.updateHass({
|
||||
config: {
|
||||
...hass.config,
|
||||
@@ -86,6 +84,8 @@ export class HaDemo extends HomeAssistantAppEl {
|
||||
"webhook",
|
||||
"usage_prediction",
|
||||
"assist_pipeline",
|
||||
"hassio",
|
||||
"hardware",
|
||||
],
|
||||
},
|
||||
});
|
||||
@@ -113,6 +113,8 @@ export class HaDemo extends HomeAssistantAppEl {
|
||||
mockEvents(hass);
|
||||
mockMediaPlayer(hass);
|
||||
mockFrontend(hass);
|
||||
mockHardware(hass);
|
||||
mockHassioSupervisor(hass);
|
||||
mockIcons(hass);
|
||||
mockEnergy(hass);
|
||||
mockPersistentNotification(hass);
|
||||
|
||||
@@ -34,8 +34,16 @@
|
||||
content="width=device-width, initial-scale=1, shrink-to-fit=no"
|
||||
/>
|
||||
<meta name="theme-color" content="#03a9f4" />
|
||||
<link rel="preload" href="/static/fonts/roboto/Roboto-Regular.woff2" as="font" type="font/woff2" crossorigin>
|
||||
<%= renderTemplate("_social_meta.html.template") %>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: "Roboto Launch Screen";
|
||||
font-display: block;
|
||||
src: url("/static/fonts/roboto/Roboto-Regular.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
html {
|
||||
background-color: var(--primary-background-color, #fafafa);
|
||||
color: var(--primary-text-color, #212121);
|
||||
@@ -56,15 +64,38 @@
|
||||
padding: 0;
|
||||
}
|
||||
#ha-launch-screen {
|
||||
font-family: "Roboto Launch Screen", sans-serif;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
transition: opacity var(--ha-animation-duration-normal, 250ms) ease-out;
|
||||
}
|
||||
#ha-launch-screen svg {
|
||||
width: 112px;
|
||||
#ha-launch-screen.removing {
|
||||
opacity: 0;
|
||||
}
|
||||
@keyframes launch-lockup-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
#ha-launch-screen .ha-lockup {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
animation: launch-lockup-in var(--ha-animation-duration-normal, 250ms) ease-out both;
|
||||
}
|
||||
#ha-launch-screen-info-box > *,
|
||||
#ha-launch-screen .ohf-logo {
|
||||
animation: launch-lockup-in var(--ha-animation-duration-normal, 250ms) ease-out both;
|
||||
}
|
||||
#ha-launch-screen .ha-logo {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
}
|
||||
#ha-launch-screen .ha-launch-screen-spacer-top {
|
||||
flex: 1;
|
||||
@@ -80,11 +111,32 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
opacity: .66;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.ohf-logo span {
|
||||
font-size: 12px;
|
||||
line-height: 12px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.ohf-logo picture {
|
||||
display: flex;
|
||||
}
|
||||
.ohf-logo img {
|
||||
width: 237px;
|
||||
aspect-ratio: 237 / 24;
|
||||
height: auto;
|
||||
}
|
||||
@media (max-height: 560px) {
|
||||
#ha-launch-screen .ha-launch-screen-spacer-top {
|
||||
margin-top: 24px;
|
||||
padding-top: 24px;
|
||||
}
|
||||
#ha-launch-screen .ha-launch-screen-spacer-bottom {
|
||||
padding-top: 16px;
|
||||
}
|
||||
.ohf-logo {
|
||||
filter: invert(1);
|
||||
margin-block: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -92,13 +144,16 @@
|
||||
<body>
|
||||
<div id="ha-launch-screen">
|
||||
<div class="ha-launch-screen-spacer-top"></div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240">
|
||||
<path fill="#18BCF2" d="M240 224.762a15 15 0 0 1-15 15H15a15 15 0 0 1-15-15v-90c0-8.25 4.77-19.769 10.61-25.609l98.78-98.7805c5.83-5.83 15.38-5.83 21.21 0l98.79 98.7895c5.83 5.83 10.61 17.36 10.61 25.61v90-.01Z"/>
|
||||
<path fill="#F2F4F9" d="m107.27 239.762-40.63-40.63c-2.09.72-4.32 1.13-6.64 1.13-11.3 0-20.5-9.2-20.5-20.5s9.2-20.5 20.5-20.5 20.5 9.2 20.5 20.5c0 2.33-.41 4.56-1.13 6.65l31.63 31.63v-115.88c-6.8-3.3395-11.5-10.3195-11.5-18.3895 0-11.3 9.2-20.5 20.5-20.5s20.5 9.2 20.5 20.5c0 8.07-4.7 15.05-11.5 18.3895v81.27l31.46-31.46c-.62-1.96-.96-4.04-.96-6.2 0-11.3 9.2-20.5 20.5-20.5s20.5 9.2 20.5 20.5-9.2 20.5-20.5 20.5c-2.5 0-4.88-.47-7.09-1.29L129 208.892v30.88z"/>
|
||||
</svg>
|
||||
<div class="ha-lockup">
|
||||
<img class="ha-logo" src="/static/images/home-assistant-logo-loading.svg" alt="Home Assistant">
|
||||
</div>
|
||||
<div id="ha-launch-screen-info-box" class="ha-launch-screen-spacer-bottom"></div>
|
||||
<div class="ohf-logo">
|
||||
<img src="/static/images/ohf-badge.svg" alt="Home Assistant is a project by the Open Home Foundation" height="46">
|
||||
<span id="ha-launch-screen-attribution">A project from the</span>
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="/static/images/open-home-foundation-on-dark.svg">
|
||||
<img src="/static/images/open-home-foundation-on-light.svg" alt="Open Home Foundation" width="237" height="24">
|
||||
</picture>
|
||||
</div>
|
||||
</div>
|
||||
<ha-demo></ha-demo>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import type {
|
||||
HardwareInfo,
|
||||
SystemStatusStreamMessage,
|
||||
} from "../../../src/data/hardware";
|
||||
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||
|
||||
// Mirrors what homeassistant_green reports, so the hardware page resolves the
|
||||
// board name and the brands image the same way it does on a real Green.
|
||||
const HARDWARE_INFO: HardwareInfo = {
|
||||
hardware: [
|
||||
{
|
||||
board: {
|
||||
hassio_board_id: "green",
|
||||
manufacturer: "homeassistant",
|
||||
model: "green",
|
||||
},
|
||||
dongle: null,
|
||||
config_entries: [],
|
||||
name: "Home Assistant Green",
|
||||
url: "https://support.nabucasa.com/hc/en-us/categories/24638797677853-Home-Assistant-Green",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const mockHardware = (hass: MockHomeAssistant) => {
|
||||
hass.mockWS("hardware/info", () => HARDWARE_INFO);
|
||||
|
||||
hass.mockWS(
|
||||
"hardware/subscribe_system_status",
|
||||
(_msg, _currentHass, onChange) => {
|
||||
// Rounded like the hardware integration rounds psutil's values.
|
||||
const send = () => {
|
||||
const usedMb = 1560 + Math.round(Math.random() * 80);
|
||||
const message: SystemStatusStreamMessage = {
|
||||
cpu_percent: Math.round((8 + Math.random() * 6) * 10) / 10,
|
||||
memory_free_mb: 4096 - usedMb,
|
||||
memory_used_mb: usedMb,
|
||||
memory_used_percent: Math.round((usedMb / 4096) * 1000) / 10,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
onChange?.(message);
|
||||
};
|
||||
send();
|
||||
const interval = window.setInterval(send, 1000);
|
||||
return () => clearInterval(interval);
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -1,59 +1,385 @@
|
||||
import type { HassioSupervisorInfo } from "../../../src/data/hassio/supervisor";
|
||||
import type {
|
||||
HassioAddonDetails,
|
||||
HassioAddonInfo,
|
||||
HassioAddonsInfo,
|
||||
} from "../../../src/data/hassio/addon";
|
||||
import type { HassioStats } from "../../../src/data/hassio/common";
|
||||
import type {
|
||||
HassioHassOSInfo,
|
||||
HassioHostInfo,
|
||||
HostDisksUsage,
|
||||
} from "../../../src/data/hassio/host";
|
||||
import type { NetworkInfo } from "../../../src/data/hassio/network";
|
||||
import type {
|
||||
HassioInfo,
|
||||
HassioSupervisorInfo,
|
||||
} from "../../../src/data/hassio/supervisor";
|
||||
import type { SupervisorMounts } from "../../../src/data/supervisor/mounts";
|
||||
import type { SupervisorUpdateConfig } from "../../../src/data/supervisor/update";
|
||||
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||
|
||||
// `icon`/`logo` are false on purpose: the panel would otherwise request
|
||||
// /api/hassio/addons/<slug>/icon, which the demo has no backend for.
|
||||
const DEMO_ADDONS: HassioAddonInfo[] = [
|
||||
{
|
||||
name: "Music Assistant",
|
||||
slug: "d5369777_music_assistant",
|
||||
description:
|
||||
"Music library manager for all your media sources and streaming services, with support for a wide range of players",
|
||||
advanced: false,
|
||||
available: true,
|
||||
build: false,
|
||||
detached: false,
|
||||
homeassistant: "2025.7.0",
|
||||
icon: false,
|
||||
installed: true,
|
||||
logo: false,
|
||||
repository: "d5369777",
|
||||
stage: "stable",
|
||||
state: "started",
|
||||
update_available: false,
|
||||
url: "https://github.com/music-assistant/home-assistant-addon",
|
||||
version: "2.6.3",
|
||||
version_latest: "2.6.3",
|
||||
},
|
||||
{
|
||||
name: "ESPHome Device Builder",
|
||||
slug: "5c53de3b_esphome",
|
||||
description:
|
||||
"Manage and program your ESP8266/ESP32 based microcontrollers directly via WiFi and with a simple, yet powerful configuration file syntax",
|
||||
advanced: false,
|
||||
available: true,
|
||||
build: false,
|
||||
detached: false,
|
||||
homeassistant: "2025.7.0",
|
||||
icon: false,
|
||||
installed: true,
|
||||
logo: false,
|
||||
repository: "5c53de3b",
|
||||
stage: "stable",
|
||||
state: "started",
|
||||
update_available: false,
|
||||
url: "https://esphome.io/",
|
||||
version: "2025.7.3",
|
||||
version_latest: "2025.7.3",
|
||||
},
|
||||
];
|
||||
|
||||
const LONG_DESCRIPTIONS: Record<string, string> = {
|
||||
d5369777_music_assistant: `## Music Assistant
|
||||
|
||||
Music Assistant brings all your music sources together in one library and streams
|
||||
them to the players you already own.
|
||||
|
||||
- Combines local files with streaming services into a single searchable library
|
||||
- Plays to Sonos, Chromecast, AirPlay, Squeezebox, DLNA and Home Assistant media players
|
||||
- Group players together for synced multi-room audio
|
||||
- Exposes players and playlists to Home Assistant automations and voice assistants`,
|
||||
"5c53de3b_esphome": `## ESPHome Device Builder
|
||||
|
||||
ESPHome turns an ESP8266 or ESP32 into a Home Assistant device using a short YAML
|
||||
configuration instead of hand-written firmware.
|
||||
|
||||
- Compile and flash firmware straight from the browser, over WiFi after the first flash
|
||||
- Hundreds of supported sensors, displays, lights and switches
|
||||
- Devices are discovered by Home Assistant automatically, with no cloud in between
|
||||
- Configuration lives next to your Home Assistant config, so it is covered by backups`,
|
||||
};
|
||||
|
||||
// Supervisor schema format (converted to selectors by the config tab). Music
|
||||
// Assistant is configured in its own UI, so it has no add-on options.
|
||||
const CONFIG_SCHEMAS: Record<string, HassioAddonDetails["schema"]> = {
|
||||
"5c53de3b_esphome": [
|
||||
{ name: "ssl", type: "boolean", required: true },
|
||||
{ name: "certfile", type: "string", required: true },
|
||||
{ name: "keyfile", type: "string", required: true },
|
||||
{ name: "leave_front_door_open", type: "boolean", required: false },
|
||||
{ name: "status_use_ping", type: "boolean", required: false },
|
||||
],
|
||||
};
|
||||
|
||||
const CONFIG_OPTIONS: Record<string, Record<string, unknown>> = {
|
||||
"5c53de3b_esphome": {
|
||||
ssl: false,
|
||||
certfile: "fullchain.pem",
|
||||
keyfile: "privkey.pem",
|
||||
},
|
||||
};
|
||||
|
||||
const addonDetails = (addon: HassioAddonInfo): HassioAddonDetails => ({
|
||||
...addon,
|
||||
apparmor: "default",
|
||||
arch: ["aarch64", "amd64"],
|
||||
audio_input: null,
|
||||
audio_output: null,
|
||||
audio: false,
|
||||
auth_api: false,
|
||||
auto_uart: false,
|
||||
auto_update: false,
|
||||
boot: "auto",
|
||||
changelog: false,
|
||||
devices: [],
|
||||
devicetree: false,
|
||||
discovery: [],
|
||||
docker_api: false,
|
||||
documentation: false,
|
||||
full_access: false,
|
||||
gpio: false,
|
||||
hassio_api: false,
|
||||
hassio_role: "default",
|
||||
hostname: addon.slug.replace(/_/g, "-"),
|
||||
homeassistant_api: false,
|
||||
host_dbus: false,
|
||||
host_ipc: false,
|
||||
host_network: false,
|
||||
host_pid: false,
|
||||
ingress_entry: null,
|
||||
ingress_panel: false,
|
||||
ingress_url: null,
|
||||
ingress: false,
|
||||
ip_address: "172.30.33.2",
|
||||
kernel_modules: false,
|
||||
long_description: LONG_DESCRIPTIONS[addon.slug],
|
||||
machine: [],
|
||||
network_description: null,
|
||||
network: null,
|
||||
options: CONFIG_OPTIONS[addon.slug] ?? {},
|
||||
privileged: [],
|
||||
protected: true,
|
||||
rating: 6,
|
||||
schema: CONFIG_SCHEMAS[addon.slug] ?? null,
|
||||
services_role: [],
|
||||
signed: false,
|
||||
startup: "application",
|
||||
stdin: false,
|
||||
system_managed: false,
|
||||
system_managed_config_entry: null,
|
||||
translations: {},
|
||||
watchdog: true,
|
||||
webui: null,
|
||||
});
|
||||
|
||||
const LOGS: Record<string, string> = {
|
||||
d5369777_music_assistant: `[server] Starting Music Assistant Server 2.6.3
|
||||
[server] Loaded provider: filesystem_local
|
||||
[server] Loaded provider: spotify
|
||||
[server] Loaded provider: sonos
|
||||
[players] Discovered player: Living Room (Sonos)
|
||||
[players] Discovered player: Kitchen (Chromecast)
|
||||
[server] Music Assistant is ready
|
||||
`,
|
||||
"5c53de3b_esphome": `[esphome] Starting ESPHome Device Builder 2025.7.3
|
||||
[esphome] Dashboard running on port 6052
|
||||
[esphome] Found 3 configurations
|
||||
[esphome] bedroom-sensor is online (2025.7.3)
|
||||
[esphome] garage-door is online (2025.7.3)
|
||||
[esphome] office-display is online (2025.7.3)
|
||||
`,
|
||||
};
|
||||
|
||||
const ADDON_STATS: HassioStats = {
|
||||
blk_read: 12300000,
|
||||
blk_write: 4500000,
|
||||
cpu_percent: 1.4,
|
||||
memory_limit: 3900000000,
|
||||
memory_percent: 4.2,
|
||||
memory_usage: 163000000,
|
||||
network_rx: 8900000,
|
||||
network_tx: 2300000,
|
||||
};
|
||||
|
||||
export const mockHassioSupervisor = (hass: MockHomeAssistant) => {
|
||||
hass.config.components.push("hassio");
|
||||
// Gallery pages rely on this to enable the hassio-gated pickers. The demo
|
||||
// lists hassio in its own components, hence the guard against duplicates.
|
||||
if (!hass.config.components.includes("hassio")) {
|
||||
hass.config.components.push("hassio");
|
||||
}
|
||||
|
||||
hass.mockWS("supervisor/api", (msg) => {
|
||||
if (msg.endpoint === "/supervisor/info") {
|
||||
const data: HassioSupervisorInfo = {
|
||||
version: "2021.10.dev0805",
|
||||
version_latest: "2021.10.dev0806",
|
||||
update_available: true,
|
||||
channel: "dev",
|
||||
version: "2026.07.1",
|
||||
version_latest: "2026.07.1",
|
||||
update_available: false,
|
||||
channel: "stable",
|
||||
arch: "aarch64",
|
||||
supported: true,
|
||||
healthy: true,
|
||||
ip_address: "172.30.32.2",
|
||||
wait_boot: 5,
|
||||
timezone: "America/Los_Angeles",
|
||||
timezone: "Europe/Amsterdam",
|
||||
logging: "info",
|
||||
debug: false,
|
||||
debug_block: false,
|
||||
diagnostics: true,
|
||||
addons: [
|
||||
{
|
||||
name: "Visual Studio Code",
|
||||
slug: "a0d7b954_vscode",
|
||||
description:
|
||||
"Fully featured VSCode experience, to edit your HA config in the browser, including auto-completion!",
|
||||
state: "started",
|
||||
version: "3.6.2",
|
||||
version_latest: "3.6.2",
|
||||
update_available: false,
|
||||
repository: "a0d7b954",
|
||||
icon: false,
|
||||
logo: true,
|
||||
},
|
||||
{
|
||||
name: "Z-Wave JS",
|
||||
slug: "core_zwave_js",
|
||||
description:
|
||||
"Control a ZWave network with Home Assistant Z-Wave JS",
|
||||
state: "started",
|
||||
version: "0.1.45",
|
||||
version_latest: "0.1.45",
|
||||
update_available: false,
|
||||
repository: "core",
|
||||
icon: true,
|
||||
logo: true,
|
||||
},
|
||||
] as any,
|
||||
addons: DEMO_ADDONS as any,
|
||||
addons_repositories: [
|
||||
"https://github.com/hassio-addons/repository",
|
||||
"https://github.com/music-assistant/home-assistant-addon",
|
||||
"https://github.com/esphome/home-assistant-addon",
|
||||
] as any,
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/addons") {
|
||||
const data: HassioAddonsInfo = {
|
||||
addons: DEMO_ADDONS,
|
||||
repositories: [
|
||||
{
|
||||
slug: "d5369777",
|
||||
name: "Music Assistant",
|
||||
source: "https://github.com/music-assistant/home-assistant-addon",
|
||||
url: "https://github.com/music-assistant/home-assistant-addon",
|
||||
maintainer: "Music Assistant",
|
||||
},
|
||||
{
|
||||
slug: "5c53de3b",
|
||||
name: "ESPHome",
|
||||
source: "https://github.com/esphome/home-assistant-addon",
|
||||
url: "https://esphome.io/",
|
||||
maintainer: "ESPHome",
|
||||
},
|
||||
],
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
const addonMatch = msg.endpoint.match(/^\/addons\/([^/]+)\/(info|stats)$/);
|
||||
if (addonMatch) {
|
||||
const addon = DEMO_ADDONS.find((item) => item.slug === addonMatch[1]);
|
||||
if (!addon) {
|
||||
return Promise.reject(`Addon ${addonMatch[1]} not found`);
|
||||
}
|
||||
return addonMatch[2] === "stats" ? ADDON_STATS : addonDetails(addon);
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/info") {
|
||||
const data: HassioInfo = {
|
||||
arch: "aarch64",
|
||||
channel: "stable",
|
||||
docker: "27.5.1",
|
||||
features: ["reboot", "shutdown", "network", "hostname", "os_agent"],
|
||||
hassos: null,
|
||||
homeassistant: "2026.7.2",
|
||||
hostname: "homeassistant",
|
||||
logging: "info",
|
||||
machine: "green",
|
||||
state: "running",
|
||||
operating_system: "Home Assistant OS 18.2",
|
||||
supervisor: "2026.07.1",
|
||||
supported: true,
|
||||
supported_arch: ["aarch64", "armv7", "armhf"],
|
||||
timezone: "Europe/Amsterdam",
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/host/info") {
|
||||
const data: HassioHostInfo = {
|
||||
agent_version: "1.8.0",
|
||||
chassis: "embedded",
|
||||
cpe: "cpe:2.3:o:home-assistant:haos:18.2:*:production:*:*:*:aarch64:*",
|
||||
deployment: "production",
|
||||
disk_life_time: 6,
|
||||
disk_free: 22.3,
|
||||
disk_total: 31.2,
|
||||
disk_used: 8.9,
|
||||
features: ["reboot", "shutdown", "network", "hostname", "os_agent"],
|
||||
hostname: "homeassistant",
|
||||
kernel: "6.12.48-haos",
|
||||
operating_system: "Home Assistant OS 18.2",
|
||||
boot_timestamp: 1751932800000000,
|
||||
startup_time: 12.4,
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/os/info") {
|
||||
const data: HassioHassOSInfo = {
|
||||
board: "green",
|
||||
boot: "A",
|
||||
update_available: false,
|
||||
version: "18.2",
|
||||
version_latest: "18.2",
|
||||
data_disk: "Home Assistant Green (mmcblk0)",
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/host/disks/default/usage") {
|
||||
const data: HostDisksUsage = {
|
||||
id: "root",
|
||||
label: "Total",
|
||||
total_bytes: 31200000000,
|
||||
used_bytes: 8900000000,
|
||||
children: [
|
||||
{ id: "media", label: "Media", used_bytes: 4100000000 },
|
||||
{ id: "addons", label: "Apps", used_bytes: 2600000000 },
|
||||
{ id: "backup", label: "Backups", used_bytes: 1400000000 },
|
||||
{ id: "share", label: "Share", used_bytes: 800000000 },
|
||||
],
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/mounts") {
|
||||
const data: SupervisorMounts = {
|
||||
default_backup_mount: null,
|
||||
mounts: [],
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/network/info") {
|
||||
const data: NetworkInfo = {
|
||||
interfaces: [
|
||||
{
|
||||
primary: true,
|
||||
privacy: false,
|
||||
interface: "eth0",
|
||||
enabled: true,
|
||||
type: "ethernet",
|
||||
ipv4: {
|
||||
address: ["192.168.1.10/24"],
|
||||
gateway: "192.168.1.1",
|
||||
method: "auto",
|
||||
nameservers: ["192.168.1.1"],
|
||||
},
|
||||
wifi: null,
|
||||
},
|
||||
],
|
||||
docker: {
|
||||
address: "172.30.32.0/23",
|
||||
dns: "172.30.32.3",
|
||||
gateway: "172.30.32.1",
|
||||
interface: "hassio",
|
||||
},
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
if (msg.endpoint === "/store/reload") {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Promise.reject(`${msg.method} ${msg.endpoint} is not implemented`);
|
||||
});
|
||||
|
||||
hass.mockWS("hassio/update/config/info", (): SupervisorUpdateConfig => ({
|
||||
add_on_backup_before_update: true,
|
||||
add_on_backup_retain_copies: 1,
|
||||
core_backup_before_update: true,
|
||||
}));
|
||||
|
||||
hass.mockAPI(/^hassio\/host\/logs\/boots$/, () => ({
|
||||
data: { boots: { "0": "2026-07-26T09:00:00.000000+00:00" } },
|
||||
}));
|
||||
|
||||
hass.mockAPI(/^hassio\/addons\/[^/]+\/logs/, (_hass, _method, path) => {
|
||||
const slug = path.split("/")[2];
|
||||
// X-First-Cursor tells error-log-card there is nothing older to page to.
|
||||
return new Response(LOGS[slug], {
|
||||
headers: { "X-First-Cursor": "demo" },
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" role="presentation">
|
||||
<style>
|
||||
.dot-left { animation: pulse-left 1300ms 350ms linear infinite; }
|
||||
.dot-right { animation: pulse-right 1300ms 350ms linear infinite; }
|
||||
.dot-top { animation: pulse-top 1300ms 350ms linear infinite; }
|
||||
@keyframes pulse-left {
|
||||
0% { transform: translate(50px, 69.634804px) scale(1); animation-timing-function: cubic-bezier(.39, .575, .565, 1); }
|
||||
15.384615% { transform: translate(50px, 69.634804px) scale(1.3); animation-timing-function: cubic-bezier(.39, .575, .565, 1); }
|
||||
38.461538%, 100% { transform: translate(50px, 69.634804px) scale(1); }
|
||||
}
|
||||
@keyframes pulse-right {
|
||||
0%, 15.384615% { transform: translate(90px, 58.634798px) scale(1); }
|
||||
15.384615% { animation-timing-function: cubic-bezier(.39, .575, .565, 1); }
|
||||
30.769231% { transform: translate(90px, 58.634798px) scale(1.3); animation-timing-function: cubic-bezier(.39, .575, .565, 1); }
|
||||
53.846154%, 100% { transform: translate(90px, 58.634798px) scale(1); }
|
||||
}
|
||||
@keyframes pulse-top {
|
||||
0%, 30.769231% { transform: translate(70px, 37.6348px) scale(1); }
|
||||
30.769231% { animation-timing-function: cubic-bezier(.39, .575, .565, 1); }
|
||||
46.153846% { transform: translate(70px, 37.6348px) scale(1.3); animation-timing-function: cubic-bezier(.39, .575, .565, 1); }
|
||||
69.230769%, 100% { transform: translate(70px, 37.6348px) scale(1); }
|
||||
}
|
||||
</style>
|
||||
<g transform="matrix(.938408 0 0 .93841 -5.688557 -13.572944)">
|
||||
<path fill="#18bcf2" d="M73.5367 13.0937 106.463 46.0524v.0033C108.41 48.0043 110 51.848 110 54.6007v30.0292c0 2.7527-2.25 5.0049-5 5.0049l-70-.0034c-2.75 0-5-2.2522-5-5.0048V54.5974c0-2.7527 1.5933-6.5998 3.5367-8.545l32.93-32.9587c1.9433-1.9452 5.1266-1.9452 7.07 0Z" transform="matrix(1.598452 0 0 1.598452 -41.89164 -.937304)"/>
|
||||
<g mask="url(#logo-mask)" transform="matrix(1.598452 0 0 1.598452 -41.89164 -.937311)">
|
||||
<path d="m70 89.6348-20-20M70 89.6348v-52M90 58.1348l-20 20" fill="none" stroke="#f2f4f9" stroke-linecap="round" stroke-width="6"/>
|
||||
<circle class="dot-left" r="7" fill="#f2f4f9" transform="translate(50 69.634804)"/>
|
||||
<circle class="dot-right" r="7" fill="#f2f4f9" transform="translate(90 58.634798)"/>
|
||||
<circle class="dot-top" r="7" fill="#f2f4f9" transform="translate(70 37.6348)"/>
|
||||
</g>
|
||||
<mask id="logo-mask" x="-150%" y="-150%" width="400%" height="400%" mask-type="luminance">
|
||||
<path fill="#f2f4f9" d="M73.5367 13.0937 106.463 46.0524v.0033C108.41 48.0043 110 51.848 110 54.6007v30.0292c0 2.7527-2.25 5.0049-5 5.0049l-70-.0034c-2.75 0-5-2.2522-5-5.0048V54.5974c0-2.7527 1.5933-6.5998 3.5367-8.545l32.93-32.9587c1.9433-1.9452 5.1266-1.9452 7.07 0Z"/>
|
||||
</mask>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
@@ -0,0 +1,22 @@
|
||||
<svg width="237" height="24" viewBox="0 0 237 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.54181 0.297615C8.14709 -0.0992051 7.5012 -0.0992051 7.1082 0.297615L0.717655 6.72232C0.322945 7.11914 0 7.90248 0 8.46249V14.2894C0 14.8494 0.456224 15.3098 1.01497 15.3098H14.635C15.1921 15.3098 15.65 14.8511 15.65 14.2894V8.46249C15.65 7.90248 15.3271 7.11914 14.9324 6.72232L8.54181 0.297615Z" fill="#F7F6F2"/>
|
||||
<path d="M14.8672 17.918C15.2993 17.918 15.6502 18.2682 15.6504 18.7002V22.417C15.6504 22.8492 15.2994 23.2002 14.8672 23.2002H13.8896C13.4575 23.2002 13.1064 22.8492 13.1064 22.417V20.4609H2.54297V22.417C2.54297 22.8491 2.19285 23.2001 1.76074 23.2002H0.782227C0.350189 23.2 0 22.8491 0 22.417V18.7002C0.000147852 18.2682 0.350281 17.9181 0.782227 17.918H14.8672Z" fill="#F7F6F2"/>
|
||||
<path d="M28.0439 5.24023C28.9236 5.24023 29.7386 5.39857 30.4891 5.71734C31.2396 6.03402 31.8754 6.47362 32.3965 7.03406C32.9177 7.5945 33.3242 8.26536 33.616 9.05081C33.9058 9.83625 34.0517 10.6842 34.0517 11.5967C34.0621 12.4989 33.9204 13.3447 33.6285 14.1385C33.3346 14.9323 32.9239 15.6094 32.3965 16.1719C31.8691 16.7344 31.227 17.1761 30.4724 17.4949C29.7178 17.8157 28.9027 17.9699 28.0272 17.9595C26.8702 17.9762 25.83 17.7095 24.9086 17.1616C23.9872 16.6136 23.2764 15.8532 22.7761 14.8802C22.2757 13.9073 22.0339 12.8176 22.0506 11.6134C22.0402 10.7113 22.1819 9.86542 22.4738 9.07164C22.7677 8.27786 23.1763 7.60075 23.7016 7.03406C24.2269 6.46945 24.8648 6.02568 25.6174 5.70692C26.3699 5.38816 27.1787 5.2319 28.0439 5.24232V5.24023ZM28.0584 15.524C29.0966 15.524 29.9179 15.1719 30.5245 14.4698C31.1312 13.7656 31.4334 12.8093 31.4334 11.5967C31.4334 10.3842 31.1312 9.41332 30.5287 8.71121C29.9262 8.01118 29.1028 7.66117 28.0584 7.66117C27.0141 7.66117 26.1906 8.01118 25.5882 8.71121C24.9857 9.41124 24.6835 10.3738 24.6835 11.5967C24.6835 12.8197 24.9857 13.7802 25.5882 14.4781C26.1906 15.1761 27.0141 15.5261 28.0584 15.5261V15.524Z" fill="#F7F6F2"/>
|
||||
<path d="M44.9854 9.52582C44.9854 10.7592 44.6123 11.7509 43.8681 12.503C43.1239 13.2551 42.1108 13.6322 40.8267 13.6322H38.3898V17.7553H35.9028V5.45899H40.86C42.1483 5.45899 43.1572 5.82151 43.8889 6.54654C44.6206 7.27157 44.9854 8.26536 44.9854 9.52374V9.52582ZM42.3588 9.47791C42.3588 8.95705 42.19 8.52578 41.8502 8.18619C41.5104 7.84659 41.0205 7.67783 40.3785 7.67783H38.3898V11.4676H40.3785C41.0247 11.4676 41.5167 11.2842 41.8544 10.9175C42.1921 10.5509 42.3588 10.0717 42.3588 9.47999V9.47791Z" fill="#F7F6F2"/>
|
||||
<path d="M54.4829 17.7553H46.7386V5.45899H54.4829V7.82159H49.2234V10.4446H53.895V12.6447H49.2234V15.4156H54.4829V17.7553Z" fill="#F7F6F2"/>
|
||||
<path d="M67.397 5.46108V17.7574H64.9268L59.5381 9.42999V17.7574H57.0678V5.46108H59.5381L64.9268 13.8052V5.46108H67.397Z" fill="#F7F6F2"/>
|
||||
<path d="M74.4409 5.46108H76.9279V10.4321L81.8037 10.4488V5.46108H84.3074V17.7574H81.8037V12.6655L76.9279 12.6322V17.7574H74.4409V5.46108Z" fill="#F7F6F2"/>
|
||||
<path d="M92.133 5.24023C93.0127 5.24023 93.8278 5.39857 94.5782 5.71734C95.3287 6.03402 95.9645 6.47362 96.4856 7.03406C97.0068 7.5945 97.4133 8.26536 97.7051 9.05081C97.9949 9.83625 98.1408 10.6842 98.1408 11.5967C98.1512 12.4989 98.0095 13.3447 97.7176 14.1385C97.4237 14.9323 97.013 15.6094 96.4856 16.1719C95.9582 16.7344 95.3162 17.1761 94.5615 17.4949C93.8069 17.8157 92.9918 17.9699 92.1163 17.9595C90.9593 17.9762 89.9191 17.7095 88.9977 17.1616C88.0763 16.6136 87.3655 15.8532 86.8652 14.8802C86.3649 13.9073 86.1231 12.8176 86.1397 11.6134C86.1293 10.7113 86.2711 9.86542 86.5629 9.07164C86.8568 8.27786 87.2654 7.60075 87.7907 7.03406C88.3161 6.46945 88.954 6.02568 89.7065 5.70692C90.459 5.38816 91.2679 5.2319 92.133 5.24232V5.24023ZM92.1476 15.524C93.1857 15.524 94.007 15.1719 94.6137 14.4698C95.2203 13.7656 95.5225 12.8093 95.5225 11.5967C95.5225 10.3842 95.2203 9.41332 94.6178 8.71121C94.0154 8.01118 93.192 7.66117 92.1476 7.66117C91.1032 7.66117 90.2798 8.01118 89.6773 8.71121C89.0749 9.41124 88.7726 10.3738 88.7726 11.5967C88.7726 12.8197 89.0749 13.7802 89.6773 14.4781C90.2798 15.1761 91.1032 15.5261 92.1476 15.5261V15.524Z" fill="#F7F6F2"/>
|
||||
<path d="M112.408 5.46108V17.7574H109.954V11.0342L107.321 17.7574H104.966L102.364 11.0842V17.7574H99.9919V5.46108H102.364L106.148 14.8552L109.954 5.46108H112.408Z" fill="#F7F6F2"/>
|
||||
<path d="M122.762 17.7553H115.018V5.45899H122.762V7.82159H117.503V10.4446H122.174V12.6447H117.503V15.4156H122.762V17.7553Z" fill="#F7F6F2"/>
|
||||
<path d="M131.526 7.21579V10.9075H136.254V12.5936H131.526V17.7408H129.65V5.44079H137.146V7.21579H131.526Z" fill="#F7F6F2"/>
|
||||
<path d="M144.303 5.24079C145.156 5.22968 145.956 5.38523 146.699 5.70468C147.441 6.02412 148.074 6.46579 148.597 7.02968C149.117 7.59357 149.525 8.27135 149.82 9.05746C150.114 9.84635 150.256 10.688 150.245 11.5852C150.256 12.488 150.114 13.338 149.82 14.1297C149.525 14.9241 149.117 15.5991 148.597 16.163C148.077 16.7241 147.443 17.1658 146.699 17.4852C145.954 17.8047 145.156 17.9602 144.303 17.9491C143.449 17.9602 142.652 17.8047 141.91 17.4852C141.168 17.1658 140.537 16.7241 140.017 16.1602C139.497 15.5963 139.089 14.9186 138.797 14.1325C138.505 13.3463 138.363 12.5019 138.374 11.6047C138.363 10.7075 138.505 9.86301 138.797 9.07412C139.089 8.28523 139.494 7.60746 140.017 7.04079C140.537 6.4769 141.168 6.03246 141.91 5.71023C142.652 5.38801 143.449 5.23246 144.303 5.24357V5.24079ZM141.44 14.8602C142.165 15.6825 143.124 16.0963 144.319 16.0963C145.515 16.0963 146.473 15.6852 147.196 14.8602C147.919 14.038 148.28 12.9463 148.28 11.5852C148.28 10.2241 147.919 9.12412 147.196 8.3019C146.473 7.47968 145.515 7.06579 144.319 7.06579C143.124 7.06579 142.163 7.47968 141.44 8.30468C140.715 9.12968 140.353 10.2241 140.353 11.5852C140.353 12.9463 140.715 14.038 141.44 14.8602Z" fill="#F7F6F2"/>
|
||||
<path d="M154.097 5.43801V13.3019C154.103 14.238 154.378 14.9463 154.923 15.4241C155.467 15.9047 156.184 16.1436 157.071 16.1436C157.958 16.1436 158.636 15.8908 159.203 15.388C159.77 14.8852 160.053 14.188 160.053 13.3019V5.43801H161.929V13.3769C161.929 14.0991 161.799 14.7519 161.54 15.338C161.282 15.9241 160.929 16.4075 160.487 16.7825C160.042 17.1602 159.531 17.4491 158.944 17.6547C158.358 17.8602 157.735 17.9602 157.068 17.9602C156.401 17.9602 155.804 17.8602 155.226 17.663C154.647 17.4658 154.131 17.1797 153.68 16.8075C153.227 16.4352 152.871 15.9547 152.61 15.363C152.349 14.7713 152.218 14.1075 152.218 13.3769V5.43801H154.097Z" fill="#F7F6F2"/>
|
||||
<path d="M174.473 5.43801V17.738H172.597L166.529 8.46857V17.738H164.653V5.43801H166.529L172.597 14.7241V5.43801H174.473Z" fill="#F7F6F2"/>
|
||||
<path d="M187.583 11.6019C187.588 12.4825 187.436 13.3102 187.124 14.0797C186.813 14.8519 186.382 15.5075 185.835 16.0463C185.287 16.5852 184.628 17.0075 183.859 17.3102C183.089 17.613 182.269 17.7575 181.391 17.7408H177.291V5.44079H181.391C182.547 5.42412 183.603 5.67968 184.553 6.21023C185.504 6.73801 186.249 7.4769 186.788 8.42412C187.327 9.37135 187.591 10.4325 187.583 11.6047V11.6019ZM185.59 11.6019C185.59 10.3019 185.204 9.24635 184.428 8.43523C183.653 7.62412 182.636 7.21579 181.374 7.21579H179.184V15.9963H181.374C182.647 15.9963 183.667 15.5936 184.437 14.7852C185.207 13.9797 185.59 12.9158 185.59 11.6019Z" fill="#F7F6F2"/>
|
||||
<path d="M195.821 14.7825H190.91L189.843 17.7408H187.916L192.363 5.44079H194.381L198.853 17.7408H196.869L195.818 14.7825H195.821ZM195.276 13.188L193.383 7.8269L191.474 13.188H195.276Z" fill="#F7F6F2"/>
|
||||
<path d="M207.278 7.21579H203.706V17.7408H201.813V7.21579H198.242V5.44079H207.275V7.21579H207.278Z" fill="#F7F6F2"/>
|
||||
<path d="M208.973 17.738V5.43801H210.866V17.738H208.973Z" fill="#F7F6F2"/>
|
||||
<path d="M218.873 5.24079C219.726 5.22968 220.527 5.38523 221.269 5.70468C222.014 6.02412 222.645 6.46579 223.167 7.02968C223.687 7.59357 224.095 8.27135 224.39 9.05746C224.685 9.84635 224.826 10.688 224.815 11.5852C224.826 12.488 224.685 13.338 224.39 14.1297C224.095 14.9241 223.687 15.5991 223.167 16.163C222.647 16.7241 222.014 17.1658 221.269 17.4852C220.524 17.8047 219.726 17.9602 218.873 17.9491C218.02 17.9602 217.222 17.8047 216.48 17.4852C215.738 17.1658 215.107 16.7241 214.587 16.1602C214.067 15.5963 213.659 14.9186 213.367 14.1325C213.075 13.3463 212.933 12.5019 212.945 11.6047C212.933 10.7075 213.075 9.86301 213.367 9.07412C213.659 8.28523 214.065 7.60746 214.587 7.04079C215.107 6.4769 215.738 6.03246 216.48 5.71023C217.222 5.38801 218.02 5.23246 218.873 5.24357V5.24079ZM216.01 14.8602C216.736 15.6825 217.695 16.0963 218.89 16.0963C220.085 16.0963 221.044 15.6852 221.766 14.8602C222.489 14.038 222.85 12.9463 222.85 11.5852C222.85 10.2241 222.489 9.12412 221.766 8.3019C221.044 7.47968 220.085 7.06579 218.89 7.06579C217.695 7.06579 216.733 7.47968 216.01 8.30468C215.285 9.12968 214.924 10.2241 214.924 11.5852C214.924 12.9463 215.285 14.038 216.01 14.8602Z" fill="#F7F6F2"/>
|
||||
<path d="M236.728 5.43801V17.738H234.852L228.784 8.46857V17.738H226.908V5.43801H228.784L234.852 14.7241V5.43801H236.728Z" fill="#F7F6F2"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.7 KiB |
@@ -0,0 +1,22 @@
|
||||
<svg width="237" height="24" viewBox="0 0 237 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8.54181 0.297615C8.14709 -0.0992051 7.5012 -0.0992051 7.1082 0.297615L0.717655 6.72232C0.322945 7.11914 0 7.90248 0 8.46249V14.2894C0 14.8494 0.456224 15.3098 1.01497 15.3098H14.635C15.1921 15.3098 15.65 14.8511 15.65 14.2894V8.46249C15.65 7.90248 15.3271 7.11914 14.9324 6.72232L8.54181 0.297615Z" fill="#09202E"/>
|
||||
<path d="M14.8672 17.9182C15.2993 17.9182 15.6502 18.2684 15.6504 18.7004V22.4172C15.6504 22.8494 15.2994 23.2004 14.8672 23.2004H13.8896C13.4575 23.2004 13.1064 22.8494 13.1064 22.4172V20.4612H2.54297V22.4172C2.54297 22.8494 2.19285 23.2004 1.76074 23.2004H0.782227C0.350189 23.2003 0 22.8493 0 22.4172V18.7004C0.000147852 18.2685 0.350281 17.9184 0.782227 17.9182H14.8672Z" fill="#09202E"/>
|
||||
<path d="M28.0439 5.23999C28.9236 5.23999 29.7386 5.39833 30.4891 5.71709C31.2396 6.03377 31.8754 6.47337 32.3965 7.03381C32.9177 7.59425 33.3242 8.26511 33.616 9.05056C33.9058 9.83601 34.0517 10.684 34.0517 11.5965C34.0621 12.4986 33.9204 13.3445 33.6285 14.1383C33.3346 14.932 32.9239 15.6092 32.3965 16.1717C31.8691 16.7342 31.227 17.1759 30.4724 17.4947C29.7178 17.8155 28.9027 17.9697 28.0272 17.9593C26.8702 17.9759 25.83 17.7092 24.9086 17.1613C23.9872 16.6134 23.2764 15.8529 22.7761 14.88C22.2757 13.907 22.0339 12.8174 22.0506 11.6132C22.0402 10.711 22.1819 9.86518 22.4738 9.0714C22.7677 8.27761 23.1763 7.6005 23.7016 7.03381C24.2269 6.46921 24.8648 6.02544 25.6174 5.70668C26.3699 5.38791 27.1787 5.23166 28.0439 5.24207V5.23999ZM28.0584 15.5237C29.0966 15.5237 29.9179 15.1716 30.5245 14.4695C31.1312 13.7653 31.4334 12.809 31.4334 11.5965C31.4334 10.3839 31.1312 9.41308 30.5287 8.71096C29.9263 8.01094 29.1028 7.66092 28.0584 7.66092C27.0141 7.66092 26.1906 8.01094 25.5882 8.71096C24.9857 9.41099 24.6835 10.3735 24.6835 11.5965C24.6835 12.8195 24.9857 13.7799 25.5882 14.4779C26.1906 15.1758 27.0141 15.5258 28.0584 15.5258V15.5237Z" fill="#09202E"/>
|
||||
<path d="M44.9854 9.52558C44.9854 10.759 44.6123 11.7507 43.8681 12.5028C43.1239 13.2549 42.1108 13.632 40.8267 13.632H38.3898V17.7551H35.9028V5.45875H40.86C42.1483 5.45875 43.1572 5.82126 43.8889 6.54629C44.6206 7.27132 44.9854 8.26511 44.9854 9.5235V9.52558ZM42.3588 9.47766C42.3588 8.95681 42.19 8.52554 41.8502 8.18594C41.5104 7.84635 41.0205 7.67759 40.3785 7.67759H38.3898V11.4673H40.3785C41.0247 11.4673 41.5167 11.284 41.8544 10.9173C42.1921 10.5506 42.3588 10.0714 42.3588 9.47975V9.47766Z" fill="#09202E"/>
|
||||
<path d="M54.4829 17.7551H46.7386V5.45875H54.4829V7.82134H49.2234V10.4444H53.895V12.6445H49.2234V15.4154H54.4829V17.7551Z" fill="#09202E"/>
|
||||
<path d="M67.397 5.46083V17.7572H64.9268L59.5381 9.42974V17.7572H57.0678V5.46083H59.5381L64.9268 13.8049V5.46083H67.397Z" fill="#09202E"/>
|
||||
<path d="M74.4409 5.46083H76.9279V10.4319L81.8037 10.4485V5.46083H84.3074V17.7572H81.8037V12.6653L76.9279 12.632V17.7572H74.4409V5.46083Z" fill="#09202E"/>
|
||||
<path d="M92.133 5.23999C93.0127 5.23999 93.8278 5.39833 94.5782 5.71709C95.3287 6.03377 95.9645 6.47337 96.4856 7.03381C97.0068 7.59425 97.4133 8.26511 97.7051 9.05056C97.9949 9.83601 98.1408 10.684 98.1408 11.5965C98.1512 12.4986 98.0095 13.3445 97.7176 14.1383C97.4237 14.932 97.013 15.6092 96.4856 16.1717C95.9582 16.7342 95.3162 17.1759 94.5615 17.4947C93.8069 17.8155 92.9918 17.9697 92.1163 17.9593C90.9593 17.9759 89.9191 17.7092 88.9977 17.1613C88.0763 16.6134 87.3655 15.8529 86.8652 14.88C86.3649 13.907 86.1231 12.8174 86.1397 11.6132C86.1293 10.711 86.2711 9.86518 86.5629 9.0714C86.8568 8.27761 87.2654 7.6005 87.7907 7.03381C88.3161 6.46921 88.954 6.02544 89.7065 5.70668C90.459 5.38791 91.2679 5.23166 92.133 5.24207V5.23999ZM92.1476 15.5237C93.1857 15.5237 94.007 15.1716 94.6137 14.4695C95.2203 13.7653 95.5225 12.809 95.5225 11.5965C95.5225 10.3839 95.2203 9.41308 94.6178 8.71096C94.0154 8.01094 93.192 7.66092 92.1476 7.66092C91.1032 7.66092 90.2798 8.01094 89.6773 8.71096C89.0749 9.41099 88.7726 10.3735 88.7726 11.5965C88.7726 12.8195 89.0749 13.7799 89.6773 14.4779C90.2798 15.1758 91.1032 15.5258 92.1476 15.5258V15.5237Z" fill="#09202E"/>
|
||||
<path d="M112.408 5.46083V17.7572H109.954V11.034L107.321 17.7572H104.966L102.364 11.084V17.7572H99.9919V5.46083H102.364L106.148 14.855L109.954 5.46083H112.408Z" fill="#09202E"/>
|
||||
<path d="M122.762 17.7551H115.018V5.45875H122.762V7.82134H117.503V10.4444H122.174V12.6445H117.503V15.4154H122.762V17.7551Z" fill="#09202E"/>
|
||||
<path d="M131.526 7.21555V10.9072H136.254V12.5933H131.526V17.7405H129.65V5.44054H137.146V7.21555H131.526Z" fill="#09202E"/>
|
||||
<path d="M144.303 5.24055C145.156 5.22943 145.956 5.38499 146.699 5.70443C147.441 6.02388 148.074 6.46555 148.597 7.02943C149.117 7.59332 149.525 8.2711 149.82 9.05721C150.114 9.8461 150.256 10.6878 150.245 11.585C150.256 12.4878 150.114 13.3378 149.82 14.1294C149.525 14.9239 149.117 15.5989 148.597 16.1628C148.077 16.7239 147.443 17.1655 146.699 17.485C145.954 17.8044 145.156 17.96 144.303 17.9489C143.449 17.96 142.652 17.8044 141.91 17.485C141.168 17.1655 140.537 16.7239 140.017 16.16C139.497 15.5961 139.089 14.9183 138.797 14.1322C138.505 13.3461 138.363 12.5017 138.374 11.6044C138.363 10.7072 138.505 9.86277 138.797 9.07388C139.089 8.28499 139.494 7.60721 140.017 7.04055C140.537 6.47666 141.168 6.03221 141.91 5.70999C142.652 5.38777 143.449 5.23221 144.303 5.24332V5.24055ZM141.44 14.86C142.165 15.6822 143.124 16.0961 144.319 16.0961C145.515 16.0961 146.473 15.685 147.196 14.86C147.919 14.0378 148.28 12.9461 148.28 11.585C148.28 10.2239 147.919 9.12388 147.196 8.30166C146.473 7.47943 145.515 7.06555 144.319 7.06555C143.124 7.06555 142.163 7.47943 141.44 8.30443C140.715 9.12943 140.353 10.2239 140.353 11.585C140.353 12.9461 140.715 14.0378 141.44 14.86Z" fill="#09202E"/>
|
||||
<path d="M154.097 5.43777V13.3017C154.103 14.2378 154.378 14.9461 154.923 15.4239C155.467 15.9044 156.184 16.1433 157.071 16.1433C157.958 16.1433 158.636 15.8905 159.203 15.3878C159.77 14.885 160.053 14.1878 160.053 13.3017V5.43777H161.929V13.3767C161.929 14.0989 161.799 14.7517 161.54 15.3378C161.282 15.9239 160.929 16.4072 160.487 16.7822C160.042 17.16 159.531 17.4489 158.944 17.6544C158.358 17.86 157.735 17.96 157.068 17.96C156.401 17.96 155.804 17.86 155.226 17.6628C154.647 17.4655 154.131 17.1794 153.68 16.8072C153.227 16.435 152.871 15.9544 152.61 15.3628C152.349 14.7711 152.218 14.1072 152.218 13.3767V5.43777H154.097Z" fill="#09202E"/>
|
||||
<path d="M174.473 5.43777V17.7378H172.597L166.529 8.46832V17.7378H164.653V5.43777H166.529L172.597 14.7239V5.43777H174.473Z" fill="#09202E"/>
|
||||
<path d="M187.583 11.6017C187.588 12.4822 187.436 13.31 187.124 14.0794C186.813 14.8517 186.382 15.5072 185.835 16.0461C185.287 16.585 184.628 17.0072 183.859 17.31C183.089 17.6128 182.269 17.7572 181.391 17.7405H177.291V5.44054H181.391C182.547 5.42388 183.603 5.67943 184.553 6.20999C185.504 6.73777 186.249 7.47666 186.788 8.42388C187.327 9.3711 187.591 10.4322 187.583 11.6044V11.6017ZM185.59 11.6017C185.59 10.3017 185.204 9.2461 184.428 8.43499C183.653 7.62388 182.636 7.21555 181.374 7.21555H179.184V15.9961H181.374C182.647 15.9961 183.667 15.5933 184.437 14.785C185.207 13.9794 185.59 12.9155 185.59 11.6017Z" fill="#09202E"/>
|
||||
<path d="M195.821 14.7822H190.91L189.843 17.7405H187.916L192.363 5.44054H194.381L198.853 17.7405H196.869L195.818 14.7822H195.821ZM195.276 13.1878L193.383 7.82666L191.474 13.1878H195.276Z" fill="#09202E"/>
|
||||
<path d="M207.278 7.21555H203.706V17.7405H201.813V7.21555H198.242V5.44054H207.275V7.21555H207.278Z" fill="#09202E"/>
|
||||
<path d="M208.973 17.7378V5.43777H210.866V17.7378H208.973Z" fill="#09202E"/>
|
||||
<path d="M218.873 5.24055C219.726 5.22943 220.527 5.38499 221.269 5.70443C222.014 6.02388 222.645 6.46555 223.167 7.02943C223.687 7.59332 224.095 8.2711 224.39 9.05721C224.685 9.8461 224.826 10.6878 224.815 11.585C224.826 12.4878 224.685 13.3378 224.39 14.1294C224.095 14.9239 223.687 15.5989 223.167 16.1628C222.647 16.7239 222.014 17.1655 221.269 17.485C220.524 17.8044 219.726 17.96 218.873 17.9489C218.02 17.96 217.222 17.8044 216.48 17.485C215.738 17.1655 215.107 16.7239 214.587 16.16C214.067 15.5961 213.659 14.9183 213.367 14.1322C213.075 13.3461 212.933 12.5017 212.945 11.6044C212.933 10.7072 213.075 9.86277 213.367 9.07388C213.659 8.28499 214.065 7.60721 214.587 7.04055C215.107 6.47666 215.738 6.03221 216.48 5.70999C217.222 5.38777 218.02 5.23221 218.873 5.24332V5.24055ZM216.01 14.86C216.736 15.6822 217.695 16.0961 218.89 16.0961C220.085 16.0961 221.044 15.685 221.766 14.86C222.489 14.0378 222.85 12.9461 222.85 11.585C222.85 10.2239 222.489 9.12388 221.766 8.30166C221.044 7.47943 220.085 7.06555 218.89 7.06555C217.695 7.06555 216.733 7.47943 216.01 8.30443C215.285 9.12943 214.924 10.2239 214.924 11.585C214.924 12.9461 215.285 14.0378 216.01 14.86Z" fill="#09202E"/>
|
||||
<path d="M236.728 5.43777V17.7378H234.852L228.784 8.46832V17.7378H226.908V5.43777H228.784L234.852 14.7239V5.43777H236.728Z" fill="#09202E"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 8.7 KiB |
@@ -0,0 +1,120 @@
|
||||
import type {
|
||||
ReactiveController,
|
||||
ReactiveControllerHost,
|
||||
} from "@lit/reactive-element/reactive-controller";
|
||||
import type { LitElement } from "lit";
|
||||
import type { Ref } from "lit/directives/ref";
|
||||
|
||||
const scrollParent = (element: Element): HTMLElement | undefined => {
|
||||
let node = element.parentElement;
|
||||
while (node) {
|
||||
const { overflowY } = getComputedStyle(node);
|
||||
if (overflowY === "auto" || overflowY === "scroll") {
|
||||
return node;
|
||||
}
|
||||
node = node.parentElement;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Does what CSS scroll anchoring does in Chrome and Firefox but not in Safari.
|
||||
* Point the ref at the element that grows, not at the scroller. Turns native
|
||||
* anchoring off on that scroller, so growth elsewhere in it is no longer
|
||||
* compensated either.
|
||||
*/
|
||||
export class PreserveScrollPositionController implements ReactiveController {
|
||||
private _target: Ref<HTMLElement>;
|
||||
|
||||
private _element?: HTMLElement;
|
||||
|
||||
private _scroller?: HTMLElement;
|
||||
|
||||
private _observer?: ResizeObserver;
|
||||
|
||||
private _height = 0;
|
||||
|
||||
constructor(
|
||||
host: ReactiveControllerHost & LitElement,
|
||||
target: Ref<HTMLElement>
|
||||
) {
|
||||
this._target = target;
|
||||
host.addController(this);
|
||||
}
|
||||
|
||||
hostConnected() {
|
||||
this._sync();
|
||||
}
|
||||
|
||||
hostUpdated() {
|
||||
this._sync();
|
||||
}
|
||||
|
||||
hostDisconnected() {
|
||||
this._detach();
|
||||
}
|
||||
|
||||
private _sync() {
|
||||
const element = this._target.value;
|
||||
|
||||
if (element === this._element) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._detach();
|
||||
this._element = element;
|
||||
|
||||
if (element) {
|
||||
this._height = element.getBoundingClientRect().height;
|
||||
this._observer = new ResizeObserver((entries) =>
|
||||
this._compensate(entries)
|
||||
);
|
||||
this._observer.observe(element);
|
||||
}
|
||||
}
|
||||
|
||||
private _detach() {
|
||||
this._observer?.disconnect();
|
||||
this._observer = undefined;
|
||||
this._element = undefined;
|
||||
if (this._scroller) {
|
||||
this._scroller.style.removeProperty("overflow-anchor");
|
||||
this._scroller = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
private _resolveScroller(): HTMLElement | undefined {
|
||||
if (!this._scroller && this._element) {
|
||||
this._scroller = scrollParent(this._element);
|
||||
if (this._scroller) {
|
||||
// Chrome and Firefox would otherwise anchor on top of this controller
|
||||
// and correct twice.
|
||||
this._scroller.style.overflowAnchor = "none";
|
||||
}
|
||||
}
|
||||
return this._scroller;
|
||||
}
|
||||
|
||||
private _compensate(entries: ResizeObserverEntry[]) {
|
||||
const element = this._element;
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
|
||||
const height =
|
||||
entries[0]?.borderBoxSize?.[0]?.blockSize ?? element.offsetHeight;
|
||||
const delta = height - this._height;
|
||||
this._height = height;
|
||||
if (!delta) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scroller = this._resolveScroller();
|
||||
if (
|
||||
scroller &&
|
||||
element.getBoundingClientRect().top < scroller.getBoundingClientRect().top
|
||||
) {
|
||||
scroller.scrollTop += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
-10
@@ -1,6 +1,7 @@
|
||||
import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, LitElement, svg } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { styleMap } from "lit/directives/style-map";
|
||||
import { formatNumber } from "../common/number/format_number";
|
||||
import { blankBeforePercent } from "../common/translations/blank_before_percent";
|
||||
@@ -46,15 +47,32 @@ export class HaGauge extends LitElement {
|
||||
|
||||
@state() private _segment_label?: string = "";
|
||||
|
||||
@query(".text") private _textSvg?: SVGSVGElement;
|
||||
|
||||
@query(".value-text") private _valueText?: SVGTextElement;
|
||||
|
||||
private _sortedLevels?: LevelDefinition[];
|
||||
|
||||
private _rescaleOnConnect = false;
|
||||
// Set when the value text could not be measured because we have no layout box
|
||||
// yet, either disconnected or inside a hidden container.
|
||||
private _rescalePending = false;
|
||||
|
||||
// Measure again once we get a layout box, e.g. when a section hidden by a
|
||||
// visibility condition is revealed. Nothing else re-renders the gauge then.
|
||||
// @ts-ignore side-effect-only controller, its value is never read
|
||||
private _resizeController = new ResizeController(this, {
|
||||
skipInitial: true,
|
||||
callback: (entries) => {
|
||||
if (this._rescalePending && entries[0]?.contentRect.width) {
|
||||
this._rescaleSvg();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
public connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
if (this._rescaleOnConnect) {
|
||||
if (this._rescalePending && this.hasUpdated) {
|
||||
this._rescaleSvg();
|
||||
this._rescaleOnConnect = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,15 +239,22 @@ export class HaGauge extends LitElement {
|
||||
// fit the text
|
||||
// That way it will auto-scale correctly
|
||||
|
||||
if (!this.isConnected) {
|
||||
// Retry this later if we're disconnected, otherwise we get a 0 bbox and missing label
|
||||
this._rescaleOnConnect = true;
|
||||
if (!this._textSvg || !this._valueText || !this.isConnected) {
|
||||
this._rescalePending = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const svgRoot = this.shadowRoot!.querySelector(".text")!;
|
||||
const box = svgRoot.querySelector("text")!.getBBox()!;
|
||||
svgRoot.setAttribute(
|
||||
const box = this._valueText.getBBox();
|
||||
|
||||
// An empty box means we have no layout, so keep the last known good viewBox
|
||||
// and retry later. A viewBox with a 0 width or height would hide the label.
|
||||
if (!box.width || !box.height) {
|
||||
this._rescalePending = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this._rescalePending = false;
|
||||
this._textSvg.setAttribute(
|
||||
"viewBox",
|
||||
`${box.x} ${box.y} ${box.width} ${box.height}`
|
||||
);
|
||||
@@ -248,6 +273,8 @@ export class HaGauge extends LitElement {
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
/* a non replaced inline element never reports a size to a resize observer */
|
||||
display: block;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface CoreFrontendUserData {
|
||||
showEntityIdPicker?: boolean;
|
||||
default_panel?: string;
|
||||
apps_info_dismissed?: boolean;
|
||||
dashboard_favorite_card_types?: string[];
|
||||
}
|
||||
|
||||
export interface SidebarFrontendUserData {
|
||||
|
||||
@@ -95,7 +95,7 @@ export interface HassioAddonDetails extends HassioAddonInfo {
|
||||
options: Record<string, unknown>;
|
||||
privileged: any;
|
||||
protected: boolean;
|
||||
rating: "1-8";
|
||||
rating: number;
|
||||
schema: HaFormSchema[] | null;
|
||||
services_role: string[];
|
||||
signed: boolean;
|
||||
|
||||
@@ -26,6 +26,7 @@ export interface StoreAddonDetails extends StoreAddon {
|
||||
apparmor: boolean;
|
||||
arch: SupervisorArch[];
|
||||
auth_api: boolean;
|
||||
changelog: boolean;
|
||||
detached: boolean;
|
||||
docker_api: boolean;
|
||||
documentation: boolean;
|
||||
|
||||
@@ -481,6 +481,17 @@ export const provideHass = (
|
||||
? response[1](hass(), method, path, parameters)
|
||||
: Promise.reject(`API Mock for ${path} is not implemented`);
|
||||
},
|
||||
// Mocks return a plain body; wrap it so callers can stream it like a fetch
|
||||
// Response. Callbacks may return a Response themselves to set headers.
|
||||
async callApiRaw(method, path, parameters, headers) {
|
||||
const result = await hassObj.callApi<any>(
|
||||
method,
|
||||
path,
|
||||
parameters,
|
||||
headers
|
||||
);
|
||||
return result instanceof Response ? result : new Response(result);
|
||||
},
|
||||
hassUrl: (path?) => path,
|
||||
fetchWithAuth: () => Promise.reject("Not implemented"),
|
||||
sendWS: (msg) => hassObj.connection.sendMessage(msg),
|
||||
|
||||
@@ -18,8 +18,16 @@
|
||||
<meta name="referrer" content="same-origin" />
|
||||
<meta name="theme-color" content="{{ theme_color }}" />
|
||||
<meta name="color-scheme" content="dark light" />
|
||||
<link rel="preload" href="/static/fonts/roboto/Roboto-Regular.woff2" as="font" type="font/woff2" crossorigin>
|
||||
<%= renderTemplate("_style_base.html.template") %>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: "Roboto Launch Screen";
|
||||
font-display: block;
|
||||
src: url("/static/fonts/roboto/Roboto-Regular.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
@keyframes fade-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
@@ -29,11 +37,11 @@
|
||||
}
|
||||
}
|
||||
::view-transition-group(launch-screen) {
|
||||
animation-duration: var(--ha-animation-duration-slow, 350ms);
|
||||
animation-duration: var(--ha-animation-duration-normal, 250ms);
|
||||
animation-timing-function: ease-out;
|
||||
}
|
||||
::view-transition-old(launch-screen) {
|
||||
animation: fade-out var(--ha-animation-duration-slow, 350ms) ease-out;
|
||||
animation: fade-out var(--ha-animation-duration-normal, 250ms) ease-out;
|
||||
}
|
||||
html {
|
||||
background-color: var(--primary-background-color, #fafafa);
|
||||
@@ -41,6 +49,7 @@
|
||||
height: 100vh;
|
||||
}
|
||||
#ha-launch-screen {
|
||||
font-family: "Roboto Launch Screen", sans-serif;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
@@ -55,13 +64,32 @@
|
||||
view-transition-name: launch-screen;
|
||||
background-color: var(--primary-background-color, #fafafa);
|
||||
z-index: 100;
|
||||
transition: opacity var(--ha-animation-duration-normal, 250ms) ease-out;
|
||||
}
|
||||
#ha-launch-screen.removing {
|
||||
opacity: 0;
|
||||
}
|
||||
#ha-launch-screen svg {
|
||||
width: 112px;
|
||||
@keyframes launch-lockup-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
#ha-launch-screen .ha-lockup {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
animation: launch-lockup-in var(--ha-animation-duration-normal, 250ms) ease-out both;
|
||||
}
|
||||
#ha-launch-screen-info-box > *,
|
||||
#ha-launch-screen .ohf-logo {
|
||||
animation: launch-lockup-in var(--ha-animation-duration-normal, 250ms) ease-out both;
|
||||
}
|
||||
#ha-launch-screen .ha-logo {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
}
|
||||
#ha-launch-screen .ha-launch-screen-spacer-top {
|
||||
flex: 1;
|
||||
@@ -77,8 +105,22 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
opacity: .66;
|
||||
}
|
||||
.ohf-logo span {
|
||||
font-size: 12px;
|
||||
line-height: 12px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.ohf-logo picture {
|
||||
display: flex;
|
||||
}
|
||||
.ohf-logo img {
|
||||
width: 237px;
|
||||
aspect-ratio: 237 / 24;
|
||||
height: auto;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html {
|
||||
background-color: var(--primary-background-color, #111111);
|
||||
@@ -88,8 +130,18 @@
|
||||
body #ha-launch-screen {
|
||||
background-color: var(--primary-background-color, #111111);
|
||||
}
|
||||
}
|
||||
@media (max-height: 560px) {
|
||||
/* body selector to avoid minification causing bad jinja2 */
|
||||
body #ha-launch-screen .ha-launch-screen-spacer-top {
|
||||
margin-top: 24px;
|
||||
padding-top: 24px;
|
||||
}
|
||||
body #ha-launch-screen .ha-launch-screen-spacer-bottom {
|
||||
padding-top: 16px;
|
||||
}
|
||||
.ohf-logo {
|
||||
filter: invert(1);
|
||||
margin-block: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -97,13 +149,16 @@
|
||||
<body>
|
||||
<div id="ha-launch-screen">
|
||||
<div class="ha-launch-screen-spacer-top"></div>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240">
|
||||
<path fill="#18BCF2" d="M240 224.762a15 15 0 0 1-15 15H15a15 15 0 0 1-15-15v-90c0-8.25 4.77-19.769 10.61-25.609l98.78-98.7805c5.83-5.83 15.38-5.83 21.21 0l98.79 98.7895c5.83 5.83 10.61 17.36 10.61 25.61v90-.01Z"/>
|
||||
<path fill="#F2F4F9" d="m107.27 239.762-40.63-40.63c-2.09.72-4.32 1.13-6.64 1.13-11.3 0-20.5-9.2-20.5-20.5s9.2-20.5 20.5-20.5 20.5 9.2 20.5 20.5c0 2.33-.41 4.56-1.13 6.65l31.63 31.63v-115.88c-6.8-3.3395-11.5-10.3195-11.5-18.3895 0-11.3 9.2-20.5 20.5-20.5s20.5 9.2 20.5 20.5c0 8.07-4.7 15.05-11.5 18.3895v81.27l31.46-31.46c-.62-1.96-.96-4.04-.96-6.2 0-11.3 9.2-20.5 20.5-20.5s20.5 9.2 20.5 20.5-9.2 20.5-20.5 20.5c-2.5 0-4.88-.47-7.09-1.29L129 208.892v30.88z"/>
|
||||
</svg>
|
||||
<div class="ha-lockup">
|
||||
<img class="ha-logo" src="/static/images/home-assistant-logo-loading.svg" alt="Home Assistant">
|
||||
</div>
|
||||
<div id="ha-launch-screen-info-box" class="ha-launch-screen-spacer-bottom"></div>
|
||||
<div class="ohf-logo">
|
||||
<img src="/static/images/ohf-badge.svg" alt="Home Assistant is a project by the Open Home Foundation" height="46">
|
||||
<span id="ha-launch-screen-attribution">A project from the</span>
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="/static/images/open-home-foundation-on-dark.svg">
|
||||
<img src="/static/images/open-home-foundation-on-light.svg" alt="Open Home Foundation" width="237" height="24">
|
||||
</picture>
|
||||
</div>
|
||||
</div>
|
||||
<home-assistant></home-assistant>
|
||||
|
||||
+59
-61
@@ -1,91 +1,91 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import "../components/ha-spinner";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import "../components/ha-button";
|
||||
|
||||
@customElement("ha-init-page")
|
||||
class HaInitPage extends LitElement {
|
||||
export class HaInitPage extends LitElement {
|
||||
@property({ type: Boolean }) public error = false;
|
||||
|
||||
@property({ type: Boolean }) public migration = false;
|
||||
|
||||
@state() private _retryInSeconds = 60;
|
||||
@property({ attribute: false }) public localize?: LocalizeFunc;
|
||||
|
||||
private _showProgressIndicatorTimeout?: number;
|
||||
@state() private _retryInSeconds = 60;
|
||||
|
||||
private _retryInterval?: number;
|
||||
|
||||
protected render() {
|
||||
return this.error
|
||||
? html`
|
||||
<p>Unable to connect to Home Assistant.</p>
|
||||
<p>
|
||||
${
|
||||
this.localize?.("ui.init.error.title") ||
|
||||
"Unable to connect to Home Assistant."
|
||||
}
|
||||
</p>
|
||||
<p class="retry-text">
|
||||
Retrying in ${this._retryInSeconds} seconds...
|
||||
${
|
||||
this.localize?.("ui.init.error.retrying", {
|
||||
seconds: this._retryInSeconds,
|
||||
}) || `Retrying in ${this._retryInSeconds} seconds...`
|
||||
}
|
||||
</p>
|
||||
<ha-button size="s" appearance="plain" @click=${this._retry}
|
||||
>Retry now</ha-button
|
||||
>${
|
||||
this.localize?.("ui.init.error.retry_now") || "Retry now"
|
||||
}</ha-button
|
||||
>
|
||||
${
|
||||
location.host.includes("ui.nabu.casa")
|
||||
? html`
|
||||
<p>
|
||||
It is possible that you are seeing this screen because your
|
||||
Home Assistant is not currently connected. You can ask it to
|
||||
come online from your
|
||||
<a href="https://account.nabucasa.com/"
|
||||
>Nabu Casa account page</a
|
||||
>.
|
||||
</p>
|
||||
`
|
||||
: ""
|
||||
? html`<p>
|
||||
${
|
||||
this.localize?.("ui.init.error.nabu_casa", {
|
||||
account_link: html`<a href="https://account.nabucasa.com/"
|
||||
>${
|
||||
this.localize?.("ui.init.error.nabu_casa_account") ||
|
||||
"Nabu Casa account page"
|
||||
}</a
|
||||
>`,
|
||||
}) ||
|
||||
html`It is possible that you are seeing this screen because
|
||||
your Home Assistant is not currently connected. You can
|
||||
ask it to come online from your
|
||||
<a href="https://account.nabucasa.com/"
|
||||
>Nabu Casa account page</a
|
||||
>.`
|
||||
}
|
||||
</p>`
|
||||
: nothing
|
||||
}
|
||||
`
|
||||
: html`
|
||||
<div id="progress-indicator-wrapper">
|
||||
<ha-spinner></ha-spinner>
|
||||
</div>
|
||||
<div id="loading-text">
|
||||
${
|
||||
this.migration
|
||||
? html`
|
||||
Database upgrade is in progress, Home Assistant will not
|
||||
start until the upgrade is completed.
|
||||
<br /><br />
|
||||
The upgrade may need a long time to complete, please be
|
||||
patient.
|
||||
`
|
||||
: "Loading data"
|
||||
}
|
||||
</div>
|
||||
`;
|
||||
: html`<p>
|
||||
${
|
||||
this.migration
|
||||
? html`<span class="migration-text"
|
||||
>${
|
||||
this.localize?.("ui.init.migration") ||
|
||||
"Database upgrade is in progress, Home Assistant will not start until the upgrade is completed.\n\nThe upgrade may need a long time to complete, please be patient."
|
||||
}</span
|
||||
>`
|
||||
: this.localize?.("ui.init.loading") || "Loading data"
|
||||
}
|
||||
</p>`;
|
||||
}
|
||||
|
||||
disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
if (this._showProgressIndicatorTimeout) {
|
||||
clearTimeout(this._showProgressIndicatorTimeout);
|
||||
}
|
||||
if (this._retryInterval) {
|
||||
clearInterval(this._retryInterval);
|
||||
}
|
||||
}
|
||||
|
||||
protected willUpdate(changedProperties: PropertyValues<this>) {
|
||||
if (changedProperties.has("error") && this.error) {
|
||||
import("../components/ha-button");
|
||||
}
|
||||
}
|
||||
|
||||
protected firstUpdated() {
|
||||
this._showProgressIndicatorTimeout = window.setTimeout(() => {
|
||||
import("../components/ha-spinner");
|
||||
}, 5000);
|
||||
|
||||
this._retryInterval = window.setInterval(() => {
|
||||
const remainingSeconds = this._retryInSeconds--;
|
||||
if (remainingSeconds <= 0) {
|
||||
if (this._retryInSeconds <= 1) {
|
||||
this._retry();
|
||||
} else {
|
||||
this._retryInSeconds -= 1;
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
@@ -104,24 +104,22 @@ class HaInitPage extends LitElement {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
#progress-indicator-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 25px 0;
|
||||
height: 50px;
|
||||
}
|
||||
a {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
.retry-text {
|
||||
margin-top: 0;
|
||||
}
|
||||
p,
|
||||
#loading-text {
|
||||
p {
|
||||
max-width: 350px;
|
||||
margin: var(--ha-space-3, 12px) var(--ha-space-4, 16px);
|
||||
color: var(--primary-text-color);
|
||||
font-size: var(--ha-font-size-m, 14px);
|
||||
text-align: center;
|
||||
}
|
||||
.migration-text {
|
||||
white-space: pre-line;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { customElement, state } from "lit/decorators";
|
||||
import { storage } from "../common/decorators/storage";
|
||||
import { isNavigationClick } from "../common/dom/is-navigation-click";
|
||||
import { navigate } from "../common/navigate";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import { fetchHttpConfig } from "../data/http";
|
||||
import type { HttpConfigState } from "../data/http";
|
||||
import type { WindowWithPreloads } from "../data/preloads";
|
||||
@@ -18,7 +19,7 @@ import type { HomeAssistant, Route } from "../types";
|
||||
import { storeState } from "../util/ha-pref-storage";
|
||||
import {
|
||||
removeLaunchScreen,
|
||||
renderLaunchScreenInfoBox,
|
||||
renderLaunchScreenContent,
|
||||
} from "../util/launch-screen";
|
||||
import { checkOnboardingSurveyToast } from "../util/onboarding-survey";
|
||||
import {
|
||||
@@ -60,6 +61,8 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
||||
|
||||
private _httpPendingDialogOpen = false;
|
||||
|
||||
private _initError = false;
|
||||
|
||||
private _onboardingSurveyChecked = false;
|
||||
|
||||
private _panelUrl: string;
|
||||
@@ -191,6 +194,11 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
||||
if (this.render !== this.renderHass) {
|
||||
this._renderInitInfo(false);
|
||||
}
|
||||
this.addEventListener("translations-updated", () => {
|
||||
if (this.render !== this.renderHass) {
|
||||
this._renderInitInfo(this._initError);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues): void {
|
||||
@@ -318,7 +326,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
||||
|
||||
protected async _initializeHass() {
|
||||
try {
|
||||
let result;
|
||||
let result: Awaited<Window["hassConnection"]>;
|
||||
|
||||
if (window.hassConnection) {
|
||||
result = await window.hassConnection;
|
||||
@@ -391,11 +399,25 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
||||
}
|
||||
|
||||
private _renderInitInfo(error: boolean) {
|
||||
renderLaunchScreenInfoBox(
|
||||
this._initError = error;
|
||||
renderLaunchScreenContent(
|
||||
html`<ha-init-page
|
||||
.error=${error}
|
||||
.migration=${this._databaseMigration}
|
||||
></ha-init-page>`
|
||||
.localize=${this._launchScreenLocalize}
|
||||
></ha-init-page>`,
|
||||
this._launchScreenAttribution
|
||||
);
|
||||
}
|
||||
|
||||
private get _launchScreenLocalize(): LocalizeFunc | undefined {
|
||||
return (this.hass ?? this._pendingHass).localize;
|
||||
}
|
||||
|
||||
private get _launchScreenAttribution() {
|
||||
return (
|
||||
this._launchScreenLocalize?.("ui.init.project_from") ||
|
||||
"A project from the"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,20 +225,33 @@ class SupervisorAppInfo extends MobileAwareMixin(LitElement) {
|
||||
"ui.panel.config.apps.dashboard.current_version",
|
||||
{ version: this._currentAddon.version }
|
||||
)}
|
||||
<div class="changelog" @click=${this._openChangelog}>
|
||||
(<span class="changelog-link"
|
||||
>${this.i18n.localize(
|
||||
"ui.panel.config.apps.dashboard.changelog"
|
||||
)}</span
|
||||
>)
|
||||
</div>
|
||||
${
|
||||
this._currentAddon.changelog
|
||||
? html`<div
|
||||
class="changelog"
|
||||
@click=${this._openChangelog}
|
||||
>
|
||||
(<span class="changelog-link"
|
||||
>${this.i18n.localize(
|
||||
"ui.panel.config.apps.dashboard.changelog"
|
||||
)}</span
|
||||
>)
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
`
|
||||
: html`${this._currentAddon.version_latest}
|
||||
<span class="changelog-link" @click=${this._openChangelog}
|
||||
>${this.i18n.localize(
|
||||
"ui.panel.config.apps.dashboard.changelog"
|
||||
)}</span
|
||||
>`
|
||||
${
|
||||
this._currentAddon.changelog
|
||||
? html`<span
|
||||
class="changelog-link"
|
||||
@click=${this._openChangelog}
|
||||
>${this.i18n.localize(
|
||||
"ui.panel.config.apps.dashboard.changelog"
|
||||
)}</span
|
||||
>`
|
||||
: nothing
|
||||
}`
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -155,15 +155,15 @@ class HuiEnergyDistrubutionCard
|
||||
const prefs = this._data.prefs;
|
||||
const types = energySourcesByType(prefs);
|
||||
|
||||
const hasGrid =
|
||||
!!types.grid?.[0] &&
|
||||
(!!types.grid[0].stat_energy_from || !!types.grid[0].stat_energy_to);
|
||||
const hasGrid = types.grid?.some(
|
||||
(g) => g.stat_energy_from || g.stat_energy_to
|
||||
);
|
||||
const hasSolarProduction = types.solar !== undefined;
|
||||
const hasBattery = types.battery !== undefined;
|
||||
const hasGas = types.gas !== undefined;
|
||||
const hasWater = types.water !== undefined;
|
||||
const hasReturnToGrid =
|
||||
types.grid?.some((source) => !!source.stat_energy_to) ?? false;
|
||||
types.grid?.some((source) => source.stat_energy_to) ?? false;
|
||||
|
||||
const { summedData, compareSummedData: _ } = getSummedData(this._data);
|
||||
const { consumption, compareConsumption: __ } = computeConsumptionData(
|
||||
|
||||
@@ -237,7 +237,7 @@ class HuiEnergySankeyCard
|
||||
}
|
||||
|
||||
// Add grid return if available
|
||||
if (types.grid && types.grid[0].stat_energy_to) {
|
||||
if (types.grid && types.grid.some((g) => g.stat_energy_to)) {
|
||||
const totalToGrid = summedData.total.to_grid ?? 0;
|
||||
|
||||
nodes.push({
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import { mdiSort, mdiStar, mdiStarOutline } from "@mdi/js";
|
||||
import type { IFuseOptions } from "fuse.js";
|
||||
import Fuse from "fuse.js";
|
||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { createRef, ref } from "lit/directives/ref";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import { until } from "lit/directives/until";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { storage } from "../../../../common/decorators/storage";
|
||||
import { PreserveScrollPositionController } from "../../../../common/controllers/preserve-scroll-position-controller";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
||||
import { stringCompare } from "../../../../common/string/compare";
|
||||
import "../../../../components/ha-expansion-panel";
|
||||
import "../../../../components/ha-icon-button";
|
||||
import "../../../../components/ha-ripple";
|
||||
import "../../../../components/ha-spinner";
|
||||
import "../../../../components/input/ha-input-search";
|
||||
import type { HaInputSearch } from "../../../../components/input/ha-input-search";
|
||||
import { UNAVAILABLE, UNKNOWN } from "../../../../data/entity/entity";
|
||||
import { saveFrontendUserData } from "../../../../data/frontend";
|
||||
import type { LovelaceCardConfig } from "../../../../data/lovelace/config/card";
|
||||
import type { LovelaceConfig } from "../../../../data/lovelace/config/types";
|
||||
import type { CustomCardEntry } from "../../../../data/lovelace_custom_cards";
|
||||
@@ -24,6 +32,7 @@ import {
|
||||
} from "../../../../data/lovelace_custom_cards";
|
||||
import { haStyleScrollbar } from "../../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import { showToast } from "../../../../util/toast";
|
||||
import {
|
||||
calcUnusedEntities,
|
||||
computeUsedEntities,
|
||||
@@ -33,12 +42,18 @@ import type { LovelaceCard } from "../../types";
|
||||
import { getCardStubConfig } from "../get-card-stub-config";
|
||||
import { coreCards, energyCards } from "../lovelace-cards";
|
||||
import type { Card, CardPickTarget } from "../types";
|
||||
import { showReorderFavoriteCardsDialog } from "./show-reorder-favorite-cards-dialog";
|
||||
|
||||
interface CardElement {
|
||||
card: Card;
|
||||
element: TemplateResult;
|
||||
}
|
||||
|
||||
const cardKey = (card: Card): string =>
|
||||
card.isCustom ? `${CUSTOM_TYPE_PREFIX}${card.type}` : card.type;
|
||||
|
||||
const SPINNER = html`<div class="spinner"><ha-spinner></ha-spinner></div>`;
|
||||
|
||||
@customElement("hui-card-picker")
|
||||
export class HuiCardPicker extends LitElement {
|
||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||
@@ -56,6 +71,8 @@ export class HuiCardPicker extends LitElement {
|
||||
|
||||
@state() private _cards: CardElement[] = [];
|
||||
|
||||
@state() private _favorites: string[] = [];
|
||||
|
||||
public lovelace?: LovelaceConfig;
|
||||
|
||||
public cardPicked?: (cardConf: LovelaceCardConfig) => void;
|
||||
@@ -64,10 +81,23 @@ export class HuiCardPicker extends LitElement {
|
||||
|
||||
@query("ha-input-search") private _searchInput?: HaInputSearch;
|
||||
|
||||
@query("#content") private _content?: HTMLElement;
|
||||
|
||||
private _unusedEntities?: string[];
|
||||
|
||||
private _usedEntities?: string[];
|
||||
|
||||
private _suggestedCards: CardElement[] = [];
|
||||
|
||||
private _favoriteElements = new Map<string, CardElement>();
|
||||
|
||||
private _topSection = createRef<HTMLElement>();
|
||||
|
||||
public preserveScrollPosition = new PreserveScrollPositionController(
|
||||
this,
|
||||
this._topSection
|
||||
);
|
||||
|
||||
public async focus(): Promise<void> {
|
||||
await this.updateComplete;
|
||||
// Wait for the input's inner wa-input to render so focus delegation works.
|
||||
@@ -99,18 +129,10 @@ export class HuiCardPicker extends LitElement {
|
||||
}
|
||||
);
|
||||
|
||||
private _suggestedCards = memoizeOne(
|
||||
(cardElements: CardElement[]): CardElement[] =>
|
||||
cardElements.filter(
|
||||
(cardElement: CardElement) => cardElement.card.isSuggested
|
||||
)
|
||||
);
|
||||
|
||||
private _customCards = memoizeOne(
|
||||
(cardElements: CardElement[]): CardElement[] =>
|
||||
cardElements.filter(
|
||||
(cardElement: CardElement) =>
|
||||
cardElement.card.isCustom && !cardElement.card.isSuggested
|
||||
(cardElement: CardElement) => cardElement.card.isCustom
|
||||
)
|
||||
);
|
||||
|
||||
@@ -118,9 +140,7 @@ export class HuiCardPicker extends LitElement {
|
||||
(cardElements: CardElement[]): CardElement[] =>
|
||||
cardElements.filter(
|
||||
(cardElement: CardElement) =>
|
||||
!cardElement.card.isSuggested &&
|
||||
!cardElement.card.isCustom &&
|
||||
!cardElement.card.isEnergy
|
||||
!cardElement.card.isCustom && !cardElement.card.isEnergy
|
||||
)
|
||||
);
|
||||
|
||||
@@ -131,6 +151,34 @@ export class HuiCardPicker extends LitElement {
|
||||
)
|
||||
);
|
||||
|
||||
private _favoriteCards(): CardElement[] {
|
||||
return this._favorites
|
||||
.map((key) => this._favoriteElement(key))
|
||||
.filter((cardElement): cardElement is CardElement => !!cardElement);
|
||||
}
|
||||
|
||||
// A preview is a live DOM node, so every section a card shows up in needs
|
||||
// its own element.
|
||||
private _toCardElement(card: Card): CardElement {
|
||||
return {
|
||||
card,
|
||||
element: html`${until(this._renderCardElement(card), SPINNER)}`,
|
||||
};
|
||||
}
|
||||
|
||||
private _favoriteElement(key: string): CardElement | undefined {
|
||||
let cardElement = this._favoriteElements.get(key);
|
||||
if (!cardElement) {
|
||||
const card = this._cards.find((item) => cardKey(item.card) === key)?.card;
|
||||
if (!card) {
|
||||
return undefined;
|
||||
}
|
||||
cardElement = this._toCardElement(card);
|
||||
this._favoriteElements.set(key, cardElement);
|
||||
}
|
||||
return cardElement;
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (
|
||||
!this.hass ||
|
||||
@@ -141,7 +189,8 @@ export class HuiCardPicker extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const suggestedCards = this._suggestedCards(this._cards);
|
||||
const favoriteCards = this._favoriteCards();
|
||||
const suggestedCards = favoriteCards.length > 0 ? [] : this._suggestedCards;
|
||||
const othersCards = this._otherCards(this._cards);
|
||||
const energyCardsItems = this._energyCards(this._cards);
|
||||
const customCardsItems = this._customCards(this._cards);
|
||||
@@ -160,53 +209,106 @@ export class HuiCardPicker extends LitElement {
|
||||
this._filter
|
||||
? html`<div class="cards-container">
|
||||
${this._filterCards(this._cards, this._filter).map(
|
||||
(cardElement: CardElement) => cardElement.element
|
||||
(cardElement: CardElement) => this._renderCard(cardElement)
|
||||
)}
|
||||
</div>`
|
||||
: html`
|
||||
${
|
||||
suggestedCards.length > 0
|
||||
? html` <ha-expansion-panel expanded>
|
||||
<div slot="header" class="cards-container-header">
|
||||
${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.suggested_cards`
|
||||
)}
|
||||
</div>
|
||||
<div class="cards-container">
|
||||
${this._renderClipboardCard()}
|
||||
${suggestedCards.map(
|
||||
(cardElement: CardElement) => cardElement.element
|
||||
)}
|
||||
</div>
|
||||
</ha-expansion-panel>`
|
||||
: nothing
|
||||
}
|
||||
<div ${ref(this._topSection)}>
|
||||
${
|
||||
favoriteCards.length > 0
|
||||
? html`<ha-expansion-panel expanded>
|
||||
<div slot="header" class="cards-container-header">
|
||||
<span class="title"
|
||||
>${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.favorite_cards`
|
||||
)}</span
|
||||
>
|
||||
${
|
||||
favoriteCards.length > 1
|
||||
? html`<ha-icon-button
|
||||
class="reorder-favorites"
|
||||
.path=${mdiSort}
|
||||
.label=${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.reorder_favorites`
|
||||
)}
|
||||
@click=${this._reorderFavorites}
|
||||
></ha-icon-button>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
<div class="cards-container">
|
||||
${this._renderClipboardCard(this._clipboard, this.hass!.locale)}
|
||||
${repeat(
|
||||
favoriteCards,
|
||||
(cardElement: CardElement) =>
|
||||
cardKey(cardElement.card),
|
||||
(cardElement: CardElement) =>
|
||||
this._renderCard(cardElement)
|
||||
)}
|
||||
</div>
|
||||
</ha-expansion-panel>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
suggestedCards.length > 0
|
||||
? html`<ha-expansion-panel expanded>
|
||||
<div slot="header" class="cards-container-header">
|
||||
<span class="title"
|
||||
>${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.suggested_cards`
|
||||
)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="cards-container">
|
||||
${
|
||||
favoriteCards.length === 0
|
||||
? this._renderClipboardCard(
|
||||
this._clipboard,
|
||||
this.hass!.locale
|
||||
)
|
||||
: nothing
|
||||
}
|
||||
${suggestedCards.map((cardElement: CardElement) =>
|
||||
this._renderCard(cardElement)
|
||||
)}
|
||||
</div>
|
||||
</ha-expansion-panel>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
<ha-expansion-panel expanded>
|
||||
<div slot="header" class="cards-container-header">
|
||||
${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.core_cards`
|
||||
)}
|
||||
<span class="title"
|
||||
>${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.core_cards`
|
||||
)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="cards-container">
|
||||
${
|
||||
suggestedCards.length === 0
|
||||
? this._renderClipboardCard()
|
||||
favoriteCards.length === 0 && suggestedCards.length === 0
|
||||
? this._renderClipboardCard(
|
||||
this._clipboard,
|
||||
this.hass!.locale
|
||||
)
|
||||
: nothing
|
||||
}
|
||||
${othersCards.map(
|
||||
(cardElement: CardElement) => cardElement.element
|
||||
${othersCards.map((cardElement: CardElement) =>
|
||||
this._renderCard(cardElement)
|
||||
)}
|
||||
</div>
|
||||
</ha-expansion-panel>
|
||||
<ha-expansion-panel>
|
||||
<div slot="header" class="cards-container-header">
|
||||
${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.energy_cards`
|
||||
)}
|
||||
<span class="title"
|
||||
>${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.energy_cards`
|
||||
)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="cards-container">
|
||||
${energyCardsItems.map(
|
||||
(cardElement: CardElement) => cardElement.element
|
||||
${energyCardsItems.map((cardElement: CardElement) =>
|
||||
this._renderCard(cardElement)
|
||||
)}
|
||||
</div>
|
||||
</ha-expansion-panel>
|
||||
@@ -215,13 +317,15 @@ export class HuiCardPicker extends LitElement {
|
||||
? html`
|
||||
<ha-expansion-panel expanded>
|
||||
<div slot="header" class="cards-container-header">
|
||||
${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.custom_cards`
|
||||
)}
|
||||
<span class="title"
|
||||
>${this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.card.generic.custom_cards`
|
||||
)}</span
|
||||
>
|
||||
</div>
|
||||
<div class="cards-container">
|
||||
${customCardsItems.map(
|
||||
(cardElement: CardElement) => cardElement.element
|
||||
${customCardsItems.map((cardElement: CardElement) =>
|
||||
this._renderCard(cardElement)
|
||||
)}
|
||||
</div>
|
||||
</ha-expansion-panel>
|
||||
@@ -254,16 +358,12 @@ export class HuiCardPicker extends LitElement {
|
||||
}
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues<this>): boolean {
|
||||
if (changedProps.size > 1 || !changedProps.has("hass")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const oldHass = changedProps.get("hass") as HomeAssistant | undefined;
|
||||
if (!oldHass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (oldHass.locale !== this.hass!.locale) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return !oldHass || oldHass.locale !== this.hass!.locale;
|
||||
}
|
||||
|
||||
protected firstUpdated(): void {
|
||||
@@ -283,16 +383,15 @@ export class HuiCardPicker extends LitElement {
|
||||
this._usedEntities = [...usedEntities].filter(isAvailable);
|
||||
this._unusedEntities = [...unusedEntities].filter(isAvailable);
|
||||
|
||||
this._favorites = this.hass.userData?.dashboard_favorite_card_types ?? [];
|
||||
|
||||
this._loadCards();
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues) {
|
||||
super.updated(changedProps);
|
||||
if (changedProps.has("_filter")) {
|
||||
const div = this.shadowRoot!.getElementById("content");
|
||||
if (div) {
|
||||
div.scrollTo({ behavior: "auto", top: 0 });
|
||||
}
|
||||
this._content?.scrollTo({ behavior: "auto", top: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,19 +407,9 @@ export class HuiCardPicker extends LitElement {
|
||||
...card,
|
||||
}));
|
||||
|
||||
cards = cards.sort((a, b) => {
|
||||
if (a.isSuggested && !b.isSuggested) {
|
||||
return -1;
|
||||
}
|
||||
if (!a.isSuggested && b.isSuggested) {
|
||||
return 1;
|
||||
}
|
||||
return stringCompare(
|
||||
a.name || a.type,
|
||||
b.name || b.type,
|
||||
this.hass?.language
|
||||
);
|
||||
});
|
||||
cards = cards.sort((a, b) =>
|
||||
stringCompare(a.name || a.type, b.name || b.type, this.hass?.language)
|
||||
);
|
||||
|
||||
cards = cards.concat(
|
||||
energyCards.map((card: Card) => ({
|
||||
@@ -354,48 +443,126 @@ export class HuiCardPicker extends LitElement {
|
||||
)
|
||||
);
|
||||
}
|
||||
this._cards = cards.map((card: Card) => ({
|
||||
card: card,
|
||||
element: html`${until(
|
||||
this._renderCardElement(card),
|
||||
html`
|
||||
<div class="card spinner">
|
||||
<ha-spinner></ha-spinner>
|
||||
</div>
|
||||
`
|
||||
)}`,
|
||||
}));
|
||||
this._cards = cards.map((card: Card) => this._toCardElement(card));
|
||||
this._suggestedCards = cards
|
||||
.filter((card: Card) => card.isSuggested)
|
||||
.map((card: Card) => this._toCardElement(card));
|
||||
}
|
||||
|
||||
private _renderClipboardCard() {
|
||||
if (!this._clipboard) {
|
||||
return nothing;
|
||||
}
|
||||
private _renderClipboardCard = memoizeOne(
|
||||
(clipboard: LovelaceCardConfig | undefined, _locale: unknown) => {
|
||||
if (!clipboard) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html` ${until(
|
||||
this._renderCardElement(
|
||||
{
|
||||
type: this._clipboard.type,
|
||||
showElement: true,
|
||||
isCustom: false,
|
||||
name: this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.generic.paste"
|
||||
),
|
||||
description: `${this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.generic.paste_description",
|
||||
return html`<div class="card" tabindex="0">
|
||||
${until(
|
||||
this._renderCardElement(
|
||||
{
|
||||
type: this._clipboard.type,
|
||||
}
|
||||
)}`,
|
||||
},
|
||||
this._clipboard
|
||||
type: clipboard.type,
|
||||
showElement: true,
|
||||
isCustom: false,
|
||||
name: this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.generic.paste"
|
||||
),
|
||||
description: `${this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.generic.paste_description",
|
||||
{
|
||||
type: clipboard.type,
|
||||
}
|
||||
)}`,
|
||||
},
|
||||
clipboard
|
||||
),
|
||||
SPINNER
|
||||
)}
|
||||
<ha-ripple></ha-ripple>
|
||||
</div>`;
|
||||
}
|
||||
);
|
||||
|
||||
private _renderCard(cardElement: CardElement): TemplateResult {
|
||||
const key = cardKey(cardElement.card);
|
||||
const favorite = this._favorites.includes(key);
|
||||
|
||||
return html`
|
||||
<div class="card" tabindex="0">
|
||||
${cardElement.element}
|
||||
<ha-icon-button
|
||||
class="favorite ${classMap({ selected: favorite })}"
|
||||
.path=${favorite ? mdiStar : mdiStarOutline}
|
||||
.label=${this.hass!.localize(
|
||||
favorite
|
||||
? "ui.panel.lovelace.editor.card.generic.remove_favorite"
|
||||
: "ui.panel.lovelace.editor.card.generic.add_favorite"
|
||||
)}
|
||||
data-card=${key}
|
||||
@click=${this._toggleFavorite}
|
||||
@pointerdown=${stopPropagation}
|
||||
></ha-icon-button>
|
||||
<ha-ripple></ha-ripple>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
private _setFavorite(key: string, value: boolean): void {
|
||||
const favorites = this._favorites.filter((favorite) => favorite !== key);
|
||||
this._favorites = value ? [...favorites, key] : favorites;
|
||||
}
|
||||
|
||||
private async _toggleFavorite(ev: Event): Promise<void> {
|
||||
ev.stopPropagation();
|
||||
const key = (ev.currentTarget as HTMLElement).dataset.card!;
|
||||
|
||||
const adding = !this._favorites.includes(key);
|
||||
this._setFavorite(key, adding);
|
||||
|
||||
try {
|
||||
await this._persistFavorites();
|
||||
} catch (_err: any) {
|
||||
this._setFavorite(key, !adding);
|
||||
this._showSaveError();
|
||||
}
|
||||
}
|
||||
|
||||
private _reorderFavorites(ev: Event): void {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
showReorderFavoriteCardsDialog(this, {
|
||||
favorites: this._favoriteCards().map((cardElement) => ({
|
||||
key: cardKey(cardElement.card),
|
||||
name: cardElement.card.name || cardElement.card.type,
|
||||
})),
|
||||
saveFavorites: (favorites) => this._saveFavorites(favorites),
|
||||
});
|
||||
}
|
||||
|
||||
private async _saveFavorites(favorites: string[]): Promise<void> {
|
||||
const previous = this._favorites;
|
||||
this._favorites = favorites;
|
||||
|
||||
try {
|
||||
await this._persistFavorites();
|
||||
} catch (_err: any) {
|
||||
this._favorites = previous;
|
||||
this._showSaveError();
|
||||
}
|
||||
}
|
||||
|
||||
private _persistFavorites(): Promise<void> {
|
||||
return saveFrontendUserData(this.hass!.connection, "core", {
|
||||
...this.hass!.userData,
|
||||
dashboard_favorite_card_types: this._favorites,
|
||||
});
|
||||
}
|
||||
|
||||
private _showSaveError(): void {
|
||||
showToast(this, {
|
||||
message: this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.card.generic.favorite_save_failed"
|
||||
),
|
||||
html`
|
||||
<div class="card spinner">
|
||||
<ha-spinner></ha-spinner>
|
||||
</div>
|
||||
`
|
||||
)}`;
|
||||
});
|
||||
}
|
||||
|
||||
private _handleSearchChange(ev: Event) {
|
||||
@@ -477,32 +644,29 @@ export class HuiCardPicker extends LitElement {
|
||||
}
|
||||
|
||||
return html`
|
||||
<div class="card" tabindex="0">
|
||||
<div
|
||||
class="overlay"
|
||||
@click=${this._cardPicked}
|
||||
.config=${cardConfig}
|
||||
></div>
|
||||
<div class="card-header">
|
||||
${customCard ? customCard.name || customCard.type : name}
|
||||
</div>
|
||||
<div
|
||||
class="preview ${classMap({
|
||||
description: !element || element.tagName === "HUI-ERROR-CARD",
|
||||
})}"
|
||||
>
|
||||
${
|
||||
element && element.tagName !== "HUI-ERROR-CARD"
|
||||
? element
|
||||
: customCard
|
||||
? customCard.description ||
|
||||
this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.cardpicker.no_description`
|
||||
)
|
||||
: description
|
||||
}
|
||||
</div>
|
||||
<ha-ripple></ha-ripple>
|
||||
<div
|
||||
class="overlay"
|
||||
@click=${this._cardPicked}
|
||||
.config=${cardConfig}
|
||||
></div>
|
||||
<div class="card-header">
|
||||
${customCard ? customCard.name || customCard.type : name}
|
||||
</div>
|
||||
<div
|
||||
class="preview ${classMap({
|
||||
description: !element || element.tagName === "HUI-ERROR-CARD",
|
||||
})}"
|
||||
>
|
||||
${
|
||||
element && element.tagName !== "HUI-ERROR-CARD"
|
||||
? element
|
||||
: customCard
|
||||
? customCard.description ||
|
||||
this.hass!.localize(
|
||||
`ui.panel.lovelace.editor.cardpicker.no_description`
|
||||
)
|
||||
: description
|
||||
}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@@ -531,6 +695,10 @@ export class HuiCardPicker extends LitElement {
|
||||
}
|
||||
|
||||
.cards-container-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-2);
|
||||
min-width: 0;
|
||||
font-size: var(--ha-font-size-l);
|
||||
font-weight: var(--ha-font-weight-medium);
|
||||
padding: var(--ha-space-3) var(--ha-space-2);
|
||||
@@ -578,11 +746,55 @@ export class HuiCardPicker extends LitElement {
|
||||
font-weight: var(--ha-font-weight-bold);
|
||||
letter-spacing: -0.012em;
|
||||
line-height: var(--ha-line-height-condensed);
|
||||
padding: var(--ha-space-3) var(--ha-space-4);
|
||||
padding: var(--ha-space-3) var(--ha-space-11);
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cards-container-header .title {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.reorder-favorites {
|
||||
flex: none;
|
||||
margin-inline-start: auto;
|
||||
/* Keeps the hit area without growing the header row */
|
||||
margin-block: calc(-1 * var(--ha-space-1));
|
||||
--ha-icon-button-size: var(--ha-space-8);
|
||||
--mdc-icon-size: var(--ha-space-5);
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
|
||||
.favorite {
|
||||
position: absolute;
|
||||
top: var(--ha-space-1);
|
||||
inset-inline-end: var(--ha-space-1);
|
||||
z-index: 2;
|
||||
color: var(--secondary-text-color);
|
||||
opacity: 0;
|
||||
transition: opacity var(--ha-animation-duration-fast) ease-in-out;
|
||||
--ha-icon-button-size: var(--ha-space-10);
|
||||
}
|
||||
|
||||
.card:hover .favorite,
|
||||
.card:focus-within .favorite,
|
||||
.favorite.selected {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.favorite.selected {
|
||||
color: var(--primary-color);
|
||||
}
|
||||
|
||||
@media (hover: none) {
|
||||
.favorite {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.preview {
|
||||
pointer-events: none;
|
||||
margin: var(--ha-space-5);
|
||||
@@ -602,6 +814,8 @@ export class HuiCardPicker extends LitElement {
|
||||
}
|
||||
|
||||
.spinner {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -622,23 +836,6 @@ export class HuiCardPicker extends LitElement {
|
||||
max-width: none;
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.icon {
|
||||
position: absolute;
|
||||
top: var(--ha-space-2);
|
||||
right: var(--ha-space-2);
|
||||
inset-inline-start: var(--ha-space-2);
|
||||
inset-inline-end: var(--ha-space-2);
|
||||
border-radius: var(--ha-border-radius-circle);
|
||||
--mdc-icon-size: var(--ha-space-4);
|
||||
line-height: var(--ha-space-4);
|
||||
box-sizing: border-box;
|
||||
color: var(--text-primary-color);
|
||||
padding: var(--ha-space-1);
|
||||
}
|
||||
.icon.custom {
|
||||
background: var(--warning-color);
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
import { mdiDragHorizontalVariant } from "@mdi/js";
|
||||
import type { CSSResultGroup } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { repeat } from "lit/directives/repeat";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import "../../../../components/ha-button";
|
||||
import "../../../../components/ha-dialog";
|
||||
import "../../../../components/ha-dialog-footer";
|
||||
import "../../../../components/ha-sortable";
|
||||
import "../../../../components/ha-svg-icon";
|
||||
import { haStyleDialog } from "../../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../../types";
|
||||
import type {
|
||||
FavoriteCardItem,
|
||||
ReorderFavoriteCardsDialogParams,
|
||||
} from "./show-reorder-favorite-cards-dialog";
|
||||
|
||||
@customElement("hui-dialog-reorder-favorite-cards")
|
||||
export class HuiDialogReorderFavoriteCards extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@state() private _params?: ReorderFavoriteCardsDialogParams;
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _favorites: FavoriteCardItem[] = [];
|
||||
|
||||
public async showDialog(
|
||||
params: ReorderFavoriteCardsDialogParams
|
||||
): Promise<void> {
|
||||
this._params = params;
|
||||
this._favorites = params.favorites;
|
||||
this._open = true;
|
||||
}
|
||||
|
||||
public closeDialog(): void {
|
||||
this._open = false;
|
||||
}
|
||||
|
||||
private _dialogClosed(): void {
|
||||
this._open = false;
|
||||
this._params = undefined;
|
||||
this._favorites = [];
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this._params) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
header-title=${this.hass.localize(
|
||||
"ui.panel.lovelace.editor.card.generic.reorder_favorites"
|
||||
)}
|
||||
@closed=${this._dialogClosed}
|
||||
>
|
||||
<ha-sortable handle-selector=".handle" @item-moved=${this._moved}>
|
||||
<div class="favorites">
|
||||
${repeat(
|
||||
this._favorites,
|
||||
(favorite) => favorite.key,
|
||||
(favorite) => html`
|
||||
<div class="favorite">
|
||||
<div class="handle">
|
||||
<ha-svg-icon
|
||||
.path=${mdiDragHorizontalVariant}
|
||||
></ha-svg-icon>
|
||||
</div>
|
||||
<span class="name">${favorite.name}</span>
|
||||
</div>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
</ha-sortable>
|
||||
<ha-dialog-footer slot="footer">
|
||||
<ha-button slot="primaryAction" @click=${this.closeDialog}>
|
||||
${this.hass.localize("ui.common.close")}
|
||||
</ha-button>
|
||||
</ha-dialog-footer>
|
||||
</ha-dialog>
|
||||
`;
|
||||
}
|
||||
|
||||
private _moved(ev: HASSDomEvent<HASSDomEvents["item-moved"]>): void {
|
||||
ev.stopPropagation();
|
||||
const { oldIndex, newIndex } = ev.detail;
|
||||
const favorites = [...this._favorites];
|
||||
const [moved] = favorites.splice(oldIndex, 1);
|
||||
favorites.splice(newIndex, 0, moved);
|
||||
|
||||
this._favorites = favorites;
|
||||
this._params!.saveFavorites(favorites.map((favorite) => favorite.key));
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyleDialog,
|
||||
css`
|
||||
.favorites {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.favorite {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-2);
|
||||
min-height: var(--ha-space-12);
|
||||
}
|
||||
.handle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
cursor: grab;
|
||||
padding: var(--ha-space-2);
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
.name {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
`,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"hui-dialog-reorder-favorite-cards": HuiDialogReorderFavoriteCards;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
|
||||
export interface FavoriteCardItem {
|
||||
key: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ReorderFavoriteCardsDialogParams {
|
||||
favorites: FavoriteCardItem[];
|
||||
saveFavorites: (favorites: string[]) => void;
|
||||
}
|
||||
|
||||
export const importReorderFavoriteCardsDialog = () =>
|
||||
import("./hui-dialog-reorder-favorite-cards");
|
||||
|
||||
export const showReorderFavoriteCardsDialog = (
|
||||
element: HTMLElement,
|
||||
reorderFavoriteCardsDialogParams: ReorderFavoriteCardsDialogParams
|
||||
): void => {
|
||||
fireEvent(element, "show-dialog", {
|
||||
dialogTag: "hui-dialog-reorder-favorite-cards",
|
||||
dialogImport: importReorderFavoriteCardsDialog,
|
||||
dialogParams: reorderFavoriteCardsDialogParams,
|
||||
});
|
||||
};
|
||||
@@ -74,6 +74,18 @@
|
||||
}
|
||||
},
|
||||
"ui": {
|
||||
"init": {
|
||||
"loading": "Loading data",
|
||||
"migration": "Database upgrade is in progress, Home Assistant will not start until the upgrade is completed.\n\nThe upgrade may need a long time to complete, please be patient.",
|
||||
"project_from": "A project from the",
|
||||
"error": {
|
||||
"title": "Unable to connect to Home Assistant.",
|
||||
"retrying": "Retrying in {seconds, plural, one {# second} other {# seconds}}...",
|
||||
"retry_now": "Retry now",
|
||||
"nabu_casa": "It is possible that you are seeing this screen because your Home Assistant is not currently connected. You can ask it to come online from your {account_link}.",
|
||||
"nabu_casa_account": "Nabu Casa account page"
|
||||
}
|
||||
},
|
||||
"backup": {
|
||||
"upload_backup": "Upload backup"
|
||||
},
|
||||
@@ -10063,6 +10075,11 @@
|
||||
"core_cards": "Core cards",
|
||||
"energy_cards": "Energy cards",
|
||||
"custom_cards": "Community cards",
|
||||
"favorite_cards": "Favorite cards",
|
||||
"add_favorite": "Add to favorites",
|
||||
"remove_favorite": "Remove from favorites",
|
||||
"reorder_favorites": "Reorder favorites",
|
||||
"favorite_save_failed": "Failed to save favorite cards",
|
||||
"round_temperature": "Round temperature",
|
||||
"features": "Features",
|
||||
"actions": "Actions",
|
||||
|
||||
@@ -26,28 +26,42 @@ export const removeLaunchScreen = (instant = false): boolean => {
|
||||
return true;
|
||||
}
|
||||
|
||||
withViewTransition((viewTransitionAvailable: boolean) => {
|
||||
if (!viewTransitionAvailable) {
|
||||
withViewTransition((viewTransitionAvailable) => {
|
||||
if (viewTransitionAvailable) {
|
||||
launchScreenElement.parentElement?.removeChild(launchScreenElement);
|
||||
return;
|
||||
}
|
||||
|
||||
launchScreenElement.classList.add("removing");
|
||||
|
||||
const durationFromCss = getComputedStyle(document.documentElement)
|
||||
.getPropertyValue("--ha-animation-duration-slow")
|
||||
.getPropertyValue("--ha-animation-duration-normal")
|
||||
.trim();
|
||||
|
||||
setTimeout(() => {
|
||||
launchScreenElement.parentElement?.removeChild(launchScreenElement);
|
||||
}, parseAnimationDuration(durationFromCss));
|
||||
setTimeout(
|
||||
() => {
|
||||
launchScreenElement.parentElement?.removeChild(launchScreenElement);
|
||||
},
|
||||
parseAnimationDuration(durationFromCss || "250ms")
|
||||
);
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
export const renderLaunchScreenInfoBox = (content: TemplateResult) => {
|
||||
export const renderLaunchScreenContent = (
|
||||
content: TemplateResult,
|
||||
attribution: string
|
||||
) => {
|
||||
const infoBoxElement = document.getElementById("ha-launch-screen-info-box");
|
||||
if (infoBoxElement) {
|
||||
render(content, infoBoxElement);
|
||||
}
|
||||
updateLaunchScreenAttribution(attribution);
|
||||
};
|
||||
|
||||
export const updateLaunchScreenAttribution = (attribution: string) => {
|
||||
const attributionElement = document.getElementById(
|
||||
"ha-launch-screen-attribution"
|
||||
);
|
||||
if (attributionElement) {
|
||||
attributionElement.textContent = attribution;
|
||||
}
|
||||
};
|
||||
|
||||
+26
-17
@@ -1,4 +1,5 @@
|
||||
import { expect, type Page } from "@playwright/test";
|
||||
import type { HaDrawer } from "../../../src/components/ha-drawer";
|
||||
import type { ThemeSettings } from "../../../src/types";
|
||||
import { NAVIGATION_TIMEOUT, SHELL_TIMEOUT } from "../helpers";
|
||||
|
||||
@@ -66,26 +67,34 @@ export async function expectStoredDemoTheme(
|
||||
}
|
||||
|
||||
export async function openDemoSidebar(page: Page) {
|
||||
const menuButton = page.locator("ha-menu-button");
|
||||
if (await menuButton.isVisible()) {
|
||||
const modalDrawer = page.locator("ha-drawer").locator("wa-drawer");
|
||||
await Promise.all([
|
||||
modalDrawer.evaluate(
|
||||
(element) =>
|
||||
new Promise<void>((resolve) => {
|
||||
element.addEventListener("wa-after-show", () => resolve(), {
|
||||
once: true,
|
||||
});
|
||||
})
|
||||
),
|
||||
menuButton.click(),
|
||||
]);
|
||||
const drawer = page.locator("ha-drawer");
|
||||
await expect(drawer).toBeAttached({ timeout: NAVIGATION_TIMEOUT });
|
||||
|
||||
// Pick the layout from ha-drawer, which home-assistant-main sets to "modal"
|
||||
// while committing its very first render (the narrow media query is resolved
|
||||
// synchronously in its constructor). ha-menu-button must not be used for
|
||||
// this: it renders nothing until its Lit contexts resolve, so sampling its
|
||||
// visibility straight after load reports "hidden" on the narrow layout too,
|
||||
// and the drawer would then silently never be opened.
|
||||
const isModal = await drawer.evaluate(
|
||||
(element) => (element as HaDrawer).type === "modal"
|
||||
);
|
||||
|
||||
if (!isModal) {
|
||||
// Wide layout: the sidebar is permanently on screen.
|
||||
await expect(page.locator("ha-sidebar")).toBeVisible({
|
||||
timeout: NAVIGATION_TIMEOUT,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await expect(page.locator("ha-sidebar")).toBeAttached({
|
||||
timeout: NAVIGATION_TIMEOUT,
|
||||
});
|
||||
const menuButton = page.locator("ha-menu-button");
|
||||
await expect(menuButton).toBeVisible({ timeout: SHELL_TIMEOUT });
|
||||
await menuButton.click();
|
||||
// ha-drawer reflects `open` once the app has actually opened the drawer.
|
||||
// The slide-in animation is covered by Playwright's stability check on the
|
||||
// next interaction.
|
||||
await expect(drawer).toHaveAttribute("open", "", { timeout: SHELL_TIMEOUT });
|
||||
}
|
||||
|
||||
export async function activateDemoSidebarPanel(page: Page, panel: string) {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { LitElement } from "lit";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { LocalizeFunc } from "../../src/common/translations/localize";
|
||||
import type { HaInitPage } from "../../src/layouts/ha-init-page";
|
||||
|
||||
vi.mock("../../src/components/ha-button", () => ({}));
|
||||
customElements.define("ha-button", class extends LitElement {});
|
||||
await import("../../src/layouts/ha-init-page");
|
||||
|
||||
const translations: Record<string, string> = {
|
||||
"ui.init.loading": "Loading translated data",
|
||||
"ui.init.migration": "Database migration translated\n\nPlease wait",
|
||||
"ui.init.error.title": "Connection error translated",
|
||||
"ui.init.error.retry_now": "Retry translated",
|
||||
};
|
||||
|
||||
const localize: LocalizeFunc = (key, values) => {
|
||||
if (key === "ui.init.error.retrying") {
|
||||
return `Retry translated ${values?.seconds}`;
|
||||
}
|
||||
return translations[key] ?? "";
|
||||
};
|
||||
|
||||
let host: HTMLDivElement | undefined;
|
||||
let element: HaInitPage | undefined;
|
||||
|
||||
const mount = async (properties: Partial<HaInitPage> = {}) => {
|
||||
host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
element = document.createElement("ha-init-page");
|
||||
Object.assign(element, { localize, ...properties });
|
||||
host.append(element);
|
||||
await element.updateComplete;
|
||||
return element;
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
host?.remove();
|
||||
host = undefined;
|
||||
element = undefined;
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe("ha-init-page", () => {
|
||||
it("renders localized loading and migration states", async () => {
|
||||
const initPage = await mount();
|
||||
expect(initPage.shadowRoot!.textContent).toContain(
|
||||
"Loading translated data"
|
||||
);
|
||||
|
||||
initPage.migration = true;
|
||||
await initPage.updateComplete;
|
||||
expect(
|
||||
initPage.shadowRoot!.querySelector(".migration-text")!.textContent
|
||||
).toBe("Database migration translated\n\nPlease wait");
|
||||
});
|
||||
|
||||
it("preserves migration paragraph breaks without localization", async () => {
|
||||
const initPage = await mount({ localize: undefined, migration: true });
|
||||
|
||||
expect(
|
||||
initPage.shadowRoot!.querySelector(".migration-text")!.textContent
|
||||
).toContain("completed.\n\nThe upgrade");
|
||||
});
|
||||
|
||||
it("renders the localized connection error and countdown", async () => {
|
||||
const initPage = await mount({ error: true });
|
||||
|
||||
expect(initPage.shadowRoot!.textContent).toContain(
|
||||
"Connection error translated"
|
||||
);
|
||||
expect(initPage.shadowRoot!.textContent).toContain("Retry translated 60");
|
||||
expect(
|
||||
initPage.shadowRoot!.querySelector("ha-button")!.textContent
|
||||
).toContain("Retry translated");
|
||||
});
|
||||
|
||||
it("counts down once per second and stops after disconnecting", async () => {
|
||||
vi.useFakeTimers();
|
||||
const initPage = await mount({ error: true });
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
await initPage.updateComplete;
|
||||
expect(initPage.shadowRoot!.textContent).toContain("Retry translated 59");
|
||||
|
||||
initPage.remove();
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(initPage.shadowRoot!.textContent).toContain("Retry translated 59");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user