Skip to content

Commit

Permalink
Updating bootstrap to update
Browse files Browse the repository at this point in the history
  • Loading branch information
terafin committed Oct 7, 2024
1 parent c22acf2 commit 4a3a125
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 671 deletions.
14 changes: 14 additions & 0 deletions mqtt-unifi-protect-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ProtectApi } from "unifi-protect"
import util from "node:util"

import { default as mqtt } from "mqtt"
import { default as interval } from "interval-promise"
import { default as _ } from "lodash"
import { default as logging } from "homeautomation-js-lib/logging.js"
import { default as health } from "homeautomation-js-lib/health.js"
Expand All @@ -12,6 +13,7 @@ import { default as mqtt_helpers } from "homeautomation-js-lib/mqtt_helpers.js"
const username = process.env.USERNAME
const password = process.env.PASSWORD
var protectURL = process.env.PROTECT_URL
var bootstrapPollInterval = process.env.BOOTSTRAP_POLL_FREQUENCY

// TODO: Does this library handle this fully?
var authenticate_poll_time = process.env.AUTH_POLL_FREQUENCY
Expand Down Expand Up @@ -40,6 +42,10 @@ if (_.isNil(baseTopic)) {
process.abort()
}

if (_.isNil(bootstrapPollInterval)) {
bootstrapPollInterval = 60
}

if (_.startsWith(protectURL)) {
logging.warn('PROTECT_URL not set, not starting')
process.abort()
Expand Down Expand Up @@ -85,6 +91,14 @@ if (!(await ufp.getBootstrap())) {
process.exit(0)
}

const startBootstrapPoll = function () {
interval(async () => {
ufp.getBootstrap()
}, bootstrapPollInterval * 1000)
}

startBootstrapPoll()

ufp.on("message", (packet) => {
const action = packet.header.action
const model = packet.header.modelKey
Expand Down
Loading

0 comments on commit 4a3a125

Please sign in to comment.