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

"use strict";function bbInitBlinds(){function createBlindFromLight(l){if(!l.modelid)return;var product=getDeviceProductName(l)||l.modelid,sensorAttributes=function(l){let mac=l.uniqueid.split("-")[0]||-1,state=app.sensors.filter(sensor=>{sensor.uniqueid&&sensor.get("uniqueid").indexOf(mac)}).map(s=>s.get("state"));return Object.assign({},...state)}(l);Object.assign(l.state,sensorAttributes);let mac=l.uniqueid.split("-")[0];return app.blinds.add({id:l.id,state:l.state,name:l.name,type:l.type,modelid:l.modelid,manufacturername:l.manufacturername,reachable:!("reachable"in l.state)||l.state.reachable,swversion:l.swversion||"unknown",product:product,mac:mac})}function addLight(light,collection){if(light.isNew())setTimeout(()=>addLight(light),100);else{var s=_.clone(light.attributes),info=getDeviceInfoMap(s);if(info&&info.type===DEV_TYPE_BLIND){var bl=createBlindFromLight(s);app.api.trigger("blind-added",bl)}}}app.Blind=Backbone.Model.extend({sync:function(method,model,options){},rename:function(name){this.save({name:name},{patch:!0})}}),app.BlindCollection=Backbone.Collection.extend({name:"blinds",model:app.Blind}),app.blinds=new app.BlindCollection,app.lights.on("add",addLight),app.lights.on("change",function(light,options){var id=light.get("id"),bl=app.blinds.get(id);if(bl){var a=light.changedAttributes();a.state&&(bl.set({lastupdated:a.state.lastupdated,bri:a.state.bri}),bl.set({reachable:a.state.reachable})),app.api.trigger("blind-changed",bl)}}),app.sensors.on("change",function(sensor,options){var bl;if(app.blinds.forEach(blind=>{let mac=blind.get("mac");-1!==sensor.get("uniqueid").indexOf(mac)&&(bl=blind)}),bl){var stateChanges=sensor.changedAttributes();stateChanges.state&&bl.set(stateChanges.state),app.api.trigger("blind-changed",bl)}}),app.lights.forEach(function(light){addLight(light)},this)}