How to use the thingpedia.PollingTrigger function in thingpedia

To help you get started, we’ve selected a few thingpedia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stanford-oval / thingpedia-common-devices / org.thingpedia.test / source.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2015 Giovanni Campagna 
//
// See LICENSE for details

const Tp = require('thingpedia');

var cnt = 0;

module.exports = new Tp.ChannelClass({
    Name: 'TestChannel',
    Extends: Tp.PollingTrigger,
    interval: 5000,

    _init: function() {
        this.parent();

        cnt++;
        console.log('Created Test channel #' + cnt);
    },

    _onTick: function() {
        this.emitEvent([42 + Math.floor(Math.random() * 42)]);
    },

    _doOpen: function() {
        return this.parent();
    },
github stanford-oval / thingpedia-common-devices / com.slack / receive.js View on Github external
}
          }
        }
      }
      return msgs[0].ts;
    })
    .catch(function(reason) {
      console.log('[info] Reason: ', String(reason));
      console.log('[ERROR] Unable to get channel history for ', channel_name);
    });
}


module.exports = new Tp.ChannelClass({
  Name: 'SlackReceiveChannel',
  Extends: Tp.PollingTrigger,
  interval: 4000,
  RequiredCapabilities: ['channel-state'],

  _init: function(engine, state, device, params) {
    this.parent();
    console.log('[info] Initializing SLACK:RECEIVE');
    this.auth = device.accessToken;
    this.user = device.state.user;
    this.state = state;
    this.interval = 4000; // Timer intervale in milliseconds
  },

  _doOpen: function() {
    console.log('[info] Calling doOpen of Receive.js');
    var d = new Date();
    var lastTs = d.getTime();
github stanford-oval / thingengine-core / lib / device-classes / thingengine / timer.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna 
//                Jiwon Seo 
//
// See COPYING for details

const Q = require('q');
const Tp = require('thingpedia');

module.exports = new Tp.ChannelClass({
    Name: 'TimerChannel',
    Extends: Tp.PollingTrigger,

    _init: function(engine, device, params) {
        this.parent();

        if (params.length !== 1 ||
            !params[0].isMeasure ||
            params[0].unit !== 'ms')
            throw new Error('Invalid @$timer parameters');

        this.interval = params[0].value;
        this.filterString = 'interval-' + this.interval;
    },

    _onTick: function() {
        var event = [this.interval];
        console.log('Emitting timer event', event);
github stanford-oval / thingengine-core / lib / devices / thingpedia / builtins / thingengine.builtin / timer.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2015 Giovanni Campagna 
//                Jiwon Seo 
//
// See COPYING for details
"use strict";

const Tp = require('thingpedia');

module.exports = class TimerChannel extends Tp.PollingTrigger {
    constructor(engine, device, params) {
        super(engine, device);

        this.interval = params[0];
        if (typeof this.interval !== 'number' || isNaN(params[0]))
            throw new Error('Missing or invalid parameter for @$timer');
        this.filterString = 'interval-' + this.interval;
    }

    formatEvent(event) {
        var interval = event[0];

        return this.engine._("Timer Elapsed");
    }

    _onTick() {