-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c73b626
commit 425ce92
Showing
1 changed file
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/*! resol-vbus | Copyright (c) 2013-2014, Daniel Wippermann | MIT license */ | ||
'use strict'; | ||
|
||
|
||
|
||
var EventEmitter = require('events').EventEmitter; | ||
|
||
|
||
var _ = require('lodash'); | ||
var Q = require('q'); | ||
|
||
|
||
var ConfigurationOptimizer = require('./configuration-optimizer'); | ||
var utils = require('./utils'); | ||
|
||
var extend = require('./extend'); | ||
|
||
|
||
|
||
var optionKeys = [ | ||
'id', | ||
'deviceAddress', | ||
'optimizer', | ||
]; | ||
|
||
|
||
|
||
var Customizer = extend(EventEmitter, /** @lends Customizer# */ { | ||
|
||
/** | ||
* An identifier for this customizer. | ||
* @type {string} | ||
*/ | ||
id: null, | ||
|
||
/** | ||
* The VBus address of the device to customize. | ||
* @type {number} | ||
*/ | ||
deviceAddress: 0, | ||
|
||
/** | ||
* A configuration optimizer. | ||
* @type {ConfigurationOptimizer} | ||
*/ | ||
optimizer: null, | ||
|
||
/** | ||
* Creates a new Customizer instance and optionally initializes its members | ||
* with the given values. | ||
* | ||
* @constructs | ||
* @param {object} [options] Initialization values for this instance's members | ||
* @param {string} [options.id] {@link Customizer#id} | ||
* @param {string} [options.deviceAddress] {@link Customizer#deviceAddress} | ||
* @param {string} [options.optimizer] {@link Customizer#optimizer} | ||
* | ||
* @classdesc | ||
* A Customizer provides functionality to transfer a set of configuration | ||
* values from or to a device. | ||
*/ | ||
constructor: function(options) { | ||
EventEmitter.call(this); | ||
|
||
_.extend(this, _.pick(options, optionKeys)); | ||
|
||
if (!this._optimizer) { | ||
this._optimizer = new ConfigurationOptimizer(this.deviceAddress); | ||
} | ||
}, | ||
|
||
/** | ||
* Load a set of configuration values from a device. | ||
*/ | ||
loadConfiguration: function() { | ||
throw new Error('Must be implemented by sub-class'); | ||
}, | ||
|
||
/** | ||
* Save a set of configuration values to a device. | ||
*/ | ||
saveConfiguration: function(configuration) { | ||
throw new Error('Must be implemented by sub-class'); | ||
}, | ||
|
||
_getInitialConfiguration: function(oldConfig) { | ||
return this._optimizer.getInitialConfiguration(oldConfig); | ||
}, | ||
|
||
_optimizeConfiguration: function(oldConfig) { | ||
return this._optimizer.optimizeConfiguration(oldConfig); | ||
}, | ||
|
||
}); | ||
|
||
|
||
|
||
module.exports = Customizer; |