ucentral-state: properly track online state

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2023-12-05 17:13:38 +01:00
parent 6872bd6964
commit 6d4788c26f

View File

@@ -18,6 +18,7 @@ let ubus = libubus.connect();
let uci = libuci.cursor();
let config;
let offline_timer;
let current_state;
function self_healing() {
@@ -74,8 +75,9 @@ function offline_handler() {
function online_handler() {
ulog(LOG_INFO, 'going online\n');
ubus.call('network.interface.admin_ui', 'down');
if (offline_timer)
if (offline_timer) {
offline_timer.cancel();
}
}
function config_load() {
@@ -175,8 +177,11 @@ let state_handler = {
let ubus_methods = {
set: {
call: function(req) {
if (current_state == req.args.state)
return;
if (!state_handler[req.args.state])
return ubus.STATUS_INVALID_ARGUMENT;
current_state = req.args.state;
blink_timeout();
ulog(LOG_INFO, 'set state -> ' + req.args.state + '\n');