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AY,MACtC,EAWA,kBAAkB,UAAU,YAAc,WACtC,IAAI,EAAqB,IAAI,QAAQ,qBASrC,OARA,EACK,kBAAkB,eAAe,aAAc,kBAC/C,kBAAkB,eAAe,MAAO,iBACxC,kBAAkB,eAAe,aAAc,KAAK,YACzD,KAAK,QAAU,IAAI,QAAQ,aAAa,KAAK,MAC7C,KAAK,QACA,kBAAkB,eAAe,gBACjC,GAAG,MAAO,KAAK,SAAS,KAAK,OAC3B,CAAC,EAAoB,KAAK,QACrC,EAEA,kBAAkB,UAAU,SAAW,SAAS,GAC5C,EAAS,KAAM,KAAK,YAAc,EACtC,EAEA,kBAAkB,UAAU,KAAO,WAC/B,KAAK,YAAc,EACnB,KAAK,QAAQ,kBAAkB,eAAe,gBAAgB,YAAgC,GAApB,KAAK,aAC3E,KAAK,SACL,aAAa,KAAK,SAEtB,IAAI,EAAO,KACX,KAAK,QAAU,YAAW,WACtB,EAAK,YAAc,EACnB,EAAK,QAAQ,kBAAkB,eAAe,gBAAgB,YAAgC,GAApB,EAAK,aAC/E,EAAK,QAAU,IACnB,GAAmB,IAAhB,EAAK,SACZ","file":"/npm/homebridge-http-doorbell-v2@1.1.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/homebridge-http-doorbell-v2@1.1.1/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","var Service;\nvar Characteristic;\nvar http = require('http');\n\nmodule.exports = function(homebridge) {\n    Service = homebridge.hap.Service;\n    Characteristic = homebridge.hap.Characteristic;\n\n    homebridge.registerPlatform(\"homebridge-http-doorbell\", \"http-doorbell\", HTTPDoorbell);\n};\n\nfunction HTTPDoorbell(log, config) {\n    this.log = log;\n    this.port = config.port;\n    this.bells = config.doorbells;\n    this.bellsAccessories = [];\n    this.bellsLastRang = [];\n    var self = this;\n    this.server = http.createServer(function(request, response) {\n        self.httpHandler(self, request.url.substring(1));\n        response.end('Handled');\n    });\n    this.server.listen(this.port, function(){\n        self.log(\"Doorbell server listening on: http://<your ip goes here>:%s/<doorbellId>\", self.port);\n    });\n}\n\nHTTPDoorbell.prototype.accessories = function (callback) {\n    var foundAccessories = [];\n    var count = this.bells.length;\n    for (index = 0; index < count; index++) {\n        var accessory = new DoorbellAccessory(this.bells[index]);\n        if (accessory.doorbellId == 0) {\n            accessory.doorbellId = index+1;\n        }\n        this.bellsAccessories[accessory.doorbellId] = accessory;\n        foundAccessories.push(accessory);\n    }\n    callback(foundAccessories);\n}\n\nHTTPDoorbell.prototype.httpHandler = function(that, doorbellId) {\n    if (that.bellsLastRang[doorbellId]) {\n        var diff = new Date().getTime() - that.bellsLastRang[doorbellId];\n        if (diff/1000 < 10) {\n            return;\n        }\n    }\n    that.bellsLastRang[doorbellId] = new Date().getTime();\n    that.bellsAccessories[doorbellId].ring();\n};\n\nfunction DoorbellAccessory(config) {\n    this.name = config[\"name\"];\n    this.duration = config[\"duration\"] || 2;\n    this.doorbellId = config[\"id\"] || 0;\n    this.binaryState = 0;\n    this.service = null;\n    this.timeout = null;\n}\n\nDoorbellAccessory.prototype.getServices = function() {\n    var informationService = new Service.AccessoryInformation();\n    informationService\n        .setCharacteristic(Characteristic.Manufacturer, \"Doorbells Inc.\")\n        .setCharacteristic(Characteristic.Model, \"HTTP Doorbell\")\n        .setCharacteristic(Characteristic.SerialNumber, this.doorbellId);\n    this.service = new Service.MotionSensor(this.name);\n    this.service\n        .getCharacteristic(Characteristic.MotionDetected)\n        .on('get', this.getState.bind(this));\n    return [informationService, this.service];\n}\n\nDoorbellAccessory.prototype.getState = function(callback) {\n    callback(null, this.binaryState > 0);\n}\n\nDoorbellAccessory.prototype.ring = function() {\n    this.binaryState = 1;\n    this.service.getCharacteristic(Characteristic.MotionDetected).updateValue(this.binaryState == 1);\n    if (this.timeout) {\n        clearTimeout(this.timeout);\n    }\n    var self = this;\n    this.timeout = setTimeout(function() {\n        self.binaryState = 0;\n        self.service.getCharacteristic(Characteristic.MotionDetected).updateValue(self.binaryState == 1);\n        self.timeout = null;\n    }, self.duration * 1000);\n}"]}