domoticz-api-linker
Version:
Domoticz API Javascript Bridge Connector
41 lines (40 loc) • 1.15 kB
JavaScript
import { DOMOTICZ_SWITCHCMD } from '../enums/Domoticz';
import { DOMOTICZ_COMMAND_PARAM } from '../enums/DomoticzCommandParam';
class SceneManager {
domoticzApi;
constructor(domoticzApi) {
this.domoticzApi = domoticzApi;
}
/**
* Get all the Domoticz"s scenes
*/
async items() {
const scenes = await this.domoticzApi.scenes();
if (((scenes?.result) != null) && scenes.result !== undefined) {
return scenes.result;
}
return [];
}
/**
* Switch a state into a specific state
*
* @param {number} idx : Domoticz index of the device
* @param {DOMOTICZ_SWITCHCMD} command : string of the state, ex: 'Off'
*/
async switch(idx, command) {
return await this.domoticzApi.command({
param: DOMOTICZ_COMMAND_PARAM.SWITCH,
idx,
switchcmd: command
});
}
/**
* Toggle a device (ex: On/Off
*
* @param {number} idx : Domoticz index of the device
*/
async toggle(idx) {
return await this.switch(idx, DOMOTICZ_SWITCHCMD.TOGGLE);
}
}
export { SceneManager };