trigger editor

This commit is contained in:
2023-10-12 23:27:04 +02:00
parent e06cf1ae34
commit 16e5726cbc
15 changed files with 410 additions and 45 deletions
+27 -5
View File
@@ -18,6 +18,7 @@
deviceList: Readable<Device[]>
assignmentList: Readable<Assignment[]>
roomList: Readable<{name: string, groups: {name: string, devices: Device[]}[], devices: Device[]}[]>
maskList: Readable<string[]>
}
export function getStateContext(): StateContextData {
@@ -30,6 +31,7 @@
assignments: {},
devices: {},
scripts: {},
triggers: {},
});
const error = writable<string | null>(null);
@@ -45,6 +47,13 @@
.sort((a,b) => a.name.localeCompare(b.name));
});
const maskList = derived(state, state => {
return Object.keys(state.devices)
.flatMap(k => state.devices[k].aliases.filter(a => ["tag", "room", "role", "name"].find(p => a.startsWith(`lucifer:${p}:`))))
.sort()
.filter((e, i, a) => a[i - 1] !== e)
});
const assignmentList = derived(state, state => {
if (state == null) {
return [];
@@ -55,7 +64,6 @@
.sort((a,b) => a.id.localeCompare(b.id));
});
const roomList = derived(state, state => {
const roomMap: Record<string, Device[]> = {};
const groupMap: Record<string, string> = {};
@@ -132,8 +140,8 @@
}
state.devices = {...state.devices}
if (patch.devices[deviceId] != null) {
state.devices[deviceId] = patch.devices[deviceId]
if (patch.devices[deviceId] !== null) {
state.devices[deviceId] = patch.devices[deviceId]!
} else {
delete state.devices[deviceId]
}
@@ -146,7 +154,7 @@
state.assignments = {...state.assignments}
if (patch.assignments[assignmentId] != null) {
state.assignments[assignmentId] = patch.assignments[assignmentId]
state.assignments[assignmentId] = patch.assignments[assignmentId]!
} else {
delete state.assignments[assignmentId]
}
@@ -159,12 +167,25 @@
state.scripts = {...state.scripts}
if (patch.scripts[scriptName] != null) {
state.scripts[scriptName] = patch.scripts[scriptName]
state.scripts[scriptName] = patch.scripts[scriptName]!
} else {
delete state.scripts[scriptName]
}
}
for (const triggerId in patch.triggers) {
if (!patch.triggers.hasOwnProperty(triggerId)) {
continue
}
state.triggers = {...state.triggers}
if (patch.triggers[triggerId] != null) {
state.triggers[triggerId] = patch.triggers[triggerId]!
} else {
delete state.triggers[triggerId]
}
}
return state;
})
}
@@ -214,6 +235,7 @@
deviceList,
assignmentList,
roomList,
maskList,
});
</script>