Fix daemon auto-start, refine logging

This commit is contained in:
Edward Brown 2023-08-31 15:18:27 +01:00
parent d5cd659e90
commit d3242fd546
3 changed files with 35 additions and 10 deletions

View file

@ -2,10 +2,17 @@ import tools, string, json, mqtt
var mod = module("haco")
var logger=tools.logger.logger
import haco_version
logger.level=4
logger.log_repl=true
var IS_DEVELOPMENT=haco_version.CHANNEL_ID=='development'
var logger=tools.logging.Logger(
'haco',
IS_DEVELOPMENT?tools.logging.Logger.DEBUG_MORE:tools.logging.Logger.INFO,
IS_DEVELOPMENT
)
tools.logger.logger=logger
var CALLBACK_MAP={}
var BRANCH='release'
@ -40,16 +47,18 @@ class ConfigDownloader
if self.id_downloading && self.id_downloading==id
logger.error(string.format("Got duplicate new config (same as currently being downloaded) ID: %s. Will be ignored.",id))
logger.debug(string.format("Got duplicate new config (same as currently being downloaded) ID: %s. Will be ignored.",id))
return
end
logger.debug(string.format("Received new config. ID: %s. Parts: %s",id,num_parts))
if self.id_downloading
logger.error(string.format("Got new config ID: %s while existing download ID: %s incomplete.",id,self.id_downloading))
end
logger.info(string.format("Downloading new config. ID: %s. Parts: %s",id,num_parts))
self.id_downloading=id
logger.debug(['Cancelling any existing downloads...'])
@ -164,7 +173,7 @@ class Daemon
def init()
logger.info(['Starting haco daemon...'])
logger.info(string.format('Starting haco daemon in %s seconds...', self.DELAY_SUBSCRIBE))
self.registry_daemon=tools.callbacks.Registry()
self.registry_config=tools.callbacks.Registry()
@ -189,6 +198,8 @@ class Daemon
if mqtt.connected() self.publish_announce() end
logger.info(string.format('haco daemon has started.', self.DELAY_SUBSCRIBE))
end
def handle_config_message(data)
@ -258,7 +269,7 @@ class Daemon
self.config_id=id
self.publish_announce()
logger.info(string.format('New config ID %s applied.',id))
logger.info(string.format('New config ID %s applied successfully.',id))
end
@ -315,8 +326,7 @@ class Daemon
end
mod.daemon=Daemon()
mod.Daemon=Daemon
mod.daemon=nil
return mod

12
berry/haco_autoexec.be Normal file
View file

@ -0,0 +1,12 @@
def autoexec(metadata)
import haco
global.haco=haco
haco.daemon=haco.Daemon()
end
var mod = module("haco_autoexec")
mod.autoexec=autoexec
return mod

View file

@ -2,4 +2,7 @@ var VERSION='0.0.9'
var mod = module("haco_version")
mod.VERSION=VERSION
mod.METADATA=(global.TAPP_METADATA!=nil?global.TAPP_METADATA:{}).find('haco',{})
mod.CHANNEL_ID=mod.METADATA.find('channel_id')
return mod