'use strict';
/**
* @class
* @description The base class of all responses.
*/
class Response {
/**
* @param {Buffer} data The received data used to build this Resopnse
*/
constructor(data) {
this._data = data;
}
/**
* @description The adapter instance
* @type {Adapter}
*/
set adapter(adapter) {
this._adapter = adapter;
}
get adapter() {
return this._adapter;
}
/**
* @description The device the command was sent to
* @type {Device}
*/
set device(device) {
this._device = device;
}
get device() {
return this._device;
}
/**
* @description The transport address
* @type {Object}
*/
set address(address) {
this._address = address;
}
get address() {
return this._address;
}
/**
* @description Returns an instance of the response class if the class can parse the data
* @param {Buffer} data The data received
* @param {Adapter} adapter The adapter instance
* @returns {Response|null}
* @static
*/
static fromData(data, adapter) {
throw new Error('Must be implemented by subclass!');
}
/**
* @description Returns the value to be set on the K4Model variable
* @type {String|Number|Boolean}
*/
get value() {
throw new Error('Must be implemented by subclass!');
}
/**
* @description Parses the data from this._data
* @abstract
*/
init() {
throw new Error('Must be implemented by subclass!');
}
/**
* @description Returns the name of the reponse. Used to match the adapter opts.
* @type {String}
*/
get name() {
throw new Error('Must be implemented by subclass!');
}
};
module.exports = Response;