iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 19.9 kB
JavaScript
export const __rspack_esm_id=23954;export const __rspack_esm_ids=[23954];export const __webpack_modules__={90433(e,t,s){s.d(t,{Vy:()=>r,fI:()=>n,ux:()=>a});var i=s(22786),o=s(79468);function r(e,t){const s=e%54+1;return t.getPropertyValue(`--color-${s}`)}function n(e,t){const s=t.getPropertyValue(`--graph-color-${e+1}`)||r(e,t);return(0,o.RQ)(s)}const a=(0,i.A)(e=>Array.from({length:54},(t,s)=>n(s,e)),(e,t)=>e[0].getPropertyValue("--graph-color-1")===t[0].getPropertyValue("--graph-color-1")&&e[0].getPropertyValue("--color-1")===t[0].getPropertyValue("--color-1"))},15090(e,t,s){s.d(t,{nP:()=>h,vB:()=>a});s(44114),s(18111),s(22489),s(61701),s(17642),s(58004),s(33853),s(45876),s(32475),s(15024),s(31698);var i=s(22675),o=s(52220),r=s(71727),n=s(69093);const a={alarm_control_panel:["armed_away","armed_custom_bypass","armed_home","armed_night","armed_vacation","arming","disarmed","disarming","pending","triggered"],alert:["on","off","idle"],assist_satellite:["idle","listening","responding","processing"],automation:["on","off"],binary_sensor:["on","off"],button:[],calendar:["on","off"],camera:["idle","recording","streaming"],cover:["closed","closing","open","opening"],device_tracker:["home","not_home"],fan:["on","off"],humidifier:["on","off"],infrared:[],input_boolean:["on","off"],input_button:[],lawn_mower:["error","paused","mowing","returning","docked"],light:["on","off"],lock:["jammed","locked","locking","unlocked","unlocking","opening","open"],media_player:["off","on","idle","playing","paused","standby","buffering"],person:["home","not_home"],plant:["ok","problem"],radio_frequency:[],remote:["on","off"],scene:[],schedule:["on","off"],script:["on","off"],siren:["on","off"],sun:["above_horizon","below_horizon"],switch:["on","off"],timer:["active","idle","paused"],update:["on","off"],vacuum:["cleaning","docked","error","idle","paused","returning"],valve:["closed","closing","open","opening"],weather:["clear-night","cloudy","exceptional","fog","hail","lightning-rainy","lightning","partlycloudy","pouring","rainy","snowy-rainy","snowy","sunny","windy-variant","windy"]},c={alarm_control_panel:{code_format:["number","text"]},binary_sensor:{device_class:["battery","battery_charging","co","cold","connectivity","door","garage_door","gas","heat","light","lock","moisture","motion","moving","occupancy","opening","plug","power","presence","problem","running","safety","smoke","sound","tamper","update","vibration","window"]},button:{device_class:["restart","update"]},camera:{frontend_stream_type:["hls","web_rtc"]},climate:{hvac_action:["off","idle","preheating","defrosting","heating","cooling","drying","fan"]},cover:{device_class:["awning","blind","curtain","damper","door","garage","gate","shade","shutter","window"]},device_tracker:{source_type:["bluetooth","bluetooth_le","gps","router"]},fan:{direction:["forward","reverse"]},humidifier:{device_class:["humidifier","dehumidifier"],action:["off","idle","humidifying","drying"]},media_player:{device_class:["tv","speaker","receiver"],media_content_type:["album","app","artist","channel","channels","composer","contributing_artist","episode","game","genre","image","movie","music","playlist","podcast","season","track","tvshow","url","video"],repeat:["off","one","all"]},number:{device_class:["temperature"]},sensor:{device_class:["apparent_power","aqi","battery","carbon_dioxide","carbon_monoxide","current","date","duration","energy","frequency","gas","humidity","illuminance","monetary","nitrogen_dioxide","nitrogen_monoxide","nitrous_oxide","ozone","ph","pm1","pm10","pm25","pm4","power_factor","power","pressure","reactive_power","signal_strength","sulphur_dioxide","temperature","timestamp","uptime","volatile_organic_compounds","volatile_organic_compounds_parts","voltage","volume_flow_rate"],state_class:["measurement","total","total_increasing"]},switch:{device_class:["outlet","switch"]},update:{device_class:["firmware"]},water_heater:{away_mode:["on","off"]}},h=(e,t,s=void 0)=>{const h=(0,n.t)(t),d=[];switch(d.push(...((e,t,s)=>{const n=[];switch(s||n.push(i.Hh,i.HV),!s&&t in a?n.push(...a[t]):s&&t in c&&s in c[t]&&n.push(...c[t][s]),t){case"device_tracker":case"person":s||n.push(...Object.entries(e.states).filter(([e,t])=>"zone"===(0,r.m)(e)&&"zone.home"!==e&&t.attributes.friendly_name).map(([e,t])=>t.attributes.friendly_name).sort((t,s)=>(0,o.xL)(t,s,e.locale.language)))}return n})(e,h,s)),h){case"climate":s?"fan_mode"===s?d.push(...t.attributes.fan_modes):"preset_mode"===s?d.push(...t.attributes.preset_modes):"swing_mode"===s?d.push(...t.attributes.swing_modes):"swing_horizontal_mode"===s&&d.push(...t.attributes.swing_horizontal_modes):d.push(...t.attributes.hvac_modes);break;case"event":"event_type"===s&&d.push(...t.attributes.event_types);break;case"fan":"preset_mode"===s&&d.push(...t.attributes.preset_modes);break;case"humidifier":"mode"===s&&d.push(...t.attributes.available_modes);break;case"input_select":case"select":s||d.push(...t.attributes.options);break;case"light":"effect"===s&&t.attributes.effect_list?d.push(...t.attributes.effect_list):"color_mode"===s&&t.attributes.supported_color_modes&&d.push(...t.attributes.supported_color_modes);break;case"media_player":"sound_mode"===s?d.push(...t.attributes.sound_mode_list):"source"===s&&d.push(...t.attributes.source_list);break;case"remote":"current_activity"===s&&d.push(...t.attributes.activity_list);break;case"sensor":s||"enum"!==t.attributes.device_class||d.push(...t.attributes.options);break;case"vacuum":"fan_speed"===s&&d.push(...t.attributes.fan_speed_list);break;case"water_heater":s&&"operation_mode"!==s||d.push(...t.attributes.operation_list)}return[...new Set(d)]}},22533(e,t,s){s.d(t,{i:()=>o});var i=s(52943);const o=(e,t)=>(e=>{switch(e){case"de":case"lb":return!0;default:return!1}})(t)?(0,i.Z)(e):e.toLocaleLowerCase(t)},86531(e,t,s){s.a(e,async function(e,i){try{s.d(t,{$O:()=>y,a$:()=>k,cj:()=>_,dG:()=>b,gM:()=>m,gd:()=>u,k$:()=>v,rc:()=>w});s(74423);var o=s(46190),r=s(71727),n=s(69093),a=s(22533),c=s(22675),h=s(25064),d=e([h]);h=(d.then?(await d)():d)[0];const l="ui.components.logbook.messages",_=["counter","proximity"],g={triggered_by_numeric_state_of:"numeric state of",triggered_by_state_of:"state of",triggered_by_event:"event",triggered_by_time_pattern:"time pattern",triggered_by_time:"time",triggered_by_homeassistant_stopping:"ioBroker stopping",triggered_by_homeassistant_starting:"ioBroker starting"},u=async(e,t,s)=>p(e,t,void 0,void 0,s),p=(e,t,s,i,o,r)=>{if((i||r)&&(!i||0===i.length)&&(!r||0===r.length))return Promise.resolve([]);const n={type:"logbook/get_events",start_time:t};return s&&(n.end_time=s),i?.length&&(n.entity_ids=i),r?.length&&(n.device_ids=r),o&&(n.context_id=o),e.callWS(n)},m=(e,t,s,i,o,r,n)=>{if((r||n)&&(!r||0===r.length)&&(!n||0===n.length))return Promise.reject("No entities or devices");const a={type:"logbook/event_stream",start_time:s,end_time:i};return r?.length&&(a.entity_ids=r),n?.length&&(a.device_ids=n),e.connection.subscribeMessage(e=>t(e,o),a)},b=(e,t)=>({entity_id:e.entity_id,state:t,attributes:{device_class:e?.attributes.device_class,source_type:e?.attributes.source_type,has_date:e?.attributes.has_date,has_time:e?.attributes.has_time,entity_picture_local:o.oL.has((0,r.m)(e.entity_id))?void 0:e?.attributes.entity_picture_local,entity_picture:o.oL.has((0,r.m)(e.entity_id))?void 0:e?.attributes.entity_picture}}),y=(e,t)=>{for(const s of Object.keys(g)){const i=g[s];if(t.startsWith(i))return t.replace(i,`${e(`ui.components.logbook.${s}`)}`)}return t},f=66649!=s.j?{triggered_by_numeric_state_of:"numeric_state_of",triggered_by_state_of:"state_of",triggered_by_event:"event",triggered_by_time_pattern:"time_pattern",triggered_by_time:"time",triggered_by_homeassistant_stopping:"homeassistant_stopping",triggered_by_homeassistant_starting:"homeassistant_starting"}:null,v=(e,t)=>{for(const s of Object.keys(g)){const i=g[s];if(t.startsWith(i)){const o=f[s];return t.replace(i,`${e(`ui.components.logbook.${o}`)}`)}}return t},k=(e,t,s,i,o)=>{switch(o){case"device_tracker":case"person":return"not_home"===s?t(`${l}.was_away`):"home"===s?t(`${l}.was_at_home`):t(`${l}.was_at_state`,{state:s});case"sun":return t("above_horizon"===s?`${l}.rose`:`${l}.set`);case"binary_sensor":{const o="on"===s,r="off"===s,n=i.attributes.device_class;if(n&&(o||r))return t(`${l}.${o?"detected_device_classes":"cleared_device_classes"}.${n}`,{device_class:(0,a.i)(t(`component.binary_sensor.entity_component.${n}.name`)||n,e.language)})||t(`${l}.${o?"detected_device_class":"cleared_device_class"}`,{device_class:(0,a.i)(t(`component.binary_sensor.entity_component.${n}.name`)||n,e.language)});break}case"cover":switch(s){case"open":return t(`${l}.was_opened`);case"opening":return t(`${l}.is_opening`);case"closing":return t(`${l}.is_closing`);case"closed":return t(`${l}.was_closed`)}break;case"event":return t(`${l}.detected_event_no_type`);case"lock":switch(s){case"unlocked":return t(`${l}.was_unlocked`);case"locking":return t(`${l}.is_locking`);case"unlocking":return t(`${l}.is_unlocking`);case"opening":return t(`${l}.is_opening`);case"open":return t(`${l}.is_opened`);case"locked":return t(`${l}.was_locked`);case"jammed":return t(`${l}.is_jammed`)}}return"on"===s?t(`${l}.turned_on`):"off"===s?t(`${l}.turned_off`):s===c.HV?t(`${l}.became_unknown`):s===c.Hh?t(`${l}.became_unavailable`):e.localize(`${l}.changed_to_state`,{state:i?e.formatEntityState(i,s):s})},w=(e,t=[])=>{const s=(0,n.t)(e);return!(_.includes(s)||"sensor"===s&&(0,h.Fp)(s,e,void 0,t))};i()}catch(e){i(e)}})},89434(e,t,s){s.a(e,async function(e,t){try{s(74423),s(44114),s(18111),s(22489),s(7588),s(13579);var i=s(62826),o=s(5124),r=s(22441),n=s(36312),a=s(69093),c=s(77796),h=s(65829),d=s(86531),l=s(61165),_=s(28669),g=s(11184),u=e([h,g,d]);[h,g,d]=u.then?(await u)():u;const p=(e,t)=>new Date(e.getTime()-1e3*t).getTime()/1e3,m=(e,t)=>(void 0!==e||void 0!==t)&&(!e||!t||e.length!==t.length||e.some(e=>!t.includes(e))||t.some(t=>!e.includes(t)));class b extends o.WF{render(){return(0,n.x)(this.hass.config,"logbook")?this._error?o.qy`<div class="no-entries"> ${`${this.hass.localize("ui.components.logbook.retrieval_error")}: ${this._error}`} </div>`:void 0===this._logbookEntries?o.qy` <div class="progress-wrapper"> <ha-spinner></ha-spinner> </div> `:0===this._logbookEntries.length?o.qy`<div class="no-entries"> ${this.hass.localize("ui.components.logbook.entries_not_found")} </div>`:o.qy` <ha-logbook-renderer .hass="${this.hass}" .narrow="${this.narrow}" .virtualize="${this.virtualize}" .noIcon="${this.noIcon}" .noName="${this.noName}" .showIndicator="${this.showIndicator}" .relativeTime="${this.relativeTime}" .entries="${this._logbookEntries}" .traceContexts="${this._traceContexts}" .userIdToName="${this._userIdToName}" -logbook-live="${this._handleLogbookLive}"></ha-logbook-renderer> `:o.s6}async refresh(e=!1){(e||!this._unsubLogbook&&void 0!==this._logbookEntries)&&(this._throttleGetLogbookEntries.cancel(),this._updateTraceContexts.cancel(),this._updateUsers.cancel(),this._unsubscribe(!0),this._liveUpdatesEnabled=!0,e?this._getLogBookData():this._throttleGetLogbookEntries())}shouldUpdate(e){if(1!==e.size||!e.has("hass"))return!0;const t=e.get("hass");return!t||t.localize!==this.hass.localize}willUpdate(e){let t=e.has("time");for(const s of["entityIds","deviceIds","stateFilter"]){if(!e.has(s))continue;const i=e.get(s),o=this[s];if(m(i,o)){t=!0;break}}t&&this.refresh(!0)}_handleLogbookLive(e){e.detail.enable&&!this._liveUpdatesEnabled&&(this._pendingStreamMessages.forEach(e=>this._processStreamMessage(e)),this._pendingStreamMessages=[]),this._liveUpdatesEnabled=e.detail.enable}get _filterAlwaysEmptyResults(){const e=this.entityIds,t=this.deviceIds;return Boolean(e||t)&&(!e||0===e.length)&&(!t||0===t.length)}_unsubscribe(e){this._unsubLogbook&&(this._unsubLogbook.then(e=>e()),this._unsubLogbook=void 0,this._logbookEntries=e?void 0:[],this._pendingStreamMessages=[])}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this._subscribeLogbookPeriod(this._calculateLogbookPeriod())}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribe(!0)}_calculateLogbookPeriod(){const e=new Date;if("range"in this.time)return{now:e,startTime:this.time.range[0],endTime:this.time.range[1],purgeBeforePythonTime:void 0};if("recent"in this.time){const t=p(e,this.time.recent);return{now:e,startTime:new Date(1e3*t),endTime:new Date(e.getTime()+31536e6),purgeBeforePythonTime:p(e,this.time.recent)}}throw new Error("Unexpected time specified")}async _subscribeLogbookPeriod(e){if(!this._unsubLogbook)try{this._logbookSubscriptionId++,this._unsubLogbook=(0,d.gM)(this.hass,(e,t)=>{t===this._logbookSubscriptionId&&this._processOrQueueStreamMessage(e)},e.startTime.toISOString(),e.endTime.toISOString(),this._logbookSubscriptionId,this.entityIds,this.deviceIds),await this._unsubLogbook}catch(e){this._unsubLogbook=void 0,this._error=e}}async _getLogBookData(){if(this._error=void 0,this._filterAlwaysEmptyResults)return void this._unsubscribe(!1);const e=this._calculateLogbookPeriod();e.startTime>e.now?this._unsubscribe(!1):(this._updateUsers(),this.hass.user?.is_admin&&this._updateTraceContexts(),this._subscribeLogbookPeriod(e))}static get styles(){return[o.AH`:host{display:block}:host([virtualize]){height:100%}.no-entries{text-align:center;padding:16px;color:var(--secondary-text-color)}.progress-wrapper{display:flex;justify-content:center;height:100%;align-items:center}`]}constructor(...e){super(...e),this.narrow=!1,this.virtualize=!1,this.noIcon=!1,this.noName=!1,this.showIndicator=!1,this.relativeTime=!1,this.showMoreLink=!0,this._traceContexts={},this._userIdToName={},this._liveUpdatesEnabled=!0,this._pendingStreamMessages=[],this._throttleGetLogbookEntries=(0,c.n)(()=>this._getLogBookData(),1e3),this._logbookSubscriptionId=0,this._nonExpiredRecords=e=>this._logbookEntries?e?this._logbookEntries.filter(t=>t.when>e):this._logbookEntries:[],this._processOrQueueStreamMessage=e=>{this._liveUpdatesEnabled?this._processStreamMessage(e):this._pendingStreamMessages.push(e)},this._processStreamMessage=e=>{const t="recent"in this.time?p(new Date,this.time.recent):void 0;let s;s=this.stateFilter&&this.stateFilter.length>0?e.events.filter(e=>e.state&&this.stateFilter?.includes(e.state)):[...e.events];const i=s.reverse();if(!this._logbookEntries||!this._logbookEntries.length)return void(this._logbookEntries=i);if(!i.length)return;const o=this._nonExpiredRecords(t);o.length?i[i.length-1].when>o[0].when?this._logbookEntries=i.concat(o):o[o.length-1].when>i[0].when?this._logbookEntries=o.concat(i):this._logbookEntries=o.concat(i).sort((e,t)=>t.when-e.when):this._logbookEntries=i},this._updateTraceContexts=(0,c.n)(async()=>{this._traceContexts=await(0,l.gq)(this.hass)},6e4),this._updateUsers=(0,c.n)(async()=>{const e={},t=this.hass.user?.is_admin&&(0,_.hU)(this.hass);for(const t of Object.values(this.hass.states))t.attributes.user_id&&"person"===(0,a.t)(t)&&(e[t.attributes.user_id]=t.attributes.friendly_name);if(t){const s=await t;for(const t of s)t.id in e||(e[t.id]=t.name)}this._userIdToName=e},6e4)}}(0,i.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"hass",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"time",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"entityIds",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"deviceIds",void 0),(0,i.Cg)([(0,r.MZ)({attribute:!1})],b.prototype,"stateFilter",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean})],b.prototype,"narrow",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean,reflect:!0})],b.prototype,"virtualize",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean,attribute:"no-icon"})],b.prototype,"noIcon",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean,attribute:"no-name"})],b.prototype,"noName",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean,attribute:"show-indicator"})],b.prototype,"showIndicator",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean,attribute:"relative-time"})],b.prototype,"relativeTime",void 0),(0,i.Cg)([(0,r.MZ)({attribute:"show-more-link",type:Boolean})],b.prototype,"showMoreLink",void 0),(0,i.Cg)([(0,r.wk)()],b.prototype,"_logbookEntries",void 0),(0,i.Cg)([(0,r.wk)()],b.prototype,"_traceContexts",void 0),(0,i.Cg)([(0,r.wk)()],b.prototype,"_userIdToName",void 0),(0,i.Cg)([(0,r.wk)()],b.prototype,"_error",void 0),b=(0,i.Cg)([(0,r.EM)("ha-logbook")],b),t()}catch(e){t(e)}})},42526(e,t,s){s.a(e,async function(e,i){try{s.r(t),s.d(t,{DEFAULT_HOURS_TO_SHOW:()=>y,HuiLogbookCard:()=>f});s(18111),s(61701);var o=s(62826),r=s(5124),n=s(22441),a=s(6412),c=s(22786),h=s(36312),d=s(42372),l=(s(76776),s(89434)),_=s(13632),g=s(20939),u=s(85979),p=s(95311),m=s(44537),b=e([l,u]);[l,u]=b.then?(await b)():b;const y=24;class f extends r.WF{static async getConfigElement(){return await Promise.all([s.e(1535),s.e(33758),s.e(8697),s.e(8955),s.e(7457)]).then(s.bind(s,38355)),document.createElement("hui-logbook-card-editor")}static getStubConfig(e,t,s){return{target:{entity_id:(0,_.B)(e,3,t,s,["light","switch"])}}}getCardSize(){return 9+(this._config?.title?1:0)}getGridOptions(){return{rows:6,columns:12,min_columns:6,min_rows:this._config?.title?4:3}}validateTarget(e){if((!e.entities||e.entities.length)&&(!e.target||e.target.area_id?.length||e.target.device_id?.length||e.target.entity_id?.length||e.target.floor_id?.length||e.target.label_id?.length))return e.entities?{entity_id:(0,g.L)(e.entities).map(e=>e.entity)}:e.target?.entity_id?{...e.target,entity_id:(0,g.L)((0,m.e)(e.target.entity_id)).map(e=>e.entity)}:e.target}setConfig(e){const t=this.validateTarget(e);if(!t)throw new Error("The provided target in the logbook card has no entities. Targets can include entities, devices, labels, or areas, with devices, areas, and labels resolving to entities.");this._config={hours_to_show:y,...e},this._time={recent:60*this._config.hours_to_show*60},this._targetPickerValue=t,this._stateFilter=(0,m.e)(e.state_filter)}_getEntityIds(){const e=this._getMemoizedEntityIds(this._targetPickerValue,this.hass.entities,this.hass.devices,this.hass.areas);if(0!==e.length)return e}update(e){super.update(e),e.has("layout")&&this.toggleAttribute("ispanel","panel"===this.layout)}updated(e){if(super.updated(e),!this._config||!this.hass)return;const t=e.has("_config"),s=e.has("hass"),i=e.get("hass"),o=e.get("_config");(s&&i?.themes!==this.hass.themes||t&&o?.theme!==this._config.theme)&&(0,d.Q)(this,this.hass.themes,this._config.theme)}render(){return this.hass&&this._config?(0,h.x)(this.hass.config,"logbook")?r.qy` <ha-card .header="${this._config.title}" class="${(0,a.H)({"no-header":!this._config.title})}"> <div class="content"> <ha-logbook class="${(0,a.H)({"is-grid":"grid"===this.layout,"is-panel":"panel"===this.layout})}" .hass="${this.hass}" .time="${this._time}" .entityIds="${this._getEntityIds()}" .stateFilter="${this._stateFilter}" narrow relative-time virtualize></ha-logbook> </div> </ha-card> `:r.qy` <hui-warning .hass="${this.hass}"> ${this.hass.localize("ui.components.logbook.not_loaded",{platform:"logbook"})}</hui-warning> `:r.s6}static get styles(){return[r.AH`ha-card{height:100%;display:flex;flex-direction:column;justify-content:space-between}.content{height:100%;padding:0 16px 16px}.no-header .content{padding-top:16px}ha-logbook{height:385px;display:block}ha-logbook.is-grid,ha-logbook.is-panel{height:100%}:host([ispanel]) .content,:host([ispanel]) ha-logbook{height:100%}`]}constructor(...e){super(...e),this._targetPickerValue={},this._getMemoizedEntityIds=(0,c.A)((e,t,s,i)=>(0,p.wY)(this.hass,e,t,s,i))}}(0,o.Cg)([(0,n.MZ)({attribute:!1})],f.prototype,"hass",void 0),(0,o.Cg)([(0,n.MZ)({attribute:!1})],f.prototype,"layout",void 0),(0,o.Cg)([(0,n.wk)()],f.prototype,"_config",void 0),(0,o.Cg)([(0,n.wk)()],f.prototype,"_time",void 0),(0,o.Cg)([(0,n.wk)()],f.prototype,"_targetPickerValue",void 0),(0,o.Cg)([(0,n.wk)()],f.prototype,"_stateFilter",void 0),f=(0,o.Cg)([(0,n.EM)("hui-logbook-card")],f),i()}catch(e){i(e)}})}};