homecontrol-control-base/ControlBase.js

53 lines
1011 B
JavaScript

const { EventEmitter } = require('events');
const BaseState = require('./states/BaseState');
class HCControlBase extends EventEmitter {
/**
* @param {Object} configuration
* @param {BaseState} state
*/
constructor(configuration, state) {
super();
if (!configuration.name) throw new Error("Device name is missing");
this._configuration = configuration;
this._state = state;
this._name = this._configuration.name;
}
static get _is_homecontrol_control() {
return true;
}
get state() {
return this._state.clone();
}
get type() {
return "none";
}
get name() {
return this._name;
}
/**
* Run some sort of asynchronous initialization
* @returns A promise which resolves when the initialization is complete
*/
init() {
return Promise.resolve();
}
/**
* Updates the state by polling the controlled device
* @returns A promise which resolves when the state has been pulled
*/
pullState() {
return Promise.resolve();
}
}
module.exports = HCControlBase;