From decad7a9cc03147d605ad52dad9d6118737db4f7 Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Fri, 10 May 2024 16:18:12 +0200 Subject: [PATCH] feat: add resources --- app/lib/api/v2/hue-api-v2.ts | 5 +++++ app/lib/app.ts | 7 +++++++ app/lib/logger.ts | 3 +++ app/lib/state/state-manager.ts | 5 ++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/lib/api/v2/hue-api-v2.ts b/app/lib/api/v2/hue-api-v2.ts index 424ed997..47a92bb0 100644 --- a/app/lib/api/v2/hue-api-v2.ts +++ b/app/lib/api/v2/hue-api-v2.ts @@ -110,6 +110,11 @@ export const loadDevices: () => Promise> | undefined = async () = return load("resource/device") } +export const loadAllResources: () => Promise> | undefined = async () => { + return load("resource") +} + + export const loadTyped: (resourceName: string) => Promise> | undefined = async (resourceName: string) => { return load(`resource/${resourceName}`) } diff --git a/app/lib/app.ts b/app/lib/app.ts index cf54f477..c382653d 100644 --- a/app/lib/app.ts +++ b/app/lib/app.ts @@ -3,6 +3,7 @@ import { destroySSE, initSSE } from "./SSEClient" import { log } from "./logger" import cron from "node-cron" import { initStateManagerFromHue } from "./state/state-manager" +import { loadAllResources } from "./api/v2/hue-api-v2" export const triggerFullUpdate = async () => { log.info("Updating devices") @@ -14,6 +15,12 @@ export const startApp = async () => { const mqttCleanUp = await connectMqtt() await triggerFullUpdate() + const level = log.level() + if (level === "DEBUG") { + let resources = await loadAllResources() + log.debug("All resources", JSON.stringify(resources)) + } + initSSE() log.info("Scheduling hourly-full-update.") diff --git a/app/lib/logger.ts b/app/lib/logger.ts index 4aee72db..4ede2e23 100755 --- a/app/lib/logger.ts +++ b/app/lib/logger.ts @@ -128,5 +128,8 @@ export const log = { on: () => { logger.silent = false }, + level: () => { + return logger.level + }, configure: (loglevel: string) => logger.configure(loggerConfig(loglevel)) } diff --git a/app/lib/state/state-manager.ts b/app/lib/state/state-manager.ts index 21cc9bf4..ccd5032a 100644 --- a/app/lib/state/state-manager.ts +++ b/app/lib/state/state-manager.ts @@ -99,7 +99,10 @@ export const initStateManagerFromHue = async () => { "relative_rotary", "temperature", "zgp_connectivity", - "zigbee_connectivity" + "zigbee_connectivity", + "grouped_motion", + "grouped_light_level", + "scene" ]) { const resources = await loadTyped(typeName) if (resources) {