funlogic-io/zwave-serialapi

View on GitHub
lib/serialapi/serialapi-utils.js

Summary

Maintainability
A
0 mins
Test Coverage
const consts = require('./consts')

function buildDefinitionsLookups (definitions) {
  const definitionsById = {}
  for (const definition of definitions) {
    const { funcId } = definition
    definitionsById[funcId] = definition
  }
  return {
    definitions,
    definitionsById
  }
}

function processResponse (funcMeta, frame) {
  if (frame.type === consts.RESPONSE) {
    if (funcMeta && typeof funcMeta.decodeResponse === 'function') {
      return funcMeta.decodeResponse(frame, {})
    }
  }
}

function processCallback (funcMeta, frame) {
  if (frame.type === consts.REQUEST) {
    if (funcMeta && typeof funcMeta.decodeCallback === 'function') {
      return funcMeta.decodeCallback(frame, {})
    }
  }
}
module.exports = {
  buildDefinitionsLookups,
  processCallback,
  processResponse
}