UNPKG

@growbox/sensors

Version:

An abstraction layer for a selection of raspberry-compatible sensors

51 lines (41 loc) 1.12 kB
/** * @author nstCactus * @date 05/12/2017 13:47 */ /** {WeakMap<string>} The human-readable name of the sensor */ const _name = new WeakMap(); /** {WeakMap<string>} A unique identifier for the sensor */ const _uid = new WeakMap(); /** * An abstract class to represent a sensor */ class AbstractSensor { /** * Constructs a new instance * @param {string} name The name of the sensor * @param {string} uid The unique identifier of the sensor */ constructor(name, uid) { if (this.constructor === AbstractSensor) { throw new TypeError('Abstract class "AbstractSensor" cannot be instantiated directly.'); } if (this.read === undefined) { throw new TypeError('Classes extending the "AbstractSensor" abstract class must implement the "read" method.'); } _name.set(this, name); _uid.set(this, uid); } /** * @returns {string} the name of the sensor */ get name() { return _name.get(this); } /** * @returns {string} the unique identifier (UID) of the sensor */ get uid() { return _uid.get(this); } } module.exports = AbstractSensor;