zettajs/zetta

VirtualDevice does not implement .available()

Closed this issue · 2 comments

/Users/ApigeeCorporation/Software/zetta/tests/ariafloat-issue/server.js:18
        if (led.available('turn-off')) {
                ^
TypeError: undefined is not a function
    at null.<anonymous> (/Users/ApigeeCorporation/Software/zetta/tests/ariafloat-issue/server.js:18:17)
    at emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Readable.push (_stream_readable.js:126:10)
    at listener (/Users/ApigeeCorporation/Software/zetta/tests/ariafloat-issue/node_modules/zetta/lib/virtual_device.js:20:16)
    at emit (events.js:129:20)
    at IncomingMessage.<anonymous> (/Users/ApigeeCorporation/Software/zetta/tests/ariafloat-issue/node_modules/zetta/lib/peer_socket.js:258:10)
    at IncomingMessage.emit (events.js:104:17)
    at _stream_readable.js:908:16
    at process._tickDomainCallback (node.js:381:11)

Test file

var zetta = require('zetta');
var Led = require('zetta-led-mock-driver');
var Photocell = require('zetta-photocell-mock-driver');
var MemoryRegistries = require('zetta-memory-registry')(zetta);
var PeerRegistry = MemoryRegistries.PeerRegistry;
var DeviceRegistry = MemoryRegistries.DeviceRegistry;

var app = function(server) {
  var photocellQuery = server.from('Dillon').where({ type: 'photocell' });
  var ledQuery = server.from('Dillon').where({ type: 'led' });
  server.observe([photocellQuery, ledQuery], function(photocell, led){
    photocell.streams.intensity.on('data', function(m) {
      if(m.data < 0.5) {
        if (led.available('turn-on')) {
          led.call('turn-on', function(){});
        }
      } else {
        if (led.available('turn-off')) {
          led.call('turn-off', function(){});
        }
      }
    });
  });
}

zetta({ registry: new DeviceRegistry(), peerRegistry: new PeerRegistry() })
  .name('cloud')
  .use(app)
  .listen(2000);

zetta({ registry: new DeviceRegistry(), peerRegistry: new PeerRegistry() })
  .name('Dillon')
  .use(Led)
  .use(Photocell)
  .link('http://localhost:2000')
  .listen(0)

More specifically we don't expose a number of methods implemented by a device driver some probably for the best and some maybe not.

Methods we expose on a device:

  • log
  • info
  • warn
  • error
  • available
  • call
  • properties
  • save
  • createReadStream
  • transitionsAvailable
  • destroy
  • enableStream
  • disableStream

We only expose call and createReadStream on a virtual device.

My proposal would be to add the following to virtual_device:

  • available
  • properties
  • transitionsAvailable

Possibly add destroy() as well because of the examples we show of destroying a device from a local app.

All the others feel like they should be limited to only the device implementation itself.