<commit_before>noflo = require 'noflo'

exports.getComponent = ->
  c = new noflo.Component
  c.icon = 'tint'
  c.description = 'Convert floor light colors to values sent to microcontroller'
  c.inPorts.add 'colors',
    datatype: 'array'
  c.outPorts.add 'floor',
    datatype: 'int'
    addressable: true
  c.process (input, output) ->
    return unless input.hasData 'colors'
    colors = input.getData 'colors'
    return output.done() unless colors.length
    [r, g, b] = colors[0]
    output.send
      floor: new noflo.IP 'data', r,
        index: 0
    output.send
      floor: new noflo.IP 'data', g,
        index: 1
    output.send
      floor: new noflo.IP 'data', b,
        index: 2
    output.done()<commit_msg>Only update floor lights when the value changes<commit_after>noflo = require 'noflo'

exports.getComponent = ->
  c = new noflo.Component
  c.icon = 'tint'
  c.description = 'Convert floor light colors to values sent to microcontroller'
  c.inPorts.add 'colors',
    datatype: 'array'
  c.outPorts.add 'floor',
    datatype: 'int'
    addressable: true
  c.previous = null
  c.tearDown = (callback) ->
    c.previous = null
    callback()
  c.process (input, output) ->
    return unless input.hasData 'colors'
    colors = input.getData 'colors'
    return output.done() unless colors.length
    followed = colors[0]
    if c.previous and followed[0] is c.previous[0] and followed[1] is c.previous[1] and followed[2] is c.previous[2]
      # No state change
      return output.done()
    c.previous = followed
    [r, g, b] = followed
    output.send
      floor: new noflo.IP 'data', r,
        index: 0
    output.send
      floor: new noflo.IP 'data', g,
        index: 1
    output.send
      floor: new noflo.IP 'data', b,
        index: 2
    output.done()

{'fraction_non_alphanumeric': 0.11781127861529872, 'fraction_numerical': 0.007816862088218872, 'mean_word_length': 2.6275303643724697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2204982', 'n_tokens_mistral': 608, 'n_tokens_neox': 596, 'n_words': 180}