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","$locationProvider",function(a,b){a.when("/",{templateUrl:"views/main.html"}).when("/profiles",{templateUrl:"views/profiles.html"}).when("/schedules",{templateUrl:"views/schedules.html"}).when("/serial",{templateUrl:"views/serial.html"}).when("/about",{templateUrl:"views/about.html"}).otherwise({redirectTo:"/"}),b.hashPrefix("")}]);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};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("MainCtrl",["$scope","$http","$interval","$timeout","$location",function(a,b,c,d,e){const f="#16F",g="#44E",h="#F0F",i="#E44";a.selectedZone=0,a.systemsEdit=null,a.systemsEdited=null,a.mkTime=function(a){return angular.equals({},a)?"00:00":a};var j=angular.fromJson(window.localStorage.getItem("infinitude"))||{};if(a.history){var k=[],l=[[],[]];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&&(k.push(new Date(1e3*b[0]).toLocaleString()),l[0].push(b[1]),l[1].push(a.history.outsideTemp[0].values[c][1]))}),a.oduLabels=k,a.oduSeries=["CoilTemp","OutsideTemp"],a.oduData=l}var m;a.reloadData=function(c){c&&a.systemsEdited&&confirm("This will erase your unsaved changes")&&(a.systemsEdited=null);var e=["systems","status","notifications","energy"];angular.forEach(e,function(c){a.systemsEdited!==!0&&(a.globeColor=f),b.get("/"+c+".json").then(function(b){var e=c;"systems"===e&&(e="system",(a.systemsEdited===!1||null===a.systemsEdited)&&(a.systemsEdit=angular.copy(b.data[e][0]))),a[c]=j[c]=b.data[e][0],a.systemsEdited!==!0&&(a.globeColor=g),d.cancel(m),m=d(function(){a.globeColor=i},24e4)},function(){a.globeColor=i,console.log("oh noes!",arguments)})}),window.localStorage.setItem("infinitude",angular.toJson(j))},a.$watch("systemsEdit",function(){null!==a.systemsEdit&&(null===a.systemsEdited||angular.equals(a.systems,a.systemsEdit)?(a.systemsEdited=!1,a.globeColor=g):a.systemsEdited===!1&&(a.systemsEdited=!0,a.globeColor=h))},!0),a.reloadData(!1),c(a.reloadData,18e4,0,!0,!1),a.isActive=function(a){return a===e.path()},a.save=function(){a.systems=angular.copy(a.systemsEdit);var c={system:[a.systems]};b.post("/systems/infinitude",c).then(function(){setTimeout(function(){a.reloadData(!1)},1e4),a.systemsEdited=!1,a.globeColor=g},function(){console.log("oh noes! save fail.")})},a.selectZone=function(b){a.selectedZone=b},a.equals=function(a,b){return angular.equals(a,b)},a.rawSerial="Loading",a.frames=[],a.state=angular.fromJson(window.localStorage.getItem("infinitude-serial-state"))||{};var n=new WebSocket(wsu("/serial"));n.onopen=function(){console.log("Socket open")},n.onclose=function(){console.log("Socket closed")};var o;n.onmessage=function(b){var c=angular.fromJson(b.data);a.transferColor="#4F4",d.cancel(o),d(function(){a.transferColor="#5E5"},2e3);var e=new jDataView(c.data);if(a.carbus={},a.history=angular.fromJson(window.localStorage.getItem("tmpdat"))||{},c.Function.match(/write|reply/)){var f=toHex(c.data.substring(0,3)),g=c.Function+c.SrcClass+c.DstClass+f;c.Device="reply"===c.Function?c.SrcClass:c.DstClass;var h=function(b,d){a.history[b]=a.history[b]||[{key:b,values:[]}],d=a.carbus[b],a.history[b][0].values.push([c.timestamp,d]),a.history[b][0].values.length>500&&a.history[b][0].values.shift(),window.localStorage.setItem("tmpdat",angular.toJson(a.history))};c.SrcClass.match(/(Furnace|FanCoil)/)&&(f.match(/00 03 06/)&&(a.carbus.blowerRPM=e.getInt16(4),h("blowerRPM")),f.match(/00 03 16/)&&(a.carbus.airflowCFM=e.getInt16(7),h("airflowCFM"))),c.SrcClass.match(/HeatPump/)&&f.match(/00 3E 01/)&&(a.carbus.outsideTemp=e.getInt16(3)/16,a.carbus.coilTemp=e.getInt16(5)/16,h("coilTemp"),h("outsideTemp"));var i=a.state[g]||c;i=i.data,a.state[g]=a.state[g]||{},angular.extend(a.state[g],c),a.state[g].history=a.state[g].history||[],i!==c.data&&a.state[g].history.unshift(i),a.state[g].history.length>9&&a.state[g].history.pop(),window.localStorage.setItem("infinitude-serial-state",angular.toJson(a.state))}a.frames.push(c),a.frames.length>9&&a.frames.shift(),a.$apply()}}]);