-
Notifications
You must be signed in to change notification settings - Fork 72
/
light_bulb_1.json
18 lines (18 loc) · 4.85 KB
/
light_bulb_1.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"alias": "light_bulb_1",
"name": "Light Bulb 1",
"descriptor": {
"type": "latest",
"sizeX": 9,
"sizeY": 9.5,
"resources": [],
"templateHtml": "<img id=\"myImage\" src=\"//sre-solutions.com/static/tb-widget/pic_bulboff.gif\" width=\"100\" height=\"180\">\r\n",
"templateCss": "#myImage {\r\n\r\n top: 50%;\r\n transform: translate(-50%, -50%);\r\n position: absolute;\r\n left: 50%;\r\n}",
"controllerScript": "\n\n\n\nself.onInit = function() {\n var settings = self.ctx.settings;\n var scope = self.ctx.$scope;\n \n \n $('#myImage', self.ctx.$container).click(function(e){\n if ( $('#myImage', self.ctx.$container)[0].src.includes(\"bulbon\"))\n {\n $('#myImage', self.ctx.$container)[0].src = \"//sre-solutions.com/static/tb-widget/pic_bulboff.gif\"\n requestChange(0,false);\n }\n else\n {\n $('#myImage', self.ctx.$container)[0].src = \"//sre-solutions.com/static/tb-widget/pic_bulbon.gif\"\n requestChange(0,true);\n }\n });\n \n function requestChange(g, value)\n {\n\n var method = settings.changeRequestMethod;\n \n var paramsBody = value;\n \n \n var $injector = self.ctx.$injector;\n let deviceService =self.ctx.deviceService;\n \n if (self.ctx.datasources.length > 0)\n {\n var dataKeyCounter = 0;\n var entityId = self.ctx.datasources[0].entityId\n \n var requestBody = {\n method: method,\n params: paramsBody\n \n }\n \n console.log(deviceService);\n \n \n deviceService.sendOneWayRpcCommand(entityId, requestBody).subscribe((responseBody) => {});\n }\n }\n \n \n\n\n}\n\nself.onDataUpdated = function() {\n \n \n console.log (self.ctx);\n var settings = self.ctx.settings;\n var value = 0;\n \n if (self.ctx.defaultSubscription.data.length > 0)\n {\n \n if (self.ctx.defaultSubscription.data.length > 0)\n {\n if (self.ctx.defaultSubscription.data[0].data.length > 0)\n value = parseInt(self.ctx.defaultSubscription.data[0].data[0][1]);\n \n if (value > 0)\n {\n $('#myImage', self.ctx.$container)[0].src = \"//sre-solutions.com/static/tb-widget/pic_bulbon.gif\"\n }\n else\n {\n $('#myImage', self.ctx.$container)[0].src = \"//sre-solutions.com/static/tb-widget/pic_bulboff.gif\"\n }\n\n }\n \n \n \n \n }\n \n function isNumber(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n}\n\nself.onResize = function() {\n if (self.ctx.width < parseInt(self.ctx.height) + 50 + \"px\")\n {\n $('#myImage', self.ctx.$container)[0].style.width = self.ctx.width + \"px\";\n $('#myImage', self.ctx.$container)[0].style.height = \"auto\";\n }\n else\n {\n $('#myImage', self.ctx.$container)[0].style.width = \"auto\";\n $('#myImage', self.ctx.$container)[0].style.height = self.ctx.height + \"px\";\n }\n}\n\nself.onDestroy = function() {\n}\n",
"settingsSchema": "{\n \"schema\": {\n \"type\": \"object\",\n \"title\": \"Settings\",\n \"properties\": {\n \n \"requestTimeout\": {\n \"title\": \"RPC request timeout\",\n \"type\": \"number\",\n \"default\": 500\n },\n \"changeRequestMethod\": {\n \"title\": \"Change request Method\",\n \"type\": \"string\",\n \"default\": \"setValue\"\n }\n },\n \"required\": [\n \"requestTimeout\",\n \"changeRequestMethod\"\n\n ]\n },\n \"form\": [\n \"requestTimeout\",\n \"changeRequestMethod\"\n ]\n}",
"dataKeySettingsSchema": "{}\n",
"defaultConfig": "{\"datasources\":[{\"type\":\"function\",\"name\":\"function\",\"entityAliasId\":null,\"filterId\":null,\"dataKeys\":[{\"name\":\"f(x)\",\"type\":\"function\",\"label\":\"Random\",\"color\":\"#2196f3\",\"settings\":{},\"_hash\":0.15479322438769105,\"funcBody\":\"var value = prevValue + Math.random() * 100 - 50;\\nvar multiplier = Math.pow(10, 2 || 0);\\nvar value = Math.round(value * multiplier) / multiplier;\\nif (value < -1000) {\\n\\tvalue = -1000;\\n} else if (value > 1000) {\\n\\tvalue = 1000;\\n}\\nreturn value;\",\"units\":null,\"decimals\":null,\"usePostProcessing\":null,\"postFuncBody\":null}]}],\"timewindow\":{\"realtime\":{\"timewindowMs\":60000}},\"showTitle\":true,\"backgroundColor\":\"#fff\",\"color\":\"rgba(0, 0, 0, 0.87)\",\"padding\":\"8px\",\"settings\":{},\"title\":\"Light Bulb 1\"}"
},
"image": null,
"description": null
}