<commit_before>var types = require("hap-nodejs/accessories/types.js");
var TellduAPI = require("telldus-live");

function TelldusLivePlatform(log, config) {
    var that = this;
    that.log = log;

    that.isLoggedIn = false;

    // Login to Telldus Live!
    that.cloud = new TellduAPI.TelldusAPI({publicKey: config["public_key"], privateKey: config["private_key"]})
        .login(config["token"], config["token_secret"], function(err, user) {
            if (!!err) that.log("Login error: " + err.message);
            that.log("User logged in: " + user.firstname + " " + user.lastname + ", " + user.email);
            that.isLoggedIn = true;
        }
    );
}

TelldusLivePlatform.prototype = {

    accessories: function(callback) {
        var that = this;

        that.log("Fetching devices...");

        that.cloud.getDevices(function(err, devices) {

            if (!!err) return that.log('getDevices: ' + err.message);

            var foundAccessories = [];

            // Clean non device
            for (var i = 0; i < devices.length; i++) {
                if (devices[i].type != 'device') {
                    devices.splice(i, 1);
                }
            }

            for (var i = 0; i < devices.length; i++) {
                if (devices[i].type === 'device') {
                    TelldusLiveAccessory.create(that.log, devices[i], that.cloud, function(err, accessory) {
                        if (!!err) that.log("Couldn't load device info");
                        foundAccessories.push(accessory);
                        if (foundAccessories.length >= devices.length) {
                            callback(foundAccessories);
                        }
                    });
                }
            }

        });
    }
};

var TelldusLiveAccessory = function TelldusLiveAccessory(log, cloud, device) {

    this.log   = log;
    this.cloud = cloud;

    var m = device.model.split(':');

    // Set accessory info
    this.device         = device;
    this.id             = device.id;
    this.name           = device.name;
    this.manufacturer   = m[1];
    this.model          = m[0];
    this.state          = device.state;
    this.stateValue     = device.stateValue;
    this.status         = device.status;
};

TelldusLiveAccessory.create = function (log, device, cloud, callback) {<commit_msg>Handle where no model is returned from Telldus Live<commit_after>var types = require("hap-nodejs/accessories/types.js");
var TellduAPI = require("telldus-live");

function TelldusLivePlatform(log, config) {
    var that = this;
    that.log = log;

    that.isLoggedIn = false;

    // Login to Telldus Live!
    that.cloud = new TellduAPI.TelldusAPI({publicKey: config["public_key"], privateKey: config["private_key"]})
        .login(config["token"], config["token_secret"], function(err, user) {
            if (!!err) that.log("Login error: " + err.message);
            that.log("User logged in: " + user.firstname + " " + user.lastname + ", " + user.email);
            that.isLoggedIn = true;
        }
    );
}

TelldusLivePlatform.prototype = {

    accessories: function(callback) {
        var that = this;

        that.log("Fetching devices...");

        that.cloud.getDevices(function(err, devices) {

            if (!!err) return that.log('getDevices: ' + err.message);

            var foundAccessories = [];

            // Clean non device
            for (var i = 0; i < devices.length; i++) {
                if (devices[i].type != 'device') {
                    devices.splice(i, 1);
                }
            }

            for (var i = 0; i < devices.length; i++) {
                if (devices[i].type === 'device') {
                    TelldusLiveAccessory.create(that.log, devices[i], that.cloud, function(err, accessory) {
                        if (!!err) that.log("Couldn't load device info");
                        foundAccessories.push(accessory);
                        if (foundAccessories.length >= devices.length) {
                            callback(foundAccessories);
                        }
                    });
                }
            }

        });
    }
};

var TelldusLiveAccessory = function TelldusLiveAccessory(log, cloud, device) {

    this.log   = log;
    this.cloud = cloud;

    var m = device.model ? device.model.split(':') : ['unknown', 'unknown'] ;

    // Set accessory info
    this.device         = device;
    this.id             = device.id;
    this.name           = device.name;
    this.manufacturer   = m[1];
    this.model          = m[0];
    this.state          = device.state;
    this.stateValue     = device.stateValue;
    this.status         = device.status;
};

TelldusLiveAccessory.create = function (log, device, cloud, callback) {
{'fraction_non_alphanumeric': 0.13469985358711567, 'fraction_numerical': 0.002091612633340305, 'mean_word_length': 1.7834691501746216, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4574664', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1364, 'n_words': 289}