-
Notifications
You must be signed in to change notification settings - Fork 1
/
hue-callionica-statistics.html
103 lines (86 loc) · 4.42 KB
/
hue-callionica-statistics.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hue Statistics</title>
<link rel="stylesheet" href="hue-callionica.css">
<style>
.limit {
color: lightgray;
}
.numeric {
text-align: right;
}
td:first-of-type {
padding: 0;
}
</style>
<script type="module">
import { loadCurrentBridge, loadConnection } from "./hue-callionica-connect.js";
import { sortBy, getAll, getCapabilities, getSensorTriggeredRules } from "./hue-callionica.js";
let bridge;
let connection;
async function main() {
bridge = loadCurrentBridge();
connection = await loadConnection("Callionica", bridge);
const data = await getAll(connection);
const capabilities = await getCapabilities(connection);
const o = {};
["sensors", "components", "rules", "schedules", "groups", "lights", "scenes"].forEach(n => o[n] = Object.values(data[n]));
const counts = [
// ["Sensors", () => o.sensors.length, capabilities.sensors.total],
["Hardware sensors", () => (capabilities.sensors.zll.total - capabilities.sensors.zll.available), capabilities.sensors.zll.total],
["Software sensors", () => (capabilities.sensors.clip.total - capabilities.sensors.clip.available), capabilities.sensors.clip.total],
["Rules", () => o.rules.length, capabilities.rules.total],
["Conditions", () => o.rules.reduce((p, c) => p + c.conditions.length, 0), capabilities.rules.conditions.total],
["Actions", () => o.rules.reduce((p, c) => p + c.actions.length, 0), capabilities.rules.actions.total],
["Schedules", () => o.schedules.length, capabilities.schedules.total],
["Lights", () => o.lights.length, capabilities.lights.total],
["Scenes", () => o.scenes.length, capabilities.scenes.total],
["Groups", () => o.groups.length, capabilities.groups.total],
["Rooms", () => o.groups.filter(group => group.type === "Room").length],
["Zones", () => o.groups.filter(group => group.type === "Zone").length],
["Passwords", () => Object.values(data.config.whitelist).length],
["Switches", () => o.sensors.filter(sensor => sensor.type === "ZLLSwitch").length],
["Motion sensors", () => o.sensors.filter(sensor => sensor.type === "ZLLPresence").length],
["Temperature sensors", () => o.sensors.filter(sensor => sensor.type === "ZLLTemperature").length],
["Light level sensors", () => o.sensors.filter(sensor => sensor.type === "ZLLLightLevel").length],
["Components", () => o.components.length],
];
const html = `<h1>${connection.bridge.name}</h1>
<h2>Statistics</h2>
<table>`
+ counts.map(count => `<tr><td>${count[0]}</td><td class="numeric">${count[1]()}</td><td>${count[2] ? "<span class='limit'> of " + count[2] + "</span>" : ""}</td></tr>`).join("\n")
+ `</table>`
;
document.getElementById("statistics").innerHTML = html;
}
async function _main() {
try {
await main();
delete document.body.dataset.showConnection;
// setTimeout(()=> _main(), 60*1000);
} catch (error) {
document.body.dataset.showConnection = true;
const e = document.querySelector("#connection");
if ((bridge === undefined) || (connection === undefined)) {
e.innerHTML = `<a href="hue-callionica-connect.html">Connect to your Hue bridge</a>`;
} else {
e.innerHTML = `<a href="https://${connection.bridge.ip}/api/unauthenticated/config">Refresh your Hue bridge connection</a>`;
}
setTimeout(()=> _main(), 3*1000);
}
}
_main().then(x => console.log("Done"));
</script>
</head>
<body>
<h1>Hue Statistics</h1>
<p>Here you can see the number of items on the current Hue bridge.</p>
<hr/>
<div id="connection"></div>
<div id="statistics"></div>
</body>
</html>