-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhue-callionica-sensor-rules.html
130 lines (111 loc) · 5.05 KB
/
hue-callionica-sensor-rules.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!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 Sensor Rules</title>
<link rel="stylesheet" href="hue-callionica.css">
<style>
tr[data-external='true'] {
color: gray;
}
</style>
<script type="module">
import { loadCurrentBridge, loadConnection } from "./hue-callionica-connect.js";
import { sortBy, getAll, getCapabilities, getSensorTriggeredRules, getSensorConditionRules, getSensorUpdatingRules, getSensorUpdatingSchedules } from "./hue-callionica.js";
let bridge;
function sensorCategory(sensor) {
if (sensor.metadata) {
return "components";
}
if (sensor.type === "ZLLSwitch") {
return "switches";
}
return "other";
}
function sensorKind(sensor) {
if (sensor.metadata) {
return `${sensor.metadata.component} > ${sensor.metadata.property}`.replaceAll(">", "›");
}
return sensor.productname || sensor.modelid;
}
function sensorStats(data) {
const rules = Object.values(data.rules);
const schedules = Object.values(data.schedules);
const result = {
switches: [],
components: [],
other: [],
};
for (const sensor of Object.values(data.sensors)) {
const category = sensorCategory(sensor);
const o = {
...sensor,
kind: sensorKind(sensor),
rules: getSensorTriggeredRules(rules, sensor.id),
conditionRules: getSensorConditionRules(rules, sensor.id),
updatingRules: getSensorUpdatingRules(rules, sensor.id),
updatingSchedules: getSensorUpdatingSchedules(schedules, sensor.id),
};
result[category].push(o);
}
result.components = result.components.sort(sortBy(s => s.component.name + s.kind + s.component.id));
result.switches = result.switches.sort(sortBy(s => s.name));
result.other = result.other.sort(sortBy(s => s.name));
return result;
}
function mf(name) {
if (name.startsWith("Signify")) {
return "Signify";
}
if (name.startsWith("IKEA")) {
return "IKEA";
}
return name;
}
function sensorHTML(sensor) {
const external =
(sensor.conditionRules.length === 0) &&
(sensor.updatingRules.length === 0) &&
(sensor.updatingSchedules.length === 0);
return `
<tr data-external="${external}" title="ID: ${sensor.id}; Conditions: ${sensor.conditionRules.length} rules; Updates: ${sensor.updatingRules.length} rules, ${sensor.updatingSchedules.length} schedules;"><td>${sensor.name}</td><td>${sensor.kind}</td><td>${mf(sensor.manufacturername)}</td><td style="text-align: right;">${sensor.rules.length}</td><td><a href="hue-callionica-data.html#sensors-${sensor.id}">➲</a><a href="hue-callionica-sensor.html?bridge=${bridge.id}&sensor=${sensor.id}">➲</a></tr>
`;
}
function componentSensorHTML(data, sensor) {
const name = sensor.component?.name || sensor.name;
return `
<tr title="ID: ${sensor.id}; Conditions: ${sensor.conditionRules.length} rules; Updates: ${sensor.updatingRules.length} rules, ${sensor.updatingSchedules.length} schedules;"><td>${name}</td><td>${sensor.kind}</td><td style="text-align: right;">${sensor.rules.length}</td><td><a href="hue-callionica-components.html#components-${sensor.component.id}">➲</a><a href="hue-callionica-sensor.html?bridge=${bridge.id}&sensor=${sensor.id}">➲</a></td></tr>
`;
}
function sensorStatsHTML(data, stats) {
return `
<h3>Component Sensors</h3>
<table>
${stats.components.map(sensor => componentSensorHTML(data, sensor)).join("\n")}
</table>
<h3>Switches & Other Sensors</h3>
<table>
${stats.switches.map(sensorHTML).join("\n")}
${stats.other.map(sensorHTML).join("\n")}
</table>
`;
}
async function main() {
bridge = loadCurrentBridge();
const connection = await loadConnection("Callionica", bridge);
const data = await getAll(connection);
const html = sensorStatsHTML(data, sensorStats(data));
document.getElementById("statistics").innerHTML = html;
}
main().then(x => console.log("Done"));
</script>
</head>
<body>
<h1>Hue Sensor Rules</h1>
<p>Here you can see the number of rules triggered by each sensor.</p>
<hr/>
<div id="statistics"></div>
</body>
</html>