<commit_before>/* jshint esversion: 6 */
/* jshint node: true */
'use strict';

// This code uses ES2015 syntax that requires at least Node.js v4.
// For Node.js ES2015 support details, reference http://node.green/

function validateArgumentType(arg, argName, expectedType) {
    if (typeof arg === 'undefined') {
        throw new Error('Missing argument: ' + argName + '. ' +
            'Expected type: ' + expectedType + '.');
    } else if (typeof arg !== expectedType) {
        throw new Error('Invalid argument: ' + argName + '. ' +
            'Expected type: ' + expectedType + ', got: ' + (typeof arg));
    }
}

// Helper method to convert SmartThings's 0.0-1.0 brightness scale to a 0-100 scale
function scaleDeviceBrightnessToTranslatorBrightness(brightnessValue) {
    return Math.floor(brightnessValue * 100);
}

// Helper method to convert a 0-100 scale to SmartThings's 0.0-1.0 brightness scale
function scaleTranslatorBrightnessToDeviceBrightness(dimmingValue) {
    return dimmingValue / 100;
}

// Helper method to convert the device schema to the translator schema.
function deviceSchemaToTranslatorSchema(deviceSchema) {

    return {
        id: deviceSchema['id'],
        n: deviceSchema['name'],
        rt: 'org.opent2t.sample.lamp.superpopular',
        power: { 'value': deviceSchema['attributes'].switch == 'on' },
        dim: { 'dimmingSetting': deviceSchema['attributes'].level, 'range': [0, 100] }
    };
}

// Helper method to convert the translator schema to the device schema.
function translatorSchemaToDeviceSchema(translatorSchema) {

    // build the object with desired state
    var result = {};
    var attributes = result.attributes;

    if (translatorSchema.n) {
        result['name'] = translatorSchema.n;
    }

    if (translatorSchema.power) {
        result['switch'] = translatorSchema.power.value? 'on' : 'off';
    }

    if (translatorSchema.dim) {
        result['level'] = translatorSchema.dim.dimmingSetting;
    }

    return result;
}

var deviceId;
var deviceType = "light";
var smartthingsHub;

// This translator class implements the 'org.opent2t.sample.lamp.superpopular' interface.
class Translator {

    constructor(deviceInfo) {
        console.log('SmartThings Lightbulb initializing...');

        validateArgumentType(deviceInfo, "deviceInfo", "object");
        
        deviceId = deviceInfo.deviceInfo.id;
        smartthingsHub = deviceInfo.hub;

        console.log('SmartThings Lightbulb initializing...Done');
    }<commit_msg>Remove "name" from support settable fields.<commit_after>/* jshint esversion: 6 */
/* jshint node: true */
'use strict';

// This code uses ES2015 syntax that requires at least Node.js v4.
// For Node.js ES2015 support details, reference http://node.green/

function validateArgumentType(arg, argName, expectedType) {
    if (typeof arg === 'undefined') {
        throw new Error('Missing argument: ' + argName + '. ' +
            'Expected type: ' + expectedType + '.');
    } else if (typeof arg !== expectedType) {
        throw new Error('Invalid argument: ' + argName + '. ' +
            'Expected type: ' + expectedType + ', got: ' + (typeof arg));
    }
}

// Helper method to convert SmartThings's 0.0-1.0 brightness scale to a 0-100 scale
function scaleDeviceBrightnessToTranslatorBrightness(brightnessValue) {
    return Math.floor(brightnessValue * 100);
}

// Helper method to convert a 0-100 scale to SmartThings's 0.0-1.0 brightness scale
function scaleTranslatorBrightnessToDeviceBrightness(dimmingValue) {
    return dimmingValue / 100;
}

// Helper method to convert the device schema to the translator schema.
function deviceSchemaToTranslatorSchema(deviceSchema) {

    return {
        id: deviceSchema['id'],
        n: deviceSchema['name'],
        rt: 'org.opent2t.sample.lamp.superpopular',
        power: { 'value': deviceSchema['attributes'].switch == 'on' },
        dim: { 'dimmingSetting': deviceSchema['attributes'].level, 'range': [0, 100] }
    };
}

// Helper method to convert the translator schema to the device schema.
function translatorSchemaToDeviceSchema(translatorSchema) {

    // build the object with desired state
    var result = {};
    var attributes = result.attributes;

    if (translatorSchema.power) {
        result['switch'] = translatorSchema.power.value? 'on' : 'off';
    }

    if (translatorSchema.dim) {
        result['level'] = translatorSchema.dim.dimmingSetting;
    }

    return result;
}

var deviceId;
var deviceType = "light";
var smartthingsHub;

// This translator class implements the 'org.opent2t.sample.lamp.superpopular' interface.
class Translator {

    constructor(deviceInfo) {
        console.log('SmartThings Lightbulb initializing...');

        validateArgumentType(deviceInfo, "deviceInfo", "object");
        
        deviceId = deviceInfo.deviceInfo.id;
        smartthingsHub = deviceInfo.hub;

        console.log('SmartThings Lightbulb initializing...Done');
    }
{'fraction_non_alphanumeric': 0.12026591458501208, 'fraction_numerical': 0.015310233682514102, 'mean_word_length': 3.2912705272255836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5329343', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1395, 'n_words': 387}