<commit_before>/*
 *  KNXBridge.js
 *
 *  <NAME>
 *  IOTDB.org
 *  2015-11-29
 *
 *  Copyright [2013-2015] [<NAME>]
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

"use strict";

var iotdb = require('iotdb');
var _ = iotdb._;
var bunyan = iotdb.bunyan;

var url = require('url');
var knx_js = require('knx.js');

var logger = bunyan.createLogger({
    name: 'homestar-knx',
    module: 'KNXBridge',
});

/*
    localIpAddress, 13671);
  var KnxConnectionTunneling = require('knx.js').KnxConnectionTunneling;
  var connection = new KnxConnectionTunneling('192.168.80.101', 3671, localIpAddress, 13671);
  */

/**
 *  See {iotdb.bridge.Bridge#Bridge} for documentation.
 *  <p>
 *  @param {object|undefined} native
 *  only used for instances, should be 
 */
var KNXBridge = function (initd, native) {
    var self = this;

    self.initd = _.defaults(initd,
        iotdb.keystore().get("bridges/KNXBridge/initd"), {
            host: null,
            port: 3671,
            tunnel: null,
            raw: false, // pass GAs unchanged (debugging mainly)
            uuid: null, // seed for the Thing-ID
            number: 0, // can be used to share a single UUID
            knx: {}, // trés important
        }
    );
    self.native = native; // the thing that does the work - keep this name

    if (self.initd.tunnel) {
        var turl = url.parse(self.initd.tunnel);
        self.initd.tunnel_host = turl.hostname;
        self.initd.tunnel_port = parseInt(turl.port);
    }

    if ((self.initd.tunnel_host === '') || (self.initd.tunnel_host === '0.0.0.0')) {
        self.initd.tunnel_host = _.ipv4();
    }

    if ((self.initd.host === '') || (self.initd.host === '0.0.0.0')) {
        self.initd.host = _.ipv4();
    }

    // preprocess knx (probably unnecessary for exemplars)
    self.knx_writed = {};
    self.knx_readd = {};

    if (!_.is.Empty(self.initd.knx)) {
        if (_.is.Dictionary(self.initd.knx)) {
            _.mapObject(self.initd.knx, function (coded, code) {
                coded = _.deepCopy(coded);
                coded.code = code;

                if (coded.write) {
                    self.knx_writed[coded.code] = coded;
                }
                if (coded.read) {
                    self.knx_readd[coded.read] = coded;
                }
            });
        }
    }

    if (self.native) {
        self.queue = _.queue("KNXBridge");<commit_msg>IOTDB API was changed<commit_after>/*
 *  KNXBridge.js
 *
 *  <NAME>
 *  IOTDB.org
 *  2015-11-29
 *
 *  Copyright [2013-2015] [<NAME>]
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

"use strict";

var iotdb = require('iotdb');
var _ = iotdb._;
var bunyan = iotdb.bunyan;

var url = require('url');
var knx_js = require('knx.js');

var logger = bunyan.createLogger({
    name: 'homestar-knx',
    module: 'KNXBridge',
});

/*
    localIpAddress, 13671);
  var KnxConnectionTunneling = require('knx.js').KnxConnectionTunneling;
  var connection = new KnxConnectionTunneling('192.168.80.101', 3671, localIpAddress, 13671);
  */

/**
 *  See {iotdb.bridge.Bridge#Bridge} for documentation.
 *  <p>
 *  @param {object|undefined} native
 *  only used for instances, should be 
 */
var KNXBridge = function (initd, native) {
    var self = this;

    self.initd = _.defaults(initd,
        iotdb.keystore().get("bridges/KNXBridge/initd"), {
            host: null,
            port: 3671,
            tunnel: null,
            raw: false, // pass GAs unchanged (debugging mainly)
            uuid: null, // seed for the Thing-ID
            number: 0, // can be used to share a single UUID
            knx: {}, // trés important
        }
    );
    self.native = native; // the thing that does the work - keep this name

    if (self.initd.tunnel) {
        var turl = url.parse(self.initd.tunnel);
        self.initd.tunnel_host = turl.hostname;
        self.initd.tunnel_port = parseInt(turl.port);
    }

    if ((self.initd.tunnel_host === '') || (self.initd.tunnel_host === '0.0.0.0')) {
        self.initd.tunnel_host = _.net.ipv4();
    }

    if ((self.initd.host === '') || (self.initd.host === '0.0.0.0')) {
        self.initd.host = _.net.ipv4();
    }

    // preprocess knx (probably unnecessary for exemplars)
    self.knx_writed = {};
    self.knx_readd = {};

    if (!_.is.Empty(self.initd.knx)) {
        if (_.is.Dictionary(self.initd.knx)) {
            _.mapObject(self.initd.knx, function (coded, code) {
                coded = _.deepCopy(coded);
                coded.code = code;

                if (coded.write) {
                    self.knx_writed[coded.code] = coded;
                }
                if (coded.read) {
                    self.knx_readd[coded.read] = coded;
                }
            });
        }
    }

    if (self.native) {
        self.queue = _.queue("KNXBridge");
{'fraction_non_alphanumeric': 0.1360381861575179, 'fraction_numerical': 0.020456870098874872, 'mean_word_length': 2.2025109170305677, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 6, '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': '5232652', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1905, 'n_words': 486}