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m/node-smartcielo-http@0.0.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/node-smartcielo-http@0.0.6/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","#!/usr/bin/env node\n\n/**\n * Includes\n */\nconst commandLineArgs = require('command-line-args');\nconst SmartCielo = require('node-smartcielo');\nvar http = require('http');\n\n/**\n * Constants\n */\n\nconst OPTION_DEFINITIONS = [\n    { name: 'port', alias: 'l', type: String },\n    { name: 'username', alias: 'u', type: String },\n    { name: 'password', alias: 'p', type: String },\n    { name: 'ip', alias: 'i', type: String }\n];\nconst OPTIONS = commandLineArgs(OPTION_DEFINITIONS);\n\n/**\n * Helper Functions\n */\nfunction extractCommandAndValueFromRequest(req, pathComponents) {\n    var command = null;\n    var value = null;\n    pathComponents.forEach(pathComponent => {\n        if ( (req.url === '/' + pathComponent) || (req.url.startsWith('/' + pathComponent + '/')) ) {\n            command = pathComponent;\n            value = req.url.startsWith('/' + pathComponent + '/') ? req.url.replace('/' + pathComponent + '/', '') : null;\n        }\n    });\n    return { command, value };\n}\n\nfunction sendQueryResponse(res, key, value) {\n    res.writeHead(200, { 'Content-Type': 'application/json' });\n    var responseObject = {};\n    responseObject[key] = value;\n    res.write(JSON.stringify(responseObject));\n    res.end();\n}\n\nfunction sendCommandSuccessResponse(res) {\n    res.writeHead(200, { 'Content-Type': 'application/json' });\n    res.write(JSON.stringify({ 'success': true }));\n    res.end();\n}\n\nfunction sendErrorResponse(res, req) {\n    res.end(JSON.stringify({ 'error': 'Invalid Request: ' + req.url }));\n}\n\n/**\n * Main Program\n */\nconst hvac = new SmartCielo(OPTIONS.username, OPTIONS.password, OPTIONS.ip,\n    commandedState => {\n        console.log('Commanded State Change:', JSON.stringify(commandedState));\n    },\n    roomTemperature => {\n        console.log('Updated Room Temperature:', roomTemperature);\n    },\n    err => {\n        console.error('Communication Error:', err);\n    });\nconsole.log('Connecting...');\nhvac.waitForConnection.then(_ => {\n    console.log('Connected.');\n    var server = http.createServer(function (req, res) {\n        console.log('Received request:', req.url);\n        var methodName = null;\n        var error = false;\n        var { command, value } = extractCommandAndValueFromRequest(req, ['power', 'mode', 'roomTemperature', 'temperature', 'fanSpeed']);\n        console.log('Extracted command:', command, 'value:', value);\n        switch (command) {\n            case 'power':\n                switch (value) {\n                    case null: methodName = 'getPower'; break;\n                    case 'off': methodName = 'sendPowerOff'; value = undefined; break;\n                    case 'on': methodName = 'sendPowerOn'; value = undefined; break;\n                    default: error = true; break;\n                }\n                break;\n            case 'mode':\n                switch (value) {\n                    case null: methodName = 'getMode'; break;\n                    case 'cool': methodName = 'sendMode'; break;\n                    case 'dry': methodName = 'sendMode'; break;\n                    case 'fan': methodName = 'sendMode'; break;\n                    case 'auto': methodName = 'sendMode'; break;\n                    case 'heat': methodName = 'sendMode'; break;\n                    default: error = true; break;\n                }\n                break;\n            case 'fanSpeed':\n                switch (value) {\n                    case null: methodName = 'getFanSpeed'; break;\n                    case 'auto': methodName = 'sendFanSpeed'; break;\n                    case 'low': methodName = 'sendFanSpeed'; break;\n                    case 'med': methodName = 'sendFanSpeed'; break;\n                    case 'high': methodName = 'sendFanSpeed'; break;\n                    default: error = true; break;\n                }\n                break;\n            case 'temperature':\n                switch (value) {\n                    case null: methodName = 'getTemperature'; break;\n                    default: methodName = 'sendTemperature'; break;\n                }\n                break;\n            case 'roomTemperature':\n                switch (value) {\n                    case null: methodName = 'getRoomTemperature'; break;\n                    default: error = true; break;\n                }\n                break;\n            default:\n                error = true;\n                break;\n        }\n        if (!error) {\n            if (value === null) {\n                sendQueryResponse(res, command, hvac[methodName]());\n            } else if (value === undefined) {\n                hvac[methodName](_ => { sendCommandSuccessResponse(res); }, err => { console.error(err); });\n            } else {\n                hvac[methodName](value, _ => { sendCommandSuccessResponse(res); }, err => { console.error(err); });\n            }\n        } else {\n            sendErrorResponse(res, req);\n        }\n    });\n    server.listen(OPTIONS.port);\n    console.log('Node.js web server running on port:', OPTIONS.port);\n}, err => {\n    console.error(err);\n});\n"]}