domoticz-api-linker
Version:
Domoticz API Javascript Bridge Connector
82 lines (81 loc) • 2.32 kB
JavaScript
import { DOMOTICZ_COMMAND_PARAM } from '../enums/DomoticzCommandParam';
class SystemManager {
domoticzApi;
constructor(domoticzApi) {
this.domoticzApi = domoticzApi;
}
/**
* Write a message into Domoticz Logs
* @param {String} message
*/
async log(message) {
return await this.domoticzApi.command({
param: DOMOTICZ_COMMAND_PARAM.ADD_LOG_MESSAGE,
message: `DOMOTICZ API : ${message}`
});
}
/**
* Check Credentials
*/
async checkCredentials() {
try {
await this.domoticzApi.checkCredentials();
return true;
}
catch (e) {
return false;
}
}
async uptime() {
const device = await this.domoticzApi.command({
param: DOMOTICZ_COMMAND_PARAM.GET_UPTIME
});
if (((device?.result) != null) && device.result !== undefined && device.result?.length > 0) {
return device.result;
}
return null;
}
/**
* Check Security Status
*/
async securityStatus() {
return await this.domoticzApi.command({ param: DOMOTICZ_COMMAND_PARAM.GET_SECURITY_STATUS });
}
/**
* Get various informations about the Domoticz Server
*/
async version() {
return await this.domoticzApi.command({ param: DOMOTICZ_COMMAND_PARAM.GET_VERSION });
}
/**
* Get times (Local time, Sunset, Sunrise, etc.) from Domoticz Server
*/
async datetimes() {
return await this.domoticzApi.command({ param: DOMOTICZ_COMMAND_PARAM.GET_SUNRISE_SUNSET });
}
/**
* Reboot Domoticz Server
*/
async reboot() {
return await this.domoticzApi.command({ param: DOMOTICZ_COMMAND_PARAM.SYSTEM_REBOOT });
}
/**
* Shutdown the Domoticz Server
*/
async shutdown() {
return await this.domoticzApi.command({ param: DOMOTICZ_COMMAND_PARAM.SYSTEM_SHUTDOWN });
}
/**
* Start Database backup
*/
async db_backup() {
return await this.domoticzApi.get('backupdatabase.php');
}
/**
* Execute database cleanup
*/
async db_vaccum() {
return await this.domoticzApi.command({ param: DOMOTICZ_COMMAND_PARAM.VACCUM_DATABASE });
}
}
export { SystemManager };