function GroupDeviceController(e){function r(e,t,n){var r="";for(var i in e.roles){var s=funcObj.devCon.getDevice(e.roles[i]),o;s&&(o=s.ip),r+=funcObj.messageCon.getContent("addGroupRole",{ROLE:i.toUpperCase(),UID:e.roles[i],IPADDRESS:o},!1)}var u="updateGroup",a="updateGroup";e.groupID||(u="addGroup",a="addGroup"),d({uID:e.groupMaster,path:u,rootNode:a,obj:{GROUPID:e.groupID,GROUPNAME:funcObj.UIMain.minEscape(e.groupName),GROUPMASTER:e.groupMaster,ROLES:r},esc:!1,onSuccess:t,onFailure:n})}function i(e,t,n){s(e)}function s(e){d({uID:e,path:"getGroup"})}function o(t,n){var r=$(n).attr("id");if(!r){var i=e.getGroupByUID(t);i&&e.removeGroup({groupID:i.groupID,originType:"device",originUID:t})}else{var s=$(n).children("name").text(),o=$(n).children("masterDeviceId").text(),u=$(n).children("status").text(),a={},f=$(n).children("roles").children("groupRole");f.length>0?(f.each(function(){var e=$(this).children("role").text().toLowerCase(),t=$(this).children("deviceId").text();a[e]=t}),e.updateGroup({groupID:r,groupName:s,groupMaster:o,groupStatus:u,roles:a,originType:"device",originUID:t}),t===o?g(t):o===funcObj.UIMain.getUID()&&funcObj.devCon.sendMsg(o,"nowPlaying")):e.removeGroup({groupID:r,originType:"device",originUID:t})}}function u(e,t,n){d({uID:e.groupMaster,path:"removeGroup",onSuccess:t,onFailure:function(r,i,s){s==="nosocket"?a(e,t,n):n&&n(r,i,s)}})}function a(t,n,r){t.authLevel=0;for(var i in t.roles)if(t.roles[i]!==t.groupMaster){d({uID:t.roles[i],path:"removeGroup",onSuccess:n,onFailure:function(i,s,o){o==="nosocket"?e.groupCloudController.removeCloudGroup(t,n,r):r&&r(i,s,o)}});break}}function f(t,n){var r=e.getGroupByUID(t);r&&e.removeGroup({groupID:r.groupID,originType:"device",originUID:t})}function l(e,t){for(var r in e)(!t||e[r]!==t)&&d({uID:e[r],path:"setupGroup",rootNode:"groupSetupReady",obj:{TIMEOUT:n.toString()}});return n}function c(e){for(var t in e)d({uID:e[t],path:"setupGroup",rootNode:"groupSetupExit"})}function h(e){for(var t in e)d({uID:e[t],path:"setupGroup",rootNode:"groupSetupComplete"})}function p(e){var r=e.uID,i=e.onSuccess,s=e.onFailure,o=e.role,u=v(i,s,t);d({uID:r,path:"setupGroup",rootNode:"groupSetupSelected",obj:{TIMEOUT:n.toString()},callbackFunc:u});var a=function(){u(null,null,!0)};return a}function d(e){var n=e.uID,r=e.path,i=e.rootNode,s=e.obj,o=e.type,u=e.esc,a=e.toHamburg,f=e.extraHeaderAttributes,l=e.onSuccess,c=e.onFailure,h=funcObj.devCon.getDevice(n);if(h&&h.sObj&&h.sObj.getSocketState()){var p=typeof e.callbackFunc=="function"?e.callbackFunc:v(e.onSuccess,e.onFailure,t);funcObj.devCon.sendMsg(n,r,i,s,o,u,a,f,p)}else c&&c(null,null,"nosocket")}function v(e,t,n){var r=0,i=!1;n&&(r=setTimeout(function(){i||(t&&t(null,null,"timeout"),i=!0)},n));var s=function(n,s,o){i||(clearTimeout(r),o||($(s).find("error").length<1?e&&e(n,s):t&&t(n,s,"error")),i=!0)};return s}function m(t,n){var r=e.getGroupByUID(t);if(r){var i={min:parseInt($(n).children("balanceMin").text()),max:parseInt($(n).children("balanceMax").text()),"default":parseInt($(n).children("balanceDefault").text()),target:parseInt($(n).children("targetBalance").text()),actual:parseInt($(n).children("actualBalance").text())};e.updateGroup({groupID:r.groupID,balance:i,originType:"device",originUID:t})}}function g(e){d({uID:e,path:"balance"})}function y(e,t){d({uID:e,path:"balance",rootNode:"balanceSet",obj:{VALUE:t.toString()}})}var t=15e3,n=3e5;this.deviceCompletionSequence=h,this.devicePrepareForSelection=l,this.deviceSelect=p,this.deviceUnPrepareForSelection=c,this.fetchDeviceGroup=s,this.parseDeviceError=i,this.parseDeviceGroup=o,this.parseRemoveDeviceGroup=f,this.removeDeviceGroup=u,this.updateDeviceGroup=r,this.parseBalance=m,this.fetchBalance=g,this.setBalance=y};