How to use the thingpedia.Tier 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 / thingengine-core / lib / device-classes / thingengine / device.js View on Github external
// own is true if this thingengine belongs to the same user
        // as the one running the code
        // (eg, a server thingengine as seen from the phone)
        // own is false if this thingengine is some other instance
        // that we discovered through some other method
        // (eg, a server thingengine for another family member,
        // as seen from a server running on the same physical machine)
        // we still want to coordinate with foreign thingengines
        // sometimes, so we have API calls and channels, but we
        // don't sync everything through them
        this.own = state.own;

        // this !! is for legacy reasons
        this.isTransient = !!state.isTransient;

        if (this.tier === Tp.Tier.CLOUD) {
            this.cloudId = state.cloudId;
        } else if (this.tier === Tp.Tier.SERVER) {
            this.host = state.host;
            this.port = state.port;

            if (typeof state.port != 'number' || isNaN(state.port))
                throw new TypeError('Invalid port number ' + state.port);
        } else if (this.tier === Tp.Tier.PHONE) {
            this.messagingId = state.messagingId;
        }

        // This is a built-in device so we're allowed some
        // "friendly" API access
        this._tierManager = engine._tiers;

        if (this.own) {
github stanford-oval / thingengine-core / lib / db / syncdb.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 events = require('events');

const Tp = require('thingpedia');
const Tier = Tp.Tier;
const sql = require('./sqlite');

class SQLDatabase {
    constructor(platform, tablename, fields) {
        this.tablename = tablename;
        this.fields = fields;
        this._discriminator = fields[0];
        this._db = sql.db(platform.getSqliteDB(), platform.getSqliteKey());
    }

    _getLastModifiedInternal(client) {
        return sql.selectAll(client, `select max(lastModified) as maxLastModified
                             from ${this.tablename}_journal`).then((rows) => {
            if (rows.length === 0 || rows[0].maxLastModified === null)
                return 0;
            else
github stanford-oval / thingengine-core / lib / tiers / paired.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 crypto = require('crypto');

const Tp = require('thingpedia');
const Tier = Tp.Tier;
const IpAddress = require('../util/ip_address');
const Builtins = require('../devices/builtins');

module.exports = class PairedEngineManager {
    constructor(platform, devices, deviceFactory, tierManager) {
        this._platform = platform;
        this._devices = devices;
        this._deviceFactory = deviceFactory;
        this._tierManager = tierManager;

        this._deviceAddedListener = this._onDeviceAdded.bind(this);
        this._deviceRemovedListener = this._onDeviceRemoved.bind(this);
    }

    _makeAuthToken() {
        var prefs = this._platform.getSharedPreferences();
github stanford-oval / thingengine-core / lib / devices / builtins / thingengine.js View on Github external
constructor(engine, state) {
        super(engine, state);

        this.tier = state.tier;

        // for compat with the currently deployed cloud server (which does not understand
        // identity) we normalize identity to ''
        this.identity = state.identity || '';
        this.address = this.tier + this.identity;
        this.own = true;

        // This is a built-in device so we're allowed some
        // "friendly" API access
        this._tierManager = engine._tiers;

        if (this.tier === Tp.Tier.CLOUD) {
            this._checkCloudIdDevKey(state);
            this.cloudId = state.cloudId;
            this.developerKey = state.developerKey;
            if (this._tierManager.ownTier !== Tp.Tier.CLOUD)
                this.engine.platform.setDeveloperKey(state.developerKey);
        } else if (this.tier === Tp.Tier.SERVER) {
            this.host = state.host;
            this.port = state.port;

            if (typeof state.port !== 'number' || isNaN(state.port))
                throw new TypeError('Invalid port number ' + state.port);
        }

        this.uniqueId = 'thingengine-own-' + this.address;
        this.name = this.engine._("Almond %s (%s)").format(this.tier, this.identity.substring(1));
        this.description = this.engine._("This is one of your own Almond apps.");
github stanford-oval / thingengine-core / lib / devices / thingpedia / builtins / thingengine.phone / index.js View on Github external
checkAvailable() {
        if (Tp.Tier.PHONE === this._tierManager.ownTier) {
            return Tp.Availability.AVAILABLE;
        } else {
            return (this._tierManager.isConnected(Tp.Tier.PHONE) ?
                    Tp.Availability.AVAILABLE :
                    Tp.Availability.OWNER_UNAVAILABLE);
        }
    }
github stanford-oval / almond-android / jsapp / thingengine.phone.js View on Github external
checkAvailable() {
        if (Tp.Tier.PHONE === this._tierManager.ownTier) {
            return Tp.Availability.AVAILABLE;
        } else {
            return (this._tierManager.isConnected(Tp.Tier.PHONE) ?
                    Tp.Availability.AVAILABLE :
                    Tp.Availability.OWNER_UNAVAILABLE);
        }
    }
github stanford-oval / almond-android / jsapp / thingengine.phone.js View on Github external
checkAvailable() {
        if (Tp.Tier.PHONE === this._tierManager.ownTier) {
            return Tp.Availability.AVAILABLE;
        } else {
            return (this._tierManager.isConnected(Tp.Tier.PHONE) ?
                    Tp.Availability.AVAILABLE :
                    Tp.Availability.OWNER_UNAVAILABLE);
        }
    }