iobroker.lovelace
Version:
With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI
1 lines • 17.2 kB
JavaScript
"use strict";(self.rspackChunkhome_assistant_frontend=self.rspackChunkhome_assistant_frontend||[]).push([[83779],{90433:function(t,e,i){i.d(e,{Vy:function(){return o},fI:function(){return a},ux:function(){return c}});var s=i(22786),r=i(79468);const n=54;function o(t,e){const i=t%n+1;return e.getPropertyValue(`--color-${i}`)}function a(t,e){const i=e.getPropertyValue(`--graph-color-${t+1}`)||o(t,e);return(0,r.RQ)(i)}const c=(0,s.A)(t=>Array.from({length:n},(e,i)=>a(i,t)),(t,e)=>t[0].getPropertyValue("--graph-color-1")===e[0].getPropertyValue("--graph-color-1")&&t[0].getPropertyValue("--color-1")===e[0].getPropertyValue("--color-1"))},15090:function(t,e,i){i.d(e,{nP:function(){return h},vB:function(){return a}});i(44114),i(26910),i(18111),i(22489),i(61701),i(17642),i(58004),i(33853),i(45876),i(32475),i(15024),i(31698),i(62953);var s=i(22675),r=i(52220),n=i(71727),o=i(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=(t,e,i=void 0)=>{const h=(0,o.t)(e),u=[];switch(u.push(...((t,e,i)=>{const o=[];switch(i||o.push(s.Hh,s.HV),!i&&e in a?o.push(...a[e]):i&&e in c&&i in c[e]&&o.push(...c[e][i]),e){case"device_tracker":case"person":i||o.push(...Object.entries(t.states).filter(([t,e])=>"zone"===(0,n.m)(t)&&"zone.home"!==t&&e.attributes.friendly_name).map(([t,e])=>e.attributes.friendly_name).sort((e,i)=>(0,r.xL)(e,i,t.locale.language)))}return o})(t,h,i)),h){case"climate":i?"fan_mode"===i?u.push(...e.attributes.fan_modes):"preset_mode"===i?u.push(...e.attributes.preset_modes):"swing_mode"===i?u.push(...e.attributes.swing_modes):"swing_horizontal_mode"===i&&u.push(...e.attributes.swing_horizontal_modes):u.push(...e.attributes.hvac_modes);break;case"event":"event_type"===i&&u.push(...e.attributes.event_types);break;case"fan":"preset_mode"===i&&u.push(...e.attributes.preset_modes);break;case"humidifier":"mode"===i&&u.push(...e.attributes.available_modes);break;case"input_select":case"select":i||u.push(...e.attributes.options);break;case"light":"effect"===i&&e.attributes.effect_list?u.push(...e.attributes.effect_list):"color_mode"===i&&e.attributes.supported_color_modes&&u.push(...e.attributes.supported_color_modes);break;case"media_player":"sound_mode"===i?u.push(...e.attributes.sound_mode_list):"source"===i&&u.push(...e.attributes.source_list);break;case"remote":"current_activity"===i&&u.push(...e.attributes.activity_list);break;case"sensor":i||"enum"!==e.attributes.device_class||u.push(...e.attributes.options);break;case"vacuum":"fan_speed"===i&&u.push(...e.attributes.fan_speed_list);break;case"water_heater":i&&"operation_mode"!==i||u.push(...e.attributes.operation_list)}return[...new Set(u)]}},72190:function(t,e,i){i.d(e,{c:function(){return m}});i(74423),i(45367),i(92731),i(62953);var s=i(90433),r=i(79468),n=i(39274),o=i(71727),a=i(69093),c=i(15090),h=i(52658),u=i(80880),d=i(22675),_=i(86030);const l={media_player:{paused:.5,idle:1},vacuum:{returning:.5}};let p=0;const f=new Map;function m(t,e,i){return function(t,e,i){var s;if(!i||t===d.Hh)return(0,_.a)("--history-unavailable-color",e);if(t===d.HV)return(0,_.a)("--history-unknown-color",e);const a=(0,o.m)(i.entity_id);if(("person"===a||"device_tracker"===a)&&!(c.vB[a]||[]).includes(t))return(0,_.a)(`--state-${a}-${(0,u.Y)(t,"_")}-color`,e);const p=(0,h.mg)(i,t);if(!p)return;const f=(0,_.a)(p,e);if(!f)return;const m=null===(s=l[a])||void 0===s?void 0:s[t];return m?(0,r.zm)((0,n.T)((0,r.Nc)((0,r.xp)(f)),m)):f}(t,e,i)||function(t,e,i){if(!i)return;const r=(0,a.t)(i),n=(c.vB[r]||"sensor"===r&&"enum"===i.attributes.device_class&&i.attributes.options||[]).indexOf(t);return-1!==n?(0,s.fI)(n,e):void 0}(t,e,i)||function(t,e){if(f.has(t))return f.get(t);const i=(0,s.fI)(p,e);return p++,f.set(t,i),i}(t,e)}},23528:function(t,e,i){i.a(t,async function(t,s){try{i.d(e,{$3:function(){return g},$O:function(){return $},$j:function(){return y},ED:function(){return a},JE:function(){return H},OQ:function(){return C},PU:function(){return I},Ph:function(){return f},Uf:function(){return S},W1:function(){return m},Wr:function(){return _},Z:function(){return u},gF:function(){return v},iY:function(){return b},jU:function(){return c},nN:function(){return x},p3:function(){return d},pJ:function(){return p},r_:function(){return h},sz:function(){return l}});i(74423),i(18111),i(13579),i(62953);var r=i(28978),n=i(380),o=t([n]);n=(o.then?(await o)():o)[0];var a=function(t){return t[t.NONE=0]="NONE",t[t.ARITHMETIC=1]="ARITHMETIC",t[t.CIRCULAR=2]="CIRCULAR",t}({});const c=66649!=i.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,h=["L","gal","ft³","m³","CCF","MCF"],u=t=>t.sendMessagePromise({type:"recorder/info"}),d=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),_=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),l=(t,e,i,s,r="hour",n,o)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:null==i?void 0:i.toISOString(),statistic_ids:s,period:r,units:n,types:o}),p=(t,e,i,s)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:s,fixed_period:i.fixed_period?{start_time:i.fixed_period.start instanceof Date?i.fixed_period.start.toISOString():i.fixed_period.start,end_time:i.fixed_period.end instanceof Date?i.fixed_period.end.toISOString():i.fixed_period.end}:void 0,calendar:i.calendar?Object.assign(Object.assign({},"week"===i.calendar.period?{first_weekday:(0,n.D)(t.locale).substring(0,3)}:{}),i.calendar):void 0,rolling_window:i.rolling_window}),f=t=>t.callWS({type:"recorder/validate_statistics"}),m=(t,e,i,s)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:i,unit_class:s}),g=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),y=t=>{let e=null;if(!t)return null;for(const i of t)null!==i.change&&void 0!==i.change&&(null===e?e=i.change:e+=i.change);return e},v=(t,e)=>{let i=null;for(const s of e){if(!(s in t))continue;const e=y(t[s]);null!==e&&(null===i?i=e:i+=e)}return i},b=(t,e)=>t.some(t=>void 0!==t[e]&&null!==t[e]),w=["mean","min","max"],k=["sum","state","change"],x=(t,e)=>!(!w.includes(e)||0===t.mean_type)||!(!k.includes(e)||!t.has_sum),S=(t,e,i,s,r)=>{const n=new Date(i).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:n,adjustment:s,adjustment_unit_of_measurement:r})},$=(t,e,i)=>{const s=t.states[e];return s?(0,r.u)(s):(null==i?void 0:i.name)||e},H=(t,e,i)=>{let s;var r;e&&(s=null===(r=t.states[e])||void 0===r?void 0:r.attributes.unit_of_measurement);return void 0===s?null==i?void 0:i.statistics_unit_of_measurement:s},C=t=>t.includes(":"),I=t=>t.callWS({type:"recorder/update_statistics_issues"});s()}catch(c){s(c)}})},41544:function(t,e,i){i.a(t,async function(t,s){try{i.r(e),i.d(e,{DEFAULT_HOURS_TO_SHOW:function(){return H},HuiHistoryGraphCard:function(){return C}});i(16280),i(18111),i(7588),i(61701),i(3362),i(62953);var r=i(40445),n=i(5124),o=i(67576),a=i(6412),c=i(79468),h=i(36312),u=i(6030),d=i(66737),_=i(38962),l=(i(76776),i(43661),i(34127)),p=i(25064),f=i(23528),m=i(64808),g=i(784),y=i(20939),v=t([d,_,l,f,p]);[d,_,l,f,p]=v.then?(await v)():v;let b,w,k,x,S,$=t=>t;const H=24;class C extends n.WF{static async getConfigElement(){return await Promise.all([i.e(99143),i.e(66990),i.e(81804),i.e(38076),i.e(36810)]).then(i.bind(i,67801)),document.createElement("hui-history-graph-card-editor")}static getStubConfig(){return{type:"history-graph",entities:["sun.sun"]}}getCardSize(){var t,e;return null!==(t=this._config)&&void 0!==t&&t.title?2:0+2*((null===(e=this._entityIds)||void 0===e?void 0:e.length)||1)}getGridOptions(){return{columns:12,min_columns:6,min_rows:2}}setConfig(t){if(!t.entities||!Array.isArray(t.entities))throw new Error("Entities need to be an array");if(!t.entities.length)throw new Error("You must include at least one entity");this._entities=t.entities?(0,y.L)(t.entities):[],this._entityIds=this._entities.map(t=>t.entity),this._hoursToShow=t.hours_to_show||H,this._config=t,this._computeNames(),this._computeColors()}_computeNames(){this.hass&&this._config&&(this._names={},this._entities.forEach(t=>{const e=this.hass.states[t.entity];this._names[t.entity]=e?this.hass.formatEntityName(e,t.name):t.entity}))}_computeColors(){this._config&&(this._colors={},this._entities.forEach(t=>{this._colors[t.entity]=t.color?(0,c.RQ)(t.color):void 0}))}willUpdate(t){super.willUpdate(t),t.has("hass")&&this._computeNames()}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}async _subscribeHistory(){if(!(0,h.x)(this.hass.config,"history")||this._subscribed)return;const t=Promise.resolve(void 0);let e;this._subscribed=t;try{({numeric_device_classes:e}=await(0,m.KL)(this.hass))}catch(i){return void(this._subscribed===t&&(this._subscribed=void 0))}this.isConnected&&this._subscribed===t?(this._subscribed=(0,p.IQ)(this.hass,t=>{var i;this._subscribed&&(this._stateHistory=(0,p.Mm)(this.hass,t,this._entityIds,this.hass.localize,e,null===(i=this._config)||void 0===i?void 0:i.split_device_classes),this._mergeHistory())},this._hoursToShow,this._entityIds).catch(t=>{this._subscribed=void 0,this._error=t}),await this._fetchStatistics(e),this._setRedrawTimer()):this._subscribed===t&&(this._subscribed=void 0)}_mergeHistory(){var t;this._stateHistory&&(this._history=(0,p.tG)(this._stateHistory,this._statisticsHistory,null===(t=this._config)||void 0===t?void 0:t.split_device_classes))}async _fetchStatistics(t){var e;if(this._hoursToShow<1)return;const i=new Date,s=new Date;s.setHours(s.getHours()-this._hoursToShow-1);const r=await(0,f.sz)(this.hass,s,i,this._entityIds,"hour",void 0,["mean","state"]);this._statisticsHistory=(0,p._1)(this.hass,r,this._entityIds,t,null===(e=this._config)||void 0===e?void 0:e.split_device_classes),this._mergeHistory()}_redrawGraph(){this._history&&(this._history=Object.assign({},this._history))}_setRedrawTimer(){clearInterval(this._interval),this.isConnected&&(this._interval=window.setInterval(()=>this._redrawGraph(),6e4))}_unsubscribeHistory(){clearInterval(this._interval),this._subscribed&&(this._subscribed.then(t=>null==t?void 0:t()).catch(()=>{}),this._subscribed=void 0)}shouldUpdate(t){if(!this._subscribed&&!this._error&&this._config&&t.has("hass")){const e=t.get("hass");if(e&&e.config.components!==this.hass.config.components)return!0}return(0,g.pY)(this,t)||t.size>1||!t.has("hass")}updated(t){if(super.updated(t),!(this._config&&this.hass&&this._hoursToShow&&this._entityIds.length))return;if(!t.has("_config")&&!t.has("hass"))return;const e=t.get("_config");!t.has("_config")||(null==e?void 0:e.entities)===this._config.entities&&(null==e?void 0:e.hours_to_show)===this._config.hours_to_show?this.isConnected&&!this._subscribed&&!this._error&&t.has("hass")&&this._subscribeHistory():(this._unsubscribeHistory(),this._subscribeHistory())}render(){var t,e,i,s;if(!this.hass||!this._config)return n.s6;const r=new Date;r.setHours(r.getHours()-this._hoursToShow);const o=`/history?${(0,u.KH)({entity_id:this._entityIds.join(","),back:"1",start_date:r.toISOString()})}`,c=null!==(t=null===(e=this._config.grid_options)||void 0===e?void 0:e.columns)&&void 0!==t?t:12,h="number"==typeof c&&c<=12,d="number"==typeof(null===(i=this._config.grid_options)||void 0===i?void 0:i.rows);return(0,n.qy)(b||(b=$` <ha-card> ${0} <div class="content ${0}"> ${0} </div> </ha-card> `),this._config.title?(0,n.qy)(w||(w=$` <h1 class="card-header"> ${0} <a id="${0}" href="${0}" aria-label="${0}"> <ha-icon-next></ha-icon-next> </a> <ha-tooltip for="${0}" placement="left"> ${0} </ha-tooltip> </h1> `),this._config.title,this._historyLinkId,o,this.hass.localize("panel.history"),this._historyLinkId,this.hass.localize("panel.history")):n.s6,(0,a.H)({"has-header":!!this._config.title,"has-rows":!(null===(s=this._config.grid_options)||void 0===s||!s.rows),"has-height":d}),this._error?(0,n.qy)(k||(k=$` <ha-alert alert-type="error"> ${0}: ${0} </ha-alert> `),this.hass.localize("ui.components.history_charts.error"),this._error.message||this._error.code):(0,n.qy)(x||(x=$` <state-history-charts .hass="${0}" .isLoadingData="${0}" .historyData="${0}" .names="${0}" up-to-now .hoursToShow="${0}" .showNames="${0}" .logarithmicScale="${0}" .minYAxis="${0}" .maxYAxis="${0}" .fitYData="${0}" .colors="${0}" .height="${0}" .narrow="${0}" .expandLegend="${0}"></state-history-charts> `),this.hass,!this._history,this._history,this._names,this._hoursToShow,void 0===this._config.show_names||this._config.show_names,this._config.logarithmic_scale||!1,this._config.min_y_axis,this._config.max_y_axis,this._config.fit_y_data||!1,this._colors,d?"100%":void 0,h,this._config.expand_legend))}constructor(...t){super(...t),this._names={},this._colors={},this._entityIds=[],this._entities=[],this._historyLinkId=`history-${Math.random().toString(36).substring(2,9)}`,this._hoursToShow=H}}C.styles=(0,n.AH)(S||(S=$`ha-card{display:flex;flex-direction:column;height:100%}.card-header{justify-content:space-between;display:flex;padding-bottom:0}.card-header ha-icon-next{--ha-icon-button-size:24px;line-height:24px;color:var(--primary-text-color)}.content{padding:0 16px 8px;flex:1;overflow:hidden}.content:has(state-history-charts){overflow:visible}.content.has-height:has(state-history-charts){overflow:hidden}.has-header{padding-top:0}state-history-charts{--timeline-top-margin:16px}.has-height state-history-charts{height:100%}.has-rows{--chart-max-height:100%}`)),(0,r.Cg)([(0,o.MZ)({attribute:!1})],C.prototype,"hass",void 0),(0,r.Cg)([(0,o.wk)()],C.prototype,"_history",void 0),(0,r.Cg)([(0,o.wk)()],C.prototype,"_statisticsHistory",void 0),(0,r.Cg)([(0,o.wk)()],C.prototype,"_config",void 0),(0,r.Cg)([(0,o.wk)()],C.prototype,"_error",void 0),C=(0,r.Cg)([(0,o.EM)("hui-history-graph-card")],C),s()}catch(b){s(b)}})},6116:function(t,e,i){i.d(e,{o:function(){return n}});var s=i(6439),r=i(83339);function n(t,e,i){const n=(0,r.b)(t,e)/6e4;return(0,s.u)(null==i?void 0:i.roundingMethod)(n)}}}]);