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kB,eAAe,mBAAoB,KAAK,aAGxC,MAAxB,KAAK,iBAAmD,MAAxB,KAAK,iBACpC,KAAK,gBACA,kBAAkB,eAAe,wBAAyB,KAAK,SAE5E,EAGA,qBAAqB,UAAU,eAAiB,SAAS,GACrD,EAAS,KAAK,KAAK,YACvB,EAGA,qBAAqB,UAAU,YAAc,SAAS,GAClD,EAAS,KAAK,KAAK,SACvB,EAGA,qBAAqB,UAAU,aAAe,SAAS,GACnD,IAAI,GAAS,EACW,MAArB,KAAK,cAEE,KAAK,aADX,GAAS,EAGF,KAAK,UACZ,GAAS,GAEb,EAAS,KAAK,EAAS,eAAe,kBAAkB,uBAAyB,eAAe,kBAAkB,mBACtH,EAGA,qBAAqB,UAAU,YAAc,WA0BzC,OAzBA,KAAK,mBAAqB,IAAI,QAAQ,qBAEtC,KAAK,mBACF,kBAAkB,eAAe,aAAc,aAC/C,kBAAkB,eAAe,MAAO,4BAA4B,KAAK,SACzE,kBAAkB,eAAe,aAAc,KAAK,MAEvD,KAAK,YAAc,IAAI,QAAQ,kBAE/B,KAAK,YACF,kBAAkB,eAAe,oBACjC,GAAG,MAAO,KAAK,eAAe,KAAK,OAEtC,KAAK,gBAAkB,IAAI,QAAQ,eAEnC,KAAK,gBACA,kBAAkB,eAAe,yBACjC,GAAG,MAAO,KAAK,YAAY,KAAK,OAErC,KAAK,iBAAmB,IAAI,QAAQ,gBAEpC,KAAK,iBACF,kBAAkB,eAAe,mBACjC,GAAG,MAAO,KAAK,aAAa,KAAK,OAE7B,CAAC,KAAK,mBAAoB,KAAK,YAAa,KAAK,iBAAkB,KAAK,gBACnF,EAEA,OAAO,QAAQ,SAAW,oBAC1B,OAAO,QAAQ,UAAY","file":"/npm/homebridge-wireless-sensor-tag@0.0.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/homebridge-wireless-sensor-tag@0.0.4/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/*\n See README.md\n */\n\nvar Service, Characteristic, types;\n\nvar request = require('request');\n\n// Handle registration with homebridge\nmodule.exports = function(homebridge) {\n  Service = homebridge.hap.Service;\n  Characteristic = homebridge.hap.Characteristic;\n  types = homebridge.hapLegacyTypes;\n  homebridge.registerPlatform(\"homebridge-wireless-sensor-tag\", \"wireless-sensor-tag\", WirelessTagPlatform);\n}\n\n// Platform object for the wireless tags. Represents the wireless tag manager\nfunction WirelessTagPlatform(log,config) {\n\tthis.username = config.username;\n\tthis.password = config.password;\n\tthis.queryFrequency = config.queryFrequency;\n    this.log = log;\n    this.tagMap = {};\n    this.tagList = [];\nis}\n\nWirelessTagPlatform.prototype.shouldIgnore = function(deviceData) {\n    if(deviceData != undefined && deviceData.name != undefined) {\n        if(this.ignoreList.indexOf(deviceData.name) > -1) {\n            return true;\n        }\n    }\n    return false;\n}\n\n// Forms a valid request to authenticate against the wireless tag manager. Calls handleResult with a boolean indicating\n// success or failure.\nWirelessTagPlatform.prototype.sendAuthentication = function(handleResult) {\n    request({\n        method: 'POST',\n        uri: 'http://www.mytaglist.com/ethAccount.asmx/Signin',\n        json: true,\n        jar: true,\n        gzip: true,\n        body: { email: this.username, password: this.password }\n    }, function (error, response, body) {\n        if(error) {\n            handleResult(true);\n        } else {\n            handleResult(response.statusCode!=200);\n        }\n    });\n}\n\n// Forms a valid request to get the latest tag list. Calls handleResult with a boolean indicating success or failure.\nWirelessTagPlatform.prototype.getTagList = function(handleResult) {\n    request({\n        method: 'POST',\n        uri: 'http://www.mytaglist.com/ethClient.asmx/GetTagList2',\n        json: true,\n        jar: true,\n        gzip: true,\n        body: {}\n    }, function (error, response, body) {\n        if(error) {\n            handleResult(true,body);\n        } else {\n            handleResult(response.statusCode!=200,body);\n        }\n    });\n}\n\n// Does a request to the server to refresh the tag data. Authenticate every time as not sure how often the \n// authentication requires refreshing. New tags we see get added to the tag map and the tag list. New tags\n// added AFTER startup will be tracked internally but not exposed as a device as frankly I don't know how\n// to do that dynamically.\nWirelessTagPlatform.prototype.refreshTagData = function(complete) {\n    var that = this;\n    // Auth\n    this.sendAuthentication(function(failed) {\n        if(!failed) {\n            // Gets the tag list\n            that.getTagList(function(innerFailure, body) {\n                if(!innerFailure) {\n                    for(var index = 0; index < body.d.length; index++) {\n                        var uuid = body.d[index].uuid;\n                        // We haven't seen the tag yet, add it\n                        if(that.tagMap[uuid] == null) {\n                            if(!that.shouldIgnore(body.d[index])) {\n                                var newTag = new WirelessTagAccessory(that.log, body.d[index]);\n                                that.tagMap[uuid] = newTag;\n                                that.tagList.push(newTag);\n                            }\n                        // We have, just update it.\n                        } else {\n                            that.tagMap[uuid].handleUpdate(body.d[index]);\n                        }\n                    }\n                    complete(true);\n                } else {\n                    that.log(\"Failed getting tag list\");\n                    complete(false);\n                }\n            }); \n        } else {\n            that.log(\"Failed authenticating to tag list\");\n            complete(false);\n        }   \n    });\n}\n\n// Handles the periodic timer. Reports success or failure and sets the next timer period.\nWirelessTagPlatform.prototype.handleTimer = function() {\n    var that = this;\n    this.log(\"Starting update of wireless tags from tag manager\");\n    this.refreshTagData(function(success) {\n        if(success) {\n            that.log(\"Updated wireless tag data\");\n        } else {\n            that.log(\"Failed to update wireless tags\");\n        }\n        // Hack as I was seeing issues with an undefined queryFrequency. Believe I have fixed it but keeping the \n        // minimum in to keep us from spamming the service. Also prevents values below 5000ms.\n        if(that.queryFrequency == undefined || that.queryFrequency < 5000) {\n            that.log(\"Error ... invalid query frequency, setting to 20000ms default\");\n            that.queryFrequency = 20000;\n        } else {\n            setTimeout(that.handleTimer.bind(that), that.queryFrequency);\n        }\n    });\n}\n\n// Responds to the homebridge platform through calling callback once list of accessories is identified.\nWirelessTagPlatform.prototype.accessories = function(callback) {\n    var that = this;\n    that.refreshTagData(function(success) {\n        that.log(\"Completed getting devices. Result=\"+success); \n        if(success) {\n            that.log(\"Authenticated and got tag list. Enumerating tags as accessories\");\n            that.handleTimer();\n            callback(that.tagList);\n        } else {\n            that.log(\"Could not get tags, no accessories exposed\");\n            callback([]);\n        }\n    });    \n}\n\n// Represents a single tag\nfunction WirelessTagAccessory(log,deviceData) {\n    this.log = log;\n    this.handleUpdate(deviceData);\n}\n\n// Refreshes tag data from the device update data\nWirelessTagAccessory.prototype.handleUpdate = function(deviceData) {\n    this.isOutOfRange = deviceData.OutOfRange;\n    this.isAlive = deviceData.alive;\n    this.batteryRemaining = deviceData.batteryRemaining;\n    this.uuid = deviceData.uuid;\n    this.tagType = deviceData.tagType;\n    this.temperature = deviceData.temperature;\n    this.name = deviceData.name;\n    if(deviceData.cap != undefined) {\n        this.humidity = Math.round(deviceData.cap);\n    } else {\n        this.humidity = 0.0;\n    }\n    this.uuid_base = this.uuid;\n    \n    // Protections to ensure we don't set the current characteristic value whens services are not yet registered.\n    if(this.tempService != null && this.tempService != undefined) {\n        this.tempService\n            .setCharacteristic(Characteristic.CurrentTemperature, this.temperature);    \n    }\n\n    if(this.humidityService != null && this.humidityService != undefined) {\n        this.humidityService\n            .setCharacteristic(Characteristic.CurrentRelativeHumidity, this.humidity);\n    }\n}\n\n// Handles getting the temperature in format needed by homebridge. Luckily this is just the raw value in degrees C\nWirelessTagAccessory.prototype.getTemperature = function(callback) {\n    callback(null,this.temperature);\n}\n\n// Handles getting the humidity in format needed by homebridge.\nWirelessTagAccessory.prototype.getHumidity = function(callback) {\n    callback(null,this.humidity);\n}\n\n// Translates tag state into an occupancy value. If tag is inactive or out of range occupancy is false\nWirelessTagAccessory.prototype.getOccupancy = function(callback) {\n    var isAway = false;\n    if(this.isOutOfRange == undefined) {\n        isAway = true;\n    } else if(this.isOutOfRange) {\n        isAway = true;\n    } else if(!this.isAlive) {\n        isAway = true;\n    }\n    callback(null,isAway ? Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED : Characteristic.OccupancyDetected.OCCUPANCY_DETECTED);\n}\n\n// Sets up the information, temperature and occupancy services.\nWirelessTagAccessory.prototype.getServices = function() {\n    this.informationService = new Service.AccessoryInformation();\n\n    this.informationService\n      .setCharacteristic(Characteristic.Manufacturer, \"SmartHome\")\n      .setCharacteristic(Characteristic.Model, \"Wireless Sensor Tag Type=\"+this.tagType)\n      .setCharacteristic(Characteristic.SerialNumber, this.uuid);   \n\n    this.tempService = new Service.TemperatureSensor();\n      \n    this.tempService\n      .getCharacteristic(Characteristic.CurrentTemperature)\n      .on('get', this.getTemperature.bind(this));\n\n    this.humidityService = new Service.HumiditySensor();\n\n    this.humidityService\n        .getCharacteristic(Characteristic.CurrentRelativeHumidity)\n        .on('get', this.getHumidity.bind(this));\n      \n    this.occupancyService = new Service.OccupancySensor();\n    \n    this.occupancyService\n      .getCharacteristic(Characteristic.OccupancyDetected)\n      .on('get', this.getOccupancy.bind(this));\n\n    return [this.informationService, this.tempService, this.occupancyService, this.humidityService];\n}\n\nmodule.exports.platform = WirelessTagPlatform;\nmodule.exports.accessory = WirelessTagAccessory;\n\n\n\n"]}