aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAutumn <git@autumnfo.rest>2026-05-12 18:51:33 +0100
committerAutumn <git@autumnfo.rest>2026-05-12 18:51:33 +0100
commit57bdd284666dd2139ffa00b28745be9a7520278d (patch)
tree339552a3827a78731f1cd56ced93be8947bc0766 /src/lib
parenta8addc5aaaecca292b7d2bdc3a848a795329a3b4 (diff)
[config] added action types
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/config/actions.ts32
-rw-r--r--src/lib/config/actions.types.ts57
2 files changed, 89 insertions, 0 deletions
diff --git a/src/lib/config/actions.ts b/src/lib/config/actions.ts
new file mode 100644
index 0000000..2a60ce0
--- /dev/null
+++ b/src/lib/config/actions.ts
@@ -0,0 +1,32 @@
+//
+// ~~~ action configs
+//
+
+// imports
+import { readFileSync } from "node:fs"
+
+import type ActionsConfig from "@lib/config/actionss.types.ts"
+
+// load config
+const configFile = "data/actions.json"
+let actionsConfig: ActionsConfig = {}
+
+try {
+ actionsConfig = JSON.parse(readFileSync(configFile, "utf8"))
+} catch(e) {
+ console.error("!> cannot read actions config")
+}
+
+// get all actions
+const allActions = Object.keys(actionsConfig).map((action) => {
+
+ const actionInfo = actionsConfig[action]
+
+ return {
+ ...actionInfo,
+ id: action
+ }
+
+})
+
+export default allActions
diff --git a/src/lib/config/actions.types.ts b/src/lib/config/actions.types.ts
new file mode 100644
index 0000000..83d58a5
--- /dev/null
+++ b/src/lib/config/actions.types.ts
@@ -0,0 +1,57 @@
+//
+// ~~~ action config types
+//
+
+
+// action "on" actions
+export enum ACTION_ON_ACTION {
+ PRESS = "press"
+ MOTION = "motion"
+}
+
+// action "on" type
+export interface ActionOnType {
+ device: string,
+ action: ACTION_ON_ACTION
+}
+
+// action "if" types
+export enum ACTION_IF_TYPE {
+ ALL = "all"
+ ANY = "any"
+}
+
+// action "if" status
+export enum ACTION_IF_STATUS {
+ ON = "on"
+ OFF = "off"
+ TOGGLE = "toggle"
+}
+
+// action "if" type
+export interface ActionIfType {
+ device: string,
+ status: ACTION_IF_STATUS
+}
+
+// action "do" actions
+export enum ACTION_DO_ACTION {
+ ON = "on"
+ OFF = "off"
+ TOGGLE = "toggle"
+}
+
+// action "do" type
+export interface ActionDoType {
+ device: string,
+ action: ACTION_DO_ACTION
+}
+
+// global action config
+export default interface ActionsConfig {
+ name: string,
+ on: ActionOnType
+ ifType?: ACTION_IF_TYPE,
+ if?: ActionIfType,
+ do: ActionDoType[]
+}