Skip to content

Commit

Permalink
feat: add resources
Browse files Browse the repository at this point in the history
  • Loading branch information
philipparndt committed May 10, 2024
1 parent 20575dd commit decad7a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/lib/api/v2/hue-api-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export const loadDevices: () => Promise<Result<Device>> | undefined = async () =
return load("resource/device")
}

export const loadAllResources: () => Promise<Result<Device>> | undefined = async () => {
return load("resource")
}


Check failure on line 117 in app/lib/api/v2/hue-api-v2.ts

View workflow job for this annotation

GitHub Actions / build

More than 1 blank line not allowed
export const loadTyped: (resourceName: string) => Promise<Result<HueIdentifiable>> | undefined = async (resourceName: string) => {
return load(`resource/${resourceName}`)
}
Expand Down
7 changes: 7 additions & 0 deletions app/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()

Check failure on line 20 in app/lib/app.ts

View workflow job for this annotation

GitHub Actions / build

'resources' is never reassigned. Use 'const' instead
log.debug("All resources", JSON.stringify(resources))
}

initSSE()

log.info("Scheduling hourly-full-update.")
Expand Down
3 changes: 3 additions & 0 deletions app/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@ export const log = {
on: () => {
logger.silent = false
},
level: () => {
return logger.level
},
configure: (loglevel: string) => logger.configure(loggerConfig(loglevel))
}
5 changes: 4 additions & 1 deletion app/lib/state/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit decad7a

Please sign in to comment.