Repository navigation
Expand file tree
/
Copy pathcard-preview.html
More file actions
74 lines (74 loc) · 5.07 KB
/
Copy pathcard-preview.html
File metadata and controls
74 lines (74 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Outage Map · Sample dashboard</title>
<style>
body{margin:0;background:#101822;color:#f4f7fb;font:15px/1.35 system-ui;display:grid;grid-template-columns:190px 1fr;min-height:100vh}
nav{background:#141f2b;border-right:1px solid #263447;padding:22px 14px;display:flex;flex-direction:column;gap:20px}
nav strong{color:#34ddec} nav small{color:#acbbcd} main{padding:20px;min-width:0} ha-icon{display:inline-grid;place-items:center;width:22px;height:22px}
/* Sample native Home Assistant palette for Follow Appearance. */
outage-watch-card{--primary-background-color:#191321;--ha-card-background:#291f35;--secondary-background-color:#3a2e49;--primary-text-color:#f8f0ff;--secondary-text-color:#d3bddf;--primary-color:#d9adff;--text-primary-color:#311443;--divider-color:#766685;--success-color:#a6e4b8;--warning-color:#ffd091;--error-color:#ffb5bd}
@media(max-width:900px){body{display:block}nav{display:none}main{padding:10px}}
</style>
<nav aria-label="Preview navigation"><b>⌂ Home Assistant</b><span>Overview</span><span>Energy</span><span>History</span><strong>Outage Map</strong><small>DESIGN PREVIEW · SAMPLE DATA</small></nav>
<main><outage-watch-card></outage-watch-card></main>
<script src="../../custom_components/outage_watch/www/outage-watch-card.js"></script>
<script>
const now = Date.now() / 1000;
const services = [
["github","GitHub",482,"source-branch"],["cloudflare","Cloudflare",289,"cloud-outline"],
["apple","Apple iCloud",118,"cloud-outline"],["google","Google",124,"magnify"],
["netflix","Netflix",96,"play-box-outline"],["spotify","Spotify",107,"music-note"],
["ewelink","eWeLink",85,"home-outline"],["example","example.com",112,"link-variant"],
["cloud","Home Assistant Cloud",103,"cloud-outline"],["anthropic","Anthropic",172,"magnify"],
["weather","Environment Canada Weather",143,"cloud-outline"],["met","MET Norway API",158,"cloud-outline"],
["radio","Radio Browser",192,"music-note"],["translate","Google Translate",136,"magnify"],
].map(([id,name,latency,icon], index) => ({
id,name,latency,icon,
category: ["netflix","plex"].includes(id) ? "Video" : ["spotify","radio"].includes(id) ? "Audio" :
["apple","ewelink"].includes(id) ? "Smart home" : ["weather","met"].includes(id) ? "Weather" :
id === "example" ? "Custom" : "Online services",
baseline:index < 2 ? 112 : latency, checked:now-60,
status:index === 0 ? "outage" : index === 1 ? "possible_problems" : "operational",
reason:index === 0 ? "provider_outage" : index === 1 ? "slow" : "ok",
signal:index < 4 ? "Feed + checks" : "Checks only", feed_fresh:index < 4, feed_checked:index < 4 ? now-120 : null,
history:Array.from({length:96}, (_, i) => [now-86400+i*900,"ok",Math.max(30,(index === 0 && i > 77 ? 402 : index < 2 ? 112 : latency)+Math.sin(i*1.7)*15+Math.cos(i*.9)*8+(index === 1 && i % 26 === 18 ? 98 : 0))]),
...(index === 0 ? {incident:"Git operations degraded. Some users may experience errors.",components:["Git Operations","API Requests"],official:"https://www.githubstatus.com/",crowd:"https://downdetector.com/status/github/"} : {}),
}));
const catalog = [{id:"docker",name:"Docker Hub"},{id:"tailscale",name:"Tailscale"}];
customElements.define("ha-icon", class extends HTMLElement {
connectedCallback() {
const name = this.getAttribute("icon").slice(4);
this.textContent = ({"source-branch":"⑂","cloud-outline":"☁","magnify":"⌕","play-box-outline":"▷","music-note":"♫","home-outline":"⌂","link-variant":"↗"})[name] || "◇";
this.setAttribute("aria-hidden", "true");
}
});
const card = document.querySelector("outage-watch-card");
card.setConfig({});
const speedStates = {
"sensor.speedtest_download": {state:"241.4", last_updated:new Date(now * 1000).toISOString()},
"sensor.speedtest_upload": {state:"31.8", last_updated:new Date(now * 1000).toISOString()},
"sensor.speedtest_ping": {state:"29", last_updated:new Date(now * 1000).toISOString()},
};
const speedHistory = Object.fromEntries(Object.keys(speedStates).slice(0, 2).map((id, index) => [
id, Array.from({length:24}, (_, i) => ({
lu:now - (24 - i) * 3600, s:String(index === 0 ? 190 + i * 2 + 22 * Math.sin(i) : 28 + 4 * Math.sin(i * 1.7)),
})),
]));
card.hass = {
states:speedStates,
callWS: async ({type}) => type === "history/history_during_period" ? speedHistory :
{services, catalog, connected:true, can_manage:true, notify_configured:true},
callService: async (_, action, data) => {
const index = services.findIndex((item) => item.id === data.service_id);
if (action === "set_alerts") services[index].alerts = data.enabled;
if (action === "remove_service") services.splice(index, 1);
if (action === "add_service") {
const item = catalog.find((entry) => entry.id === data.catalog_id);
services.push({id:item?.id || crypto.randomUUID(), name:item?.name || data.name,status:"unknown",signal:"Checks only", history:[]});
}
},
};
</script>
</html>