text: "use strict";function wsu(a){var b=window.location;return("https:"===b.protocol?"wss://":"ws://")+b.hostname+(80!==b.port&&443!==b.port?":"+b.port:"")+a}angular.module("infinitude",["ngCookies","ngResource","ngSanitize","ngRoute","yaru22.angular-timeago","angular-dialgauge","jkuri.timepicker","chart.js"]).config(["$routeProvider",function(a){a.when("/",{templateUrl:"views/main.html",controller:"MainCtrl"}).when("/profiles",{templateUrl:"views/profiles.html",controller:"MainCtrl"}).when("/schedules",{templateUrl:"views/schedules.html",controller:"MainCtrl"}).when("/serial",{templateUrl:"views/serial.html",controller:"SerialCtrl"}).when("/about",{templateUrl:"views/about.html",controller:"MainCtrl"}).otherwise({redirectTo:"/"})}]),angular.module("infinitude").controller("MainCtrl",["$scope","$http","$interval","$timeout","$location",function(a,b,c,d,e){a.debounce=0,a.carbus=a.carbus||{},a.empty=function(a){console.log(a)},a.mkTime=function(a){return angular.equals({},a)?"00:00":a};var f=angular.fromJson(window.localStorage.getItem("infinitude"))||{};if(a.history){var g=[],h=[[],[]];angular.forEach(a.history.coilTemp[0].values,function(b,c){var d=a.history.coilTemp[0].values.length,e=Math.round(d/20);c%e==0&&(g.push(new Date(1e3*b[0]).toLocaleString()),h[0].push(b[1]),h[1].push(a.history.outsideTemp[0].values[c][1]))}),a.oduLabels=g,a.oduSeries=["CoilTemp","OutsideTemp"],a.oduData=h}var i;a.reloadData=function(){a.debounce>0&&(a.debounce=a.debounce-1);var c=["systems","status","notifications","energy"];angular.forEach(c,function(c){a.globeColor="#16F",b.get("/"+c+".json").success(function(b){var e=c;"systems"===e&&(e="system"),a[c]=f[c]=b[e][0],a.globeColor="#44E",d.cancel(i),i=d(function(){a.globeColor="#E44"},24e4)}).error(function(){a.globeColor="#E44",console.log("oh noes!",arguments)})}),window.localStorage.setItem("infinitude",angular.toJson(f))},a.$watch("systems",function(b,c){b!==c&&(a.debounce=a.debounce+1)},!0),a.reloadData(),c(a.reloadData,18e4),a.isActive=function(a){return a===e.path()},a.save=function(){var c={system:[a.systems]};b.post("/systems/infinitude",c).success(function(){a.debounce=0,setTimeout(function(){0==a.debounce&&a.reloadData()},1e4)}).error(function(){console.log("oh noes! save fail.")})}}]);var toHex=function(a){for(var b="",c=0;c<a.length;c++)b+=" "+("0"+a.charCodeAt(c).toString(16).toUpperCase()).substr(-2,2);return b},serial;angular.module("infinitude").filter("markDiff",function(){return function(a,b){if(!b)return a;for(var c=!1,d="",e=0;e<a.length;e++)a.charCodeAt(e)!==b.charCodeAt(e)&&c===!1&&(c=!0,d+='<span class="diff">'),a.charCodeAt(e)===b.charCodeAt(e)&&c===!0&&(c=!1,d+="</span>"),d+=a.substr(e,1);return c&&(d+="</span>"),d}}).filter("subStr",function(){return function(a,b,c){return a?a.substr(b,c):""}}).filter("strings",function(){return function(a,b){b=b||4;for(var c=0,d=!1,e="",f="",g=0;g<a.length;g++)0===a.charCodeAt(g)&&d&&(f+=e+"\n"),a.charCodeAt(g)>=32&&a.charCodeAt(g)<=127?(e+=a.substr(g,1),c+=1,c>=b&&(d=!0)):(c=0,d=!1,e="");return f}}).filter("toHex",function(){return toHex}).filter("toList",function(){return function(a){var b=[];return angular.forEach(a,function(a){b.push(a)}),b}}).controller("SerialCtrl",["$scope","$rootScope","$timeout",function(a,b,c){a.rawSerial="Loading",a.frames=[],a.state=angular.fromJson(window.localStorage.getItem("infinitude-serial-state"))||{},serial=serial||new WebSocket(wsu("/serial")),serial.onopen=function(){console.log("Socket open")},serial.onclose=function(){console.log("Socket closed")};var d;serial.onmessage=function(e){var f=angular.fromJson(e.data);b.transferColor="#4F4",c.cancel(d),c(function(){b.transferColor="#5E5"},2e3);var g=new jDataView(f.data);if(b.carbus=b.carbus||{},b.history=b.history||angular.fromJson(window.localStorage.getItem("tmpdat"))||{},f.Function.match(/write|reply/)){var h=toHex(f.data.substring(0,3)),i=f.Function+f.SrcClass+f.DstClass+h;f.Device="reply"==f.Function?f.SrcClass:f.DstClass;var j=function(a,c){b.history[a]=b.history[a]||[{key:a,values:[]}],c=b.carbus[a],b.history[a][0].values.push([f.timestamp,c]),b.history[a][0].values.length>500&&b.history[a][0].values.shift(),window.localStorage.setItem("tmpdat",angular.toJson(b.history))};f.SrcClass.match(/(Furnace|FanCoil)/)&&(h.match(/00 03 06/)&&(b.carbus.blowerRPM=g.getInt16(4),j("blowerRPM")),h.match(/00 03 16/)&&(b.carbus.airflowCFM=g.getInt16(7),j("airflowCFM"))),f.SrcClass.match(/HeatPump/)&&h.match(/00 3E 01/)&&(b.carbus.outsideTemp=g.getInt16(3)/16,b.carbus.coilTemp=g.getInt16(5)/16,j("coilTemp"),j("outsideTemp"));var k=a.state[i]||f;k=k.data,a.state[i]=a.state[i]||{},angular.extend(a.state[i],f),a.state[i].history=a.state[i].history||[],k!==f.data&&a.state[i].history.unshift(k),a.state[i].history.length>9&&a.state[i].history.pop(),window.localStorage.setItem("infinitude-serial-state",angular.toJson(a.state))}a.frames.push(f),a.frames.length>9&&a.frames.shift(),a.$apply()}}]);