-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermostat_2.json
18 lines (18 loc) · 5.6 KB
/
thermostat_2.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"alias": "thermostat_2",
"name": "Thermostat 2",
"descriptor": {
"type": "rpc",
"sizeX": 7,
"sizeY": 6,
"resources": [],
"templateHtml": "<div class=\"thermostat\">\r\n\r\n <div class=\"control up\">\r\n <i class=\"fa fa-plus fa-fw\"></i>\r\n </div>\r\n\r\n <div class=\"temperature\">\r\n <span class=\"degrees\"></span><span>°</span>\r\n </div>\r\n\r\n <div class=\"control down\">\r\n <i class=\"fa fa-minus fa-fw\"></i>\r\n </div>\r\n\r\n</div>",
"templateCss": "#container {\n\t background: #b197fc;\n\t background: linear-gradient(to right, #d0bfff, #9775fa);\n\t color: #7950f2;\n}\n .thermostat {\n\t position: absolute;\n\t left: 50%;\n\t top: 50%;\n\t transform: translateX(-50%) translateY(-50%);\n}\n .thermostat .temperature {\n\t font-size: 100px;\n\t font-weight: 600;\n\t text-align: center;\n}\n .thermostat .temperature span::selection {\n\t background: transparent;\n}\n .thermostat .control {\n\t font-size: 32px;\n\t text-align: center;\n}\n .thermostat .control i:hover {\n\t cursor: pointer;\n}\n ",
"controllerScript": "var namespace;\nvar cssParser = new cssjs();\n\nvar number = 20;\n\nself.onInit = function() {\n var settings = self.ctx.settings;\n var move_unit = 1;\nif (settings.stepWidth == '0.1')\n move_unit = 0.1;\n\nrequestStatus();\n \n requestStatus()\n \n \n const temperature = document.querySelector(\".degrees\")\nconst up = document.querySelector(\".up i\")\nconst down = document.querySelector(\".down i\")\n\n\n\ntemperature.innerHTML = number\n\nfunction hotter() {\n up.style.opacity = \"1\"\n down.style.opacity = \"1\"\n\n if (number < settings.maxValue) {\n number = number + move_unit;\n temperature.innerHTML = number.toFixed(1);\n }\n\n if (number === settings.maxValue) {\n up.style.opacity = \"0.5\"\n }\n \n sendValue();\n \n}\n\nfunction colder() {\n up.style.opacity = \"1\"\n down.style.opacity = \"1\"\n\n if (number > settings.minValue) {\n number = number - move_unit;\n temperature.innerHTML = number.toFixed(1);\n }\n\n if (number === settings.minValue) {\n down.style.opacity = \"0.5\"\n }\n \n sendValue();\n \n \n \n \n \n}\n\nup.addEventListener(\"click\", hotter)\ndown.addEventListener(\"click\", colder)\n\n sendValue = function() {\n var settings = self.ctx.settings;\n var method = settings.changeRequestMethod;\n \n var paramsBody = number.toFixed(1);\n \n \n \n self.ctx.controlApi.sendTwoWayCommand(method, \n paramsBody, settings.requestTimeout)\n .subscribe(\n function success(responseBody) {\n \n }\n );\n}\n\n\nfunction requestStatus() {\n method = settings.statusRequestMethod;\n timeout = settings.requestTimeout;\n paramsBody = \"\";\n self.ctx.controlApi.sendTwoWayCommand(method, \n paramsBody, \n timeout)\n .subscribe(\n function success(responseBody) {\n number = parseFloat(responseBody); \n if (number < settings.min)\n number = settings.min;\n if (number > settings.max)\n number = settings.max;\n temperature.innerHTML = number;\n }\n );\n}\n\n\n}\n\n\n\nself.onResize = function() {\n}\n\nself.onDestroy = function() {\n}\n",
"settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"Settings\",\n \"properties\": {\n \"minValue\": {\n \"title\": \"Minimum Value\",\n \"type\": \"number\",\n \"default\": 0\n },\n \"maxValue\": {\n \"title\": \"Maximum Value\",\n \"type\": \"number\",\n \"default\": 100\n },\n \"stepWidth\": {\n \"title\": \"Step Width\",\n \"type\": \"string\",\n \"enum\": [\n \"0.1\",\n \"1\"],\n \"default\": \"1\"\n },\n\n \"requestTimeout\": {\n \"title\": \"RPC request timeout\",\n \"type\": \"number\",\n \"default\": 500\n },\n \"statusRequestMethod\": {\n \"title\": \"Status request Method\",\n \"type\": \"string\",\n \"default\": \"getValue\"\n },\n \"changeRequestMethod\": {\n \"title\": \"Change request Method\",\n \"type\": \"string\",\n \"default\": \"setValue\"\n },\n \"required\": [\n \"requestTimeout\",\n \"statusRequestMethod\",\n \"changeRequestMethod\"\n ]\n }\n },\n \"form\": [\n \"minValue\",\n \"maxValue\",\n \"stepWidth\",\n \"requestTimeout\",\n \"statusRequestMethod\",\n \"changeRequestMethod\"\n ]\n\n}",
"dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"targetDeviceAliases\":[],\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"0px\",\"settings\":{\"requestTimeout\":500,\"maxValue\":100,\"stepWidth\":\"1\",\"statusRequestMethod\":\"getValue\",\"changeRequestMethod\":\"setValue\",\"minValue\":0},\"title\":\"Thermostat 2\",\"targetDeviceAliasIds\":[\"ce1ae231-5815-c34b-e94d-4edea4b1533b\"]}"
},
"image": null,
"description": null
}