mirror of
https://github.com/outbackdingo/sysadm.git
synced 2026-01-27 10:20:26 +00:00
Add new API call for batteryinfo
Will return battery:"true/false" if one exists
If one exists, it will also return "level":"1-99"
and "status":"offline/charging/backup/unknown"
REST Request:
-------------------------------
PUT /sysadm/systeminfo
{
"action" : "batteryinfo"
}
REST Response:
-------------------------------
{
"args": {
"batteryinfo": {
"battery": "false"
}
}
}
WebSocket Request:
-------------------------------
{
"namespace" : "sysadm",
"name" : "systeminfo",
"id" : "fooid",
"args" : {
"action" : "batteryinfo"
}
}
WebSocket Response:
-------------------------------
{
"args": {
"batteryinfo": {
"battery": "false"
}
},
"id": "fooid",
"name": "response",
"namespace": "sysadm"
}
This commit is contained in:
@@ -12,8 +12,42 @@ using namespace sysadm;
|
||||
|
||||
//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h
|
||||
|
||||
|
||||
//Battery Availability
|
||||
QJsonObject SysInfo::batteryInfo(){
|
||||
QJsonObject retObject;
|
||||
bool ok;
|
||||
|
||||
int val = General::RunCommand("apm -l").toInt(&ok);
|
||||
if ( ok && (val >= 0 && val <= 100) ) {
|
||||
retObject.insert("battery", "true");
|
||||
} else {
|
||||
retObject.insert("battery", "false");
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// We have a battery, return info about it
|
||||
//Battery Charge Level
|
||||
QString tmp;
|
||||
tmp.setNum(val);
|
||||
retObject.insert("level", tmp);
|
||||
|
||||
//Battery Charging State
|
||||
int state = General::RunCommand("apm -a").toInt(&ok);
|
||||
if ( ok && state == 0 )
|
||||
retObject.insert("status", "offline");
|
||||
else if ( ok && state == 1 )
|
||||
retObject.insert("status", "charging");
|
||||
else if ( ok && state == 2 )
|
||||
retObject.insert("status", "backup");
|
||||
else
|
||||
retObject.insert("status", "unknown");
|
||||
|
||||
return retObject;
|
||||
}
|
||||
|
||||
// ==== ExternalDevicePaths() ====
|
||||
QJsonObject SysInfo::ExternalDevicePaths() {
|
||||
QJsonObject SysInfo::externalDevicePaths() {
|
||||
QJsonObject retObject;
|
||||
|
||||
//Returns: QStringList[<type>::::<filesystem>::::<path>]
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace sysadm{
|
||||
|
||||
class SysInfo{
|
||||
public:
|
||||
static QJsonObject ExternalDevicePaths();
|
||||
static QJsonObject batteryInfo();
|
||||
static QJsonObject externalDevicePaths();
|
||||
};
|
||||
|
||||
} //end of pcbsd namespace
|
||||
|
||||
@@ -257,7 +257,11 @@ RestOutputStruct::ExitCode WebSocket::EvaluateSysadmSystemInfoRequest(const QJso
|
||||
QString act = JsonValueToString(in_args.toObject().value("action"));
|
||||
if(act=="externalmounts"){
|
||||
ok = true;
|
||||
out->insert("externalmounts", sysadm::SysInfo::ExternalDevicePaths());
|
||||
out->insert("externalmounts", sysadm::SysInfo::externalDevicePaths());
|
||||
}
|
||||
if(act=="batteryinfo"){
|
||||
ok = true;
|
||||
out->insert("batteryinfo", sysadm::SysInfo::batteryInfo());
|
||||
}
|
||||
|
||||
} //end of "action" key usage
|
||||
|
||||
Reference in New Issue
Block a user