-
Notifications
You must be signed in to change notification settings - Fork 1
/
hue-callionica-data.html
89 lines (78 loc) · 3.18 KB
/
hue-callionica-data.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
<!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 Data</title>
<script type="module">
import { hueToHtml } from "./hue-json-to-html.js";
import { loadCurrentBridge, loadConnection } from "./hue-callionica-connect.js";
import { getAllCategories, getCapabilities, getSceneComplete, Address, put } from "./hue-callionica.js";
function ancestorData(e, name) {
const attr = "data-" + name;
let container = e.parentNode;
while (container) {
if (container.hasAttribute(attr)) {
break;
}
container = container.parentElement;
}
return container?.getAttribute(attr) || undefined;
}
async function main() {
const params = new URLSearchParams(document.location.search);
const scenes = params.get("scenes")?.toLocaleLowerCase().trim();
const bridge = loadCurrentBridge();
const connection = await loadConnection("Callionica", bridge);
const data = await getAllCategories(connection);
data.capabilities = await getCapabilities(connection);
const showScenes = scenes !== "false";
if (showScenes) {
document.title = "Hue Data + Scenes";
for (const [id, scene] of Object.entries(data.scenes)) {
const completeScene = await getSceneComplete(connection, id, scene.lastupdated);
scene.lightstates = completeScene.lightstates;
}
}
const html = hueToHtml(data);
document.getElementById("data").innerHTML = html;
const controls = [...document.querySelectorAll("select[data-address][data-property]")];
// console.log(controls);
controls.map(control => {
control.onchange = (evt) => {
const address = Address(connection, control.dataset.address);
let value = control.value;
if (value === "true") {
value = true;
} else if (value === "false") {
value = false;
} else if (value === "undefined") {
value = undefined;
}
const body = JSON.parse(ancestorData(control, "light-value"));
if (value !== undefined) {
body[control.dataset.property] = value;
} else {
delete body[control.dataset.property];
}
put(address, body);
};
});
}
main().then(x => {
if (document.location.hash.length > 0) {
document.querySelector(document.location.hash)?.scrollIntoView();
}
});
</script>
<style>
a.action {
color: red;
}
</style>
</head>
<body>
<pre id="data"></pre>
</body>
</html>