From 57bdd284666dd2139ffa00b28745be9a7520278d Mon Sep 17 00:00:00 2001 From: Autumn Date: Tue, 12 May 2026 18:51:33 +0100 Subject: [config] added action types --- src/lib/config/actions.ts | 32 +++++++++++++++++++++++ src/lib/config/actions.types.ts | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/lib/config/actions.ts create mode 100644 src/lib/config/actions.types.ts 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[] +} -- cgit v1.3