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

"use strict";function bbInitMeta(){app.Device=Backbone.Model.extend(),app.DeviceCollection=Backbone.Collection.extend({name:"devices"}),app.devices=new app.DeviceCollection,app.listenTo(app.sensors,"add",addSensor),app.listenTo(app.sensors,"remove",function(sensor){var model=app.devices.findWhere({id:sensor.get("uniqueid")});model&&app.devices.remove(model);sessionStorage.setItem("app.devices",JSON.stringify(app.devices.toJSON()))});var cache=sessionStorage.getItem("app.devices");function addSensor(sen){if("ZHASwitch"!==sen.get("type")&&"ZGPSwitch"!==sen.get("type")&&"ZLLSwitch"!==sen.get("type"))return;let uniqueid=sen.get("uniqueid"),mac=sen.get("mac"),url=`//${app.session.gw}/api/${app.apikey}/devices/${uniqueid}/state/buttonevent/introspect`;callApi(url).then(res=>{if(res.buttons){res.uniqueid=uniqueid,mac&&(res.mac=mac);var model=new app.Device({id:res.uniqueid,...res});app.devices.contains(model)||app.devices.add(model)}}).then(()=>sessionStorage.setItem("app.devices",JSON.stringify(app.devices.toJSON()))).catch(console.log)}cache?app.devices.add(JSON.parse(cache)):app.sensors.forEach(sen=>{addSensor(sen)})}var callApi=url=>new Promise((resolve,reject)=>{const xhr=new XMLHttpRequest;xhr.open("GET",url,!0),xhr.setRequestHeader("Content-type","application/json; charset=utf-8"),xhr.setRequestHeader("Accept",apiversion),xhr.send(),xhr.onreadystatechange=(e=>{if(4==xhr.readyState){let res=xhr.responseText||"{}";res=JSON.parse(res),resolve(res)}})});