How to use the thingpedia.ObjectSet 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 / com.nest / collections.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2016-2018 Giovanni Campagna 
//
// See LICENSE for details
"use strict";

const Tp = require('thingpedia');
const ObjectSet = Tp.ObjectSet;

class NestDeviceCollection extends ObjectSet.Simple {
    constructor(device, path, constructor) {
        super(false);
        this._device = device;
        this._path = path;
        this._childConstructor = constructor;

        this._childAddedListener = this._onChildAdded.bind(this);
        this._childRemovedListener = this._onChildRemoved.bind(this);
        this._childChangedListener = this._onChildChanged.bind(this);
    }

    _onChildAdded(state) {
        var url = this._path + '/' + state.key();
        var obj = new (this._childConstructor)(this._device.engine, state.val(), url, this._device);
github stanford-oval / thingengine-core / lib / devices / database.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2015 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const uuid = require('uuid');

const Tp = require('thingpedia');
const ObjectSet = Tp.ObjectSet;
const SyncDatabase = require('../db/syncdb');

/**
 * The collection of all configured Thingpedia devices.
 */
class DeviceDatabase extends ObjectSet.Base {
    /**
     * Construct the device database for this engine.
     *
     * There is only one device database instance per engine,
     * and it is accessible as {@link Engine#devices}.
     *
     * @param {external:thingpedia.BasePlatform} - the platform associated with the engine
     * @param {TierManager} - the tier manager to use for device synchronization
     * @param {external:thingpedia.DeviceFactory} - the factory to load and construct Thingpedia devices
     * @param {external:thingtalk.SchemaRetriever} - the schema retriever to typecheck ThingTalk code
github stanford-oval / thingengine-core / lib / devices / database.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 
//
// See COPYING for details
"use strict";

const Q = require('q');
const events = require('events');
const fs = require('fs');
const uuid = require('node-uuid');

const Tp = require('thingpedia');
const ObjectSet = Tp.ObjectSet;
const SyncDatabase = require('../db/syncdb');

module.exports = class DeviceDatabase extends ObjectSet.Base {
     constructor(platform, tierManager, factory, schemas) {
        super();
        this.setMaxListeners(0);

        this.factory = factory;

        // for compat only
        this.schemas = schemas;

        this._devices = new Map();
        this._byDescriptor = {};

        this._tierManager = tierManager;
github stanford-oval / thingengine-core / lib / apps / channel_opener.js View on Github external
//
// This file is part of ThingEngine
//
// Copyright 2015 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const Q = require('q');

const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Tp = require('thingpedia');
const ObjectSet = Tp.ObjectSet;

const DeviceView = require('../devices/device_view');

// the device that owns/implements a builtin
const BuiltinOwner = {
    'return': 'thingengine-app',
    'notify': 'thingengine-app',
    'timer': 'thingengine-app',
};

module.exports = class ChannelOpener extends ObjectSet.Base {
    constructor(engine, app, mode, selector, channelName, params) {
        super();

        this.engine = engine;
        this.app = app;
github stanford-oval / thingpedia-common-devices / com.tesla / device.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// Copyright 2018 Monica Lam 
//
// See LICENSE for details
"use strict";

const Tp = require('thingpedia');
const ObjectSet = Tp.ObjectSet;

const TESLA_CLIENT_ID = 'e4a9949fcfa04068f59abb5a658f2bac0a3428e4652315490b659d5ab3f35a9e';
const TESLA_CLIENT_SECRET = 'c75f14bbadc8bee3a7594412c31416f8300256d7668ea7e6e7f06727bfb9d220';
const TESLA_BASE_URI = 'https://owner-api.teslamotors.com';
//const TESLA_BASE_URI = 'https://private-anon-6e9b9d475-timdorr.apiary-mock.com';

// emulate the android mobile app
var version = '2.1.79';
var model = 'SM-G900V';
var codename = 'REL';
var release = '4.4.4';
var locale = 'en_US';
var user_agent = 'Model S ' + version + ' (' + model + '; Android ' + codename + ' ' + release + '; ' + locale + ')';

class TeslaCarDevice extends Tp.BaseDevice {
    constructor(engine, state, master) {
github stanford-oval / thingengine-core / lib / devices / device_view.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2015 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const Tp = require('thingpedia');
const ObjectSet = Tp.ObjectSet;

function like(str, substr) {
    return str.toLowerCase().indexOf(substr.toLowerCase()) >= 0;
}

// A "view" of a set of devices, as a set of selectors matching
// in specific context (which must be an ObjectSet of Devices)
module.exports = class DeviceView extends ObjectSet.Base {
    constructor(context, kind, attrs, dynamic = true) {
        super();

        this.context = context;
        this.kind = kind;
        this.attrs = attrs;

        this._deviceAddedListener = null;
github stanford-oval / thingengine-core / test / functional / test-classes / collection.js View on Github external
constructor(engine, state) {
        super(engine, state);

        this.name = "Test Collection Device";
        this.description = "This is a Test, a Device, and also a Collection";
        this.uniqueId = 'org.thingpedia.builtin.test.collection-1';

        this._collection = new Tp.ObjectSet.Simple();
    }
github stanford-oval / thingpedia-common-devices / com.hue / device.js View on Github external
_init: function(engine, state) {
        this.parent(engine, state);

        this.uniqueId = 'com.hue-' + state.uuid;
        this.name = "Philips Hue Bridge (%s)".format(state.host);
        this.description = "This is a Philips Hue Bridge. It holds your light bulbs toghether.";
        this.descriptors = ['upnp/' + state.uuid];

        this._initialized = false;
        this._deviceCollection = new Tp.ObjectSet.Simple(false);
    },
github stanford-oval / thingpedia-common-devices / com.tumblr / device.js View on Github external
_init: function(engine, state) {
        this.parent(engine, state);

        this.uniqueId = 'com.tumblr-' + state.username;

        this.name = "Tumblr Account " + state.username;
        this.description = "Your Tumblr account allows you to retrieve information about Tumblr blogs and post on your blogs.";

        this._deviceCollection = new Tp.ObjectSet.Simple(false);
    },