feat: HA event handling + emitting
This commit is contained in:
@@ -95,7 +95,7 @@ module.exports = {
|
||||
* @param {Array} keys Array of keys to save
|
||||
* @returns Promise
|
||||
*/
|
||||
async saveToDb(keys) {
|
||||
async saveToDb(keys, propagate = true) {
|
||||
try {
|
||||
for (let key of keys) {
|
||||
let value = _.get(WIKI.config, key, null)
|
||||
@@ -107,6 +107,9 @@ module.exports = {
|
||||
await WIKI.models.settings.query().insert({ key, value })
|
||||
}
|
||||
}
|
||||
if (propagate) {
|
||||
WIKI.events.outbound.emit('reloadConfig')
|
||||
}
|
||||
} catch (err) {
|
||||
WIKI.logger.error(`Failed to save configuration to DB: ${err.message}`)
|
||||
return false
|
||||
@@ -119,5 +122,15 @@ module.exports = {
|
||||
*/
|
||||
async applyFlags() {
|
||||
WIKI.models.knex.client.config.debug = WIKI.config.flags.sqllog
|
||||
},
|
||||
|
||||
/**
|
||||
* Subscribe to HA propagation events
|
||||
*/
|
||||
subscribeToEvents() {
|
||||
WIKI.events.inbound.on('reloadConfig', async () => {
|
||||
await WIKI.configSvc.loadFromDb()
|
||||
await WIKI.configSvc.applyFlags()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user