UNPKG

barnowl-enocean

Version:

Collect ambient EnOcean Wireless Standard packets from EnOcean Serial Protocol (ESP) devices. We believe in an open Internet of Things.

51 lines (37 loc) 1.22 kB
/** * Copyright reelyActive 2022 * We believe in an open Internet of Things */ const DEFAULT_RADIO_DECODINGS_PERIOD_MILLISECONDS = 1000; const TEST_ORIGIN = 'test'; /** * TestListener Class * Provides a consistent stream of artificially generated ESP packets. */ class TestListener { /** * TestListener constructor * @param {Object} options The options as a JSON object. * @constructor */ constructor(options) { options = options || {}; this.decoder = options.decoder; this.radioDecodingPeriod = options.radioDecodingPeriod || DEFAULT_RADIO_DECODINGS_PERIOD_MILLISECONDS; this.decodingOptions = options.decodingOptions || {}; setInterval(emitRadioDecodings, this.radioDecodingPeriod, this); } } /** * Emit simulated radio decoding packets * @param {TestListener} instance The given instance. */ function emitRadioDecodings(instance) { let time = new Date().getTime(); let simulatedESPData = '55000f07012bd2ad98000c8c08f55a40041415598001ffffffff3a00fe'; instance.decoder.handleData(simulatedESPData, TEST_ORIGIN, time, instance.decodingOptions); } module.exports = TestListener;