in bots/src/bot/core.js [91:140]
updateState: function (props, logger) {
const version = props.version;
const status = props.status;
const batteryLife = props.batteryLife
// Check if there is a status change needed
if(status === Constants.OFF_STATUS) return ;
if(props.startWorkRequested) {
logger.info(`bot-status-change from ${status} to ${Constants.WORKING_STATUS}`);
props.status = Constants.WORKING_STATUS;
props.startWorkRequested = false;
}
if(props.standByRequested) {
logger.info(`bot-status-change from ${status} to ${Constants.STANDBY_STATUS}`);
props.status = Constants.STANDBY_STATUS;
props.standByRequested = false;
}
else if (status === Constants.WORKING_STATUS && batteryLife <= DEFAULT_CHARGING_THRESHOLD && props.autoChargingEnabled === true) {
props.status = Constants.CHARGING_STATUS;
logger.info(`bot-status-change from ${status} to ${Constants.CHARGING_STATUS}`);
return;
} else if(status === Constants.CHARGING_STATUS && batteryLife >= MAX_BATTERY_LIVE) {
props.status = Constants.WORKING_STATUS;
logger.info(`bot-status-change from ${status} to ${Constants.WORKING_STATUS}`);
return;
}
// Update batteryLife value
var delta = getDelta(version, status, 1);
var newValue = props.batteryLife + delta;
if (newValue > MAX_BATTERY_LIVE) {
newValue = MAX_BATTERY_LIVE;
} else if (newValue < MIN_BATTERY_LIFE) {
newValue = MIN_BATTERY_LIFE;
}
props.batteryLife = Number(newValue.toFixed(6));
telemetryData = {
recorded_at: Date.now(),
version: version,
status: status,
batteryLife: batteryLife
}
if (version === OLD_VERSION) { // just send 1 sec of data
cache.recordTelemetry(telemetryData, 1);
} else { // send up to 2 mins of data
cache.recordTelemetry(telemetryData);
}
},