// Generated by CoffeeScript 1.10.0
(function() {
  var createDeviceManager;

  createDeviceManager = function(app) {
    var api, devices, intervalId, updateDevices;
    intervalId = null;
    devices = [];
    updateDevices = function() {
      var device, i, len, now, results;
      now = new Date();
      results = [];
      for (i = 0, len = devices.length; i < len; i++) {
        device = devices[i];
        results.push(device.online = (now - device.lastSeen) < app.config.deviceConnection.updateTimeout);
      }
      return results;
    };
    return api = {
      init: function(cb) {
        intervalId = setInterval(updateDevices, 2000);
        if (cb) {
          return cb();
        }
      },
      add: function(device) {
        return devices.push(device);
      },
      all: function() {
        return devices;
      },
      byDeviceId: function(deviceId) {
        return devices.find(function(device) {
          return deviceId === device.deviceId;
        });
      }
    };
  };

  module.exports = createDeviceManager;

}).call(this);
