/*! phoscon-app 2025-10-13 */

"use strict";function bbInitRooms(){let pollBusy=!1,pollQueue=[],pollTimer=null;function processPoll(){if(pollTimer=null,pollBusy||0===pollQueue.length)return;pollBusy=!0;let r=pollQueue.shift();pollQueue.length>3&&(console.log("poll /rooms instead",pollQueue.length,"single requests"),pollQueue=[],r=app.rooms),restGetResource(r).catch(console.log).then(()=>{pollBusy=!1,pollQueue.length>0&&(pollTimer=setTimeout(processPoll,50))})}app.api.on("event",function(e){if("rooms"===e.r)if("added"!==e.e){if("changed"===e.e){var r=app.rooms.get(e.id);if(r){e.name&&r.set({name:e.name}),pollQueue.push(r),pollTimer||(pollTimer=setTimeout(processPoll,5e3));var args={};_.map(e,function(val,key){if(r.has(key)){if("state"===key){var mod=!1,state=r.attributes.state;return _.map(val,function(val2,key2){state[key2]!==val2&&(state[key2]=val2,mod=!0)}),void(mod&&(g.unset("state",{silent:!0}),g.set({state:state})))}r.get(key)!==val&&(args[key]=val)}}),r.set(args)}}}else app.rooms.fetch()});var Room=Backbone.Model.extend({sync:function(method,model,options){return"patch"===method&&(method="update"),Backbone.sync(method,model,options)},initialize:function(){}});app.RoomCollection=Backbone.Collection.extend({name:"rooms",model:Room,url:"//"+app.session.gw+"/api/"+app.apikey+"/groups",parse:function(groups){if(!app.groups)return;let roomlist=app.groups.filter(group=>"Room"===group.get("type"));return _.map(roomlist,function(room,i){return room.id=room.get("id"),app.resourcelinks&&app.resourcelinks.models.every(rl=>{if(6e3===rl.get("classid")&&rl.get("name")==="room "+room.get("id")){var gids=[],lids=[],sids=[],tids=[],bids=[];return rl.get("links").forEach(l=>{-1!==l.indexOf("/groups/")?gids.push(l.slice(l.lastIndexOf("/")+1)):-1!==l.indexOf("/sensors/")?sids.push(l.slice(l.lastIndexOf("/")+1)):-1!==l.indexOf("/lights/")?lids.push(l.slice(l.lastIndexOf("/")+1)):-1!==l.indexOf("/thermostats/")?tids.push(l.slice(l.lastIndexOf("/")+1)):-1!==l.indexOf("/blinds/")&&bids.push(l.slice(l.lastIndexOf("/")+1))}),room.set("groups",gids),room.set("lights",lids),room.set("sensors",sids),room.set("thermostats",tids),room.set("blinds",bids),!1}return!0}),room})}}),app.groups&&restGetResource(app.groups).then(()=>{app.rooms=new app.RoomCollection}).then(()=>{var cache=sessionStorage.getItem("app.rooms");cache&&app.rooms.reset(JSON.parse(cache))}).catch(e=>{console.log(e)})}