Ejemplo n.º 1
0
test.before(async () => {
    var hubTranslator = await OpenT2T.createTranslatorAsync(hubPath, 'thingTranslator', config);
    var hubInfo = await OpenT2T.invokeMethodAsync(hubTranslator, 'org.opent2t.sample.hub.superpopular', 'get', []);
    var deviceInfo = getBinarySwitch(hubInfo.platforms);

    translator = await OpenT2T.createTranslatorAsync(translatorPath, 'thingTranslator', {'deviceInfo': deviceInfo, 'hub': hubTranslator});
});
Ejemplo n.º 2
0
        return OpenT2T.invokeMethodAsync(hubTranslator, 'org.opent2t.sample.hub.superpopular', 'get', [false]).then(platforms => {
            var platformInfo = getBinarySwitch(platforms.platforms);
            var deviceInfo = {};
            deviceInfo.opent2t = platformInfo.opent2t;

            return OpenT2T.createTranslatorAsync(translatorPath, 'thingTranslator', {'deviceInfo': deviceInfo, 'hub': hubTranslator});
        });
Ejemplo n.º 3
0
        devices.forEach((smartThingsDevice) => {
            // get the opent2t schema and translator for the SmartThings device
            var opent2tInfo = this._getOpent2tInfo(smartThingsDevice.deviceType);

            if (typeof opent2tInfo !== 'undefined') // we support the device                    
            {
                /// set the opent2t info for the SmartThings device
                var deviceInfo = {};
                deviceInfo.opent2t = {};
                deviceInfo.opent2t.controlId = smartThingsDevice.id;
                deviceInfo.opent2t.endpointURI = endpointUri;

                // Create a translator for this device and get the platform information, possibly expanded
                platformPromises.push(this.opent2t.createTranslatorAsync(opent2tInfo.translator, { 'deviceInfo': deviceInfo, 'hub': this })
                    .then((translator) => {

                        var deviceData = smartThingsDevice;
                        deviceData.endpointUri = endpointUri;

                        // Use get to translate the SmartThings formatted device that we already got in the previous request.
                        // We already have this data, so no need to make an unnecesary request over the wire.
                        return this.opent2t.invokeMethodAsync(translator, opent2tInfo.schema, 'get', [expand, deviceData])
                            .then((platformResponse) => {
                                return Promise.resolve(platformResponse);
                            });
                    }).catch((err) => {
                        return Promise.reject(err);
                    }));
            } else {
                // Platforms without translators should be recorded as errors, but can be safely ignored.
                toReturn.errors.push(new OpenT2TError(404, `${OpenT2TConstants.UnknownPlatform}: ${smartThingsDevice.deviceType}`));
            }
        });
Ejemplo n.º 4
0
test.serial('Get', t => {

    return opent2t.createTranslatorAsync(translatorPath, 'thingTranslator', config)
        .then(translator => {
            // TEST: translator is valid
            t.is(typeof translator, 'object') && t.truthy(translator);
            return opent2t.invokeMethodAsync(translator, 'org.opent2t.sample.hub.superpopular', 'getPlatforms', [true])
                .then((hub) => {
                    
                    console.log("Hub schema:");
                    console.log(JSON.stringify(hub.schema, null, 2));
                    console.log("Hub Platforms:");
                    console.log(JSON.stringify(hub.platforms, null, 2));
                    console.log("Hub Errors:");
                    console.log(hub.errors);

                    // TEST: something was returned
                    t.truthy(hub);

                    // TEST: hub has devices
                    t.truthy(hub.platforms);
                    t.true(hub.platforms.length > 0);
                });
        });
});
Ejemplo n.º 5
0
    return OpenT2T.createTranslatorAsync(hubPath, 'thingTranslator', config).then(hubTranslator => {
        return OpenT2T.invokeMethodAsync(hubTranslator, 'org.opent2t.sample.hub.superpopular', 'get', [false]).then(platforms => {
            var platformInfo = getThermostat(platforms.platforms);
            deviceInfo.opent2t = platformInfo.opent2t;

            return OpenT2T.createTranslatorAsync(translatorPath, 'thingTranslator', {'deviceInfo': deviceInfo, 'hub': hubTranslator});
        });
    });
Ejemplo n.º 6
0
 .then((translator) => {
     // Use get to translate the Insteon formatted device that we already got in the previous request.
     // We already have this data, so no need to make an unnecesary request over the wire.
     return this.opent2t.invokeMethodAsync(translator, opent2tInfo.schema, 'get', [expand, deviceData])
         .then((platformResponse) => {
             return Promise.resolve(platformResponse);
         });
 }).catch((err) => {
Ejemplo n.º 7
0
test.serial('GetPower', t => {
    return OpenT2T.invokeMethodAsync(translator, 'org.opent2t.sample.binaryswitch.superpopular', 'getDevicesPower', ['F85B0738-6EC0-4A8B-A95A-503B6F2CA0D8'])
        .then((response) => {
            t.is(response.rt[0], 'oic.r.switch.binary');

            console.log('*** response: \n' + JSON.stringify(response, null, 2));
        });
});
Ejemplo n.º 8
0
test.serial('GetPlatform', t => {
    return OpenT2T.invokeMethodAsync(translator, 'org.opent2t.sample.binaryswitch.superpopular', 'get', [])
        .then((response) => {
            t.is(response.rt[0], 'org.opent2t.sample.binaryswitch.superpopular');

            console.log('*** response: \n' + JSON.stringify(response, null, 2));
        });
});
Ejemplo n.º 9
0
function createTranslator() {
    return OpenT2T.createTranslatorAsync(hubPath, 'thingTranslator', config).then(hubTranslator => {
        return OpenT2T.invokeMethodAsync(hubTranslator, 'org.opent2t.sample.hub.superpopular', 'get', [false]).then(platforms => {
            var platformInfo = getLamp(platforms.platforms);
            var deviceInfo = {'opent2t': platformInfo.opent2t};

            return OpenT2T.createTranslatorAsync(translatorPath, 'thingTranslator', {'deviceInfo': deviceInfo, 'hub': hubTranslator});
        });
    });
}
Ejemplo n.º 10
0
test.serial('GetPlatformExpanded', t => {
    return OpenT2T.invokeMethodAsync(translator, 'org.opent2t.sample.binaryswitch.superpopular', 'get', [true])
        .then((response) => {
            t.is(response.rt[0], 'org.opent2t.sample.binaryswitch.superpopular');

            var resource = response.entities[0].resources[0];
            t.is(resource.id, 'power');
            t.is(resource.rt[0], 'oic.r.switch.binary');
            t.true(resource.value !== undefined);

            console.log('*** response: \n' + JSON.stringify(response, null, 2));
        });
});
Ejemplo n.º 11
0
        .then(onboarding => {
            // TEST: translator is valid
            t.is(typeof onboarding, 'object') && t.truthy(onboarding);

            return opent2t.invokeMethodAsync(onboarding, "org.opent2t.onboarding.wink", "onboard", [testConfig])
                .then((accessToken) => {
                    console.log("accessToken:");
                    console.log(JSON.stringify(accessToken, null, 2));

                    // TEST: something was returned
                    t.truthy(accessToken);
                    t.truthy(accessToken.accessToken);
                });
        });
Ejemplo n.º 12
0
        return translator.postSubscribe(subscriptionInfo).then((response) => {
            t.is(response[0], 'succeed');

            var targetTemperatureHigh = { 'temperature': 85, 'units': 'f' };
            return OpenT2T.invokeMethodAsync(translator, 'org.opent2t.sample.thermostat.superpopular', 'postDevicesTargetTemperatureHigh', [deviceId, targetTemperatureHigh])
            .then((responseTwo) => {
                t.is(responseTwo.rt[0], 'oic.r.temperature');
                t.is(responseTwo.temperature, targetTemperatureHigh.temperature);
                
                // Unsubscribe and end the test
                console.log('Unsubscribing for ' + deviceId + ' ...');
                return translator.deleteSubscribe(subscriptionInfo).then((responseThree) => {
                    t.is(responseThree, 'succeed');
                });
            });
        });
Ejemplo n.º 13
0
        .then(translator => {
            // TEST: translator is valid
            t.is(typeof translator, 'object') && t.truthy(translator);
            return opent2t.invokeMethodAsync(translator, 'org.opent2t.sample.hub.superpopular', 'getPlatforms', [])
                .then((hub) => {

                    logger.verbose("Hub:");
                    logger.verbose(JSON.stringify(hub, null, 2));

                    // TEST: something was returned
                    t.truthy(hub);

                    // TEST: hub has platforms
                    t.truthy(hub.platforms);
                    t.true(hub.platforms.length > 0);
                });
        });
Ejemplo n.º 14
0
test.serial('onboard', t => {

    return opent2t.createTranslatorAsync(onboardingPath, 'thingOnboarding', testConfig)
        .then(onboarding => {
            // TEST: translator is valid
            t.is(typeof onboarding, 'object') && t.truthy(onboarding);

            return opent2t.invokeMethodAsync(onboarding, "org.opent2t.onboarding.smartthings", "onboard", [testConfig])
                .then((accessToken) => {
                    console.log("accessToken:");
                    console.log(JSON.stringify(accessToken, null, 2));

                    // TEST: something was returned
                    t.truthy(accessToken);
                    t.truthy(accessToken.accessToken);
                });
        });
});
Ejemplo n.º 15
0
        .then(onboarding => {
            // TEST: translator is valid
            t.is(typeof onboarding, 'object') && t.truthy(onboarding);

            return opent2t.invokeMethodAsync(onboarding, "org.opent2t.onboarding.getverahub", "onboard", [testConfig])
                .then((accessToken) => {
                    console.log("accessToken:");
                    console.log(JSON.stringify(accessToken, null, 2));

                    // TEST: something was returned
                    t.truthy(accessToken);
                    t.truthy(accessToken.relaySessionToken);
                    t.truthy(accessToken.relayServer);
                    t.truthy(accessToken.refreshToken);
                    t.truthy(accessToken.username);
                    t.truthy(accessToken.internalIP);
                    t.truthy(accessToken.port);
                });
        });
Ejemplo n.º 16
0
                                    .then((deviceStatus) => {
                                        if (deviceStatus !== undefined && deviceStatus.status === 'succeeded') {

                                            deviceData['Reachable'] = true;

                                            switch (opent2tInfo.schema) {
                                                case 'org.opent2t.sample.thermostat.superpopular':
                                                    for (var status in deviceStatus.response) {
                                                        deviceData[status] = deviceStatus.response[status];
                                                    }
                                                    break;
                                                default:
                                                    deviceData['Level'] = deviceStatus.response.level;
                                                    if (deviceStatus.response.level == 0) {
                                                        deviceData['Power'] = 'off';
                                                    } else {
                                                        deviceData['Power'] = 'on';
                                                    }
                                                    break;
                                            }

                                        } else if (deviceStatus.status === 'failed') {
                                            deviceData['Reachable'] = false;
                                        }

                                        // Create a translator for this device and get the platform information, possibly expanded
                                        return this.opent2t.createTranslatorAsync(opent2tInfo.translator, { 'deviceInfo': deviceInfo, 'hub': this })
                                            .then((translator) => {
                                                // Use get to translate the Insteon formatted device that we already got in the previous request.
                                                // We already have this data, so no need to make an unnecesary request over the wire.
                                                return this.opent2t.invokeMethodAsync(translator, opent2tInfo.schema, 'get', [expand, deviceData])
                                                    .then((platformResponse) => {
                                                        return Promise.resolve(platformResponse);
                                                    });
                                            }).catch((err) => {
                                                // Being logged in HubController already
                                                return Promise.resolve(undefined);
                                            });

                                    }).catch((err) => {
Ejemplo n.º 17
0
        winkDevices.forEach((winkDevice) => {
            // Ignore physical hubs for now
            if (winkDevice.object_type && winkDevice.object_type.toLowerCase() === 'hub') {
               return;
            }
            // Ignore hidden devices
            if (winkDevice.hidden_at) {
                return;
            }

            // Get the opent2t schema and translator for the wink device
            var opent2tInfo = this._getOpent2tInfo(winkDevice);

            if (!opent2tInfo) {
                // Platforms without translators should be recorded as errors, but can be safely ignored.
                toReturn.errors.push(new OpenT2TError(404, `${OpenT2TConstants.UnknownPlatform}: ${winkDevice.model_name}`));
            }
            else {
                var deviceInfo = {};
                deviceInfo.opent2t = {};
                deviceInfo.opent2t.controlId = this._getDeviceId(winkDevice);

                // Create a translator for this device and get the platform information, possibly expanded
                platformPromises.push(this.opent2t.createTranslatorAsync(opent2tInfo.translator, {'deviceInfo': deviceInfo, 'hub': this})
                    .then((translator) => {

                        // Use get to translate the Wink formatted device that we already got in the previous request.
                        // We already have this data, so no need to make an unnecesary request over the wire.
                        return this.opent2t.invokeMethodAsync(translator, opent2tInfo.schema, 'get', [expand, winkDevice])
                            .then((platformResponse) => {
                                return platformResponse;
                            });
                    }).catch((err) => {
                        // Being logged in HubController already
                        return Promise.reject(err);
                    }));
            }
        });
Ejemplo n.º 18
0
 return OpenT2T.invokeMethodAsync(hubTranslator, 'org.opent2t.sample.hub.superpopular', 'get', [false]).then(platforms => {
     var platformInfo = getThermostat(platforms.platforms);
     var deviceInfo = {'opent2t': platformInfo.opent2t};
     deviceId = platformInfo.entities[0].di;
     return OpenT2T.createTranslatorAsync(translatorPath, 'thingTranslator', {'deviceInfo': deviceInfo, 'hub': hubTranslator});
 });