How to use the thingpedia.Value 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.schema / index.js View on Github external
// XXX: we keep String for builtin entities (pictures, phone numbers, etc.)
                // because it's more compatible with other code
                // (it should handle both, but who knows...)
                //if (typemeta.type === 'tt:Entity')
                //    return new Tp.Value.Entity(value, null);
                if (typemeta.type === 'tt:Date')
                    return new Date(value);
                if (typemeta.type === 'tt:Time')
                    return parseTime(value);
                // value is already normalized
                return value;
            } else {
                const entity = DATA[typemeta.type][value];
                if (!entity)
                    return new Tp.Value.Entity(value, null);
                return new Tp.Value.Entity(value, entity.name || null);
            }
        }

        const ret = {};
        for (let field in typemeta.type)
            ret[field] = this._handleField(value[field], typemeta.type[field]);
        return ret;
    }
github stanford-oval / thingpedia-common-devices / test / org.schema.js View on Github external
['query', 'Hotel', {}, (results) => {
        for (let result of results) {
            //console.log(result);
            assert(result.id instanceof Tp.Value.Entity);
            assert(typeof result.id.value === 'string' && result.id.value);
            assert(typeof result.id.display === 'string');
        }
    }]
];
github stanford-oval / thingpedia-common-devices / test / us.sportradar.js View on Github external
['query', 'am_soccer_games', {
        league: new Tp.Value.Entity(
            'sr:tournament:242'),
        date: new Date(2018, 12, 19)
    }, (results) => {
        for (let result of results) {
            assert.strictEqual(typeof result.home_team.display,
                'string');
            assert.strictEqual(typeof result.away_team.display,
                'string');
            assert.strictEqual(result.status, 'closed');
        }
    }],

    ['query', 'nba_roster', { team: new Tp.Value.Entity('hou') }, (
        results) => {
        for (let result of results) {
            assert(['SG', 'SF', 'PG', 'PF', 'C', 'Head Coach'].includes(
                result.position));
            assert.strictEqual(typeof result.member, 'string');
        }
    }],

    ['query', 'mlb_roster', { team: new Tp.Value.Entity('oak') }, (
        results) => {
        for (let result of results) {

            try {
                assert(['1B', '2B', '3B', 'SS', 'LF', 'CF', 'RF', 'C', 'DH', 'SP1', 'SP2',
                    'SP3', 'SP4', 'SP5', 'CL'
                ].includes(result.position));
github stanford-oval / thingengine-core / test / functional / test_builtins.js View on Github external
async function testGetCommands(engine) {
    const device = engine.devices.getDevice('thingengine-own-global');

    const result = await device.get_get_commands({ device: new Tp.Value.Entity('com.xkcd', 'tt:device', 'XKCD') });

    for (let ex of result)
        assert(ex.program instanceof ThingTalk.Ast.Example);
}
github stanford-oval / thingpedia-common-devices / com.yandex.translate / device.js View on Github external
return Tp.Helpers.Http.get(url).then((response) => {
            console.log(response);
            const parsed = JSON.parse(response);
            if (parsed.code !== 200)
                throw new Error('Failed to detect language');

            return [{ value: new Tp.Value.Entity(parsed.lang, languages[parsed.lang]) }];
        });
    }
github stanford-oval / thingpedia-common-devices / gov.nasa / device.js View on Github external
return photos.slice(0, count).map((photo) => {
                const picture_url = photo.img_src;
                const date_taken = new Date(photo.earth_date);
                const camera_used = new Tp.Value.Entity(photo.camera.name, photo.camera.full_name);
                return { date_taken, picture_url, camera_used };
            });
        });
github stanford-oval / thingpedia-common-devices / org.thingpedia.weather / device.js View on Github external
return Tp.Helpers.Http.get(url).then(Tp.Helpers.Xml.parseString).then((parsed) => {
            var sun = parsed.astrodata.time[0].location[0].sun[0];
            var rise = new Date(sun.$.rise);
            var set = new Date(sun.$.set);

            return [{
                location,
                date,
                sunrise_time: new Tp.Value.Time(rise.getHours(), rise.getMinutes(), rise.getSeconds()),
                sunset_time: new Tp.Value.Time(set.getHours(), set.getMinutes(), set.getSeconds())
            }];
        });
    }
github stanford-oval / thingpedia-common-devices / us.sportradar / soccer_eu_team.js View on Github external
_createTpEntity(team) {
        return new Tp.Value.Entity(team.abbreviation.toLowerCase(), team.name);
    }
github stanford-oval / thingpedia-common-devices / org.schema / index.js View on Github external
function parseTime(value) {
    const [, hour, minute, second] = /^([0-9]{2}):([0-9]{2})(?::([0-9]{2}))?$/.exec(value);
    return new Tp.Value.Time(parseInt(hour), parseInt(minute), parseInt(second)||0);
}
github stanford-oval / thingpedia-common-devices / us.sportradar / nba_team.js View on Github external
_createTpEntity(team) {
        return new Tp.Value.Entity(team.alias.toLowerCase(), team.name);
    }