UNPKG

iobroker.lovelace

Version:

With this adapter you can build visualization for ioBroker with Home Assistant Lovelace UI

1 lines 15.9 kB
export const __rspack_esm_id=83779;export const __rspack_esm_ids=[83779];export const __webpack_modules__={90433(t,e,s){s.d(e,{Vy:()=>o,fI:()=>a,ux:()=>n});var i=s(22786),r=s(79468);function o(t,e){const s=t%54+1;return e.getPropertyValue(`--color-${s}`)}function a(t,e){const s=e.getPropertyValue(`--graph-color-${t+1}`)||o(t,e);return(0,r.RQ)(s)}const n=(0,i.A)(t=>Array.from({length:54},(e,s)=>a(s,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(t,e,s){s.d(e,{nP:()=>h,vB:()=>n});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),r=s(52220),o=s(71727),a=s(69093);const n={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,s=void 0)=>{const h=(0,a.t)(e),d=[];switch(d.push(...((t,e,s)=>{const a=[];switch(s||a.push(i.Hh,i.HV),!s&&e in n?a.push(...n[e]):s&&e in c&&s in c[e]&&a.push(...c[e][s]),e){case"device_tracker":case"person":s||a.push(...Object.entries(t.states).filter(([t,e])=>"zone"===(0,o.m)(t)&&"zone.home"!==t&&e.attributes.friendly_name).map(([t,e])=>e.attributes.friendly_name).sort((e,s)=>(0,r.xL)(e,s,t.locale.language)))}return a})(t,h,s)),h){case"climate":s?"fan_mode"===s?d.push(...e.attributes.fan_modes):"preset_mode"===s?d.push(...e.attributes.preset_modes):"swing_mode"===s?d.push(...e.attributes.swing_modes):"swing_horizontal_mode"===s&&d.push(...e.attributes.swing_horizontal_modes):d.push(...e.attributes.hvac_modes);break;case"event":"event_type"===s&&d.push(...e.attributes.event_types);break;case"fan":"preset_mode"===s&&d.push(...e.attributes.preset_modes);break;case"humidifier":"mode"===s&&d.push(...e.attributes.available_modes);break;case"input_select":case"select":s||d.push(...e.attributes.options);break;case"light":"effect"===s&&e.attributes.effect_list?d.push(...e.attributes.effect_list):"color_mode"===s&&e.attributes.supported_color_modes&&d.push(...e.attributes.supported_color_modes);break;case"media_player":"sound_mode"===s?d.push(...e.attributes.sound_mode_list):"source"===s&&d.push(...e.attributes.source_list);break;case"remote":"current_activity"===s&&d.push(...e.attributes.activity_list);break;case"sensor":s||"enum"!==e.attributes.device_class||d.push(...e.attributes.options);break;case"vacuum":"fan_speed"===s&&d.push(...e.attributes.fan_speed_list);break;case"water_heater":s&&"operation_mode"!==s||d.push(...e.attributes.operation_list)}return[...new Set(d)]}},72190(t,e,s){s.d(e,{c:()=>g});s(74423),s(45367),s(92731);var i=s(90433),r=s(79468),o=s(39274),a=s(71727),n=s(69093),c=s(15090),h=s(52658),d=s(80880),_=s(22675),u=s(86030);const l={media_player:{paused:.5,idle:1},vacuum:{returning:.5}};let p=0;const m=new Map;function g(t,e,s){return function(t,e,s){if(!s||t===_.Hh)return(0,u.a)("--history-unavailable-color",e);if(t===_.HV)return(0,u.a)("--history-unknown-color",e);const i=(0,a.m)(s.entity_id);if(("person"===i||"device_tracker"===i)&&!(c.vB[i]||[]).includes(t))return(0,u.a)(`--state-${i}-${(0,d.Y)(t,"_")}-color`,e);const n=(0,h.mg)(s,t);if(!n)return;const p=(0,u.a)(n,e);if(!p)return;const m=l[i]?.[t];return m?(0,r.zm)((0,o.T)((0,r.Nc)((0,r.xp)(p)),m)):p}(t,e,s)||function(t,e,s){if(!s)return;const r=(0,n.t)(s),o=(c.vB[r]||"sensor"===r&&"enum"===s.attributes.device_class&&s.attributes.options||[]).indexOf(t);return-1!==o?(0,i.fI)(o,e):void 0}(t,e,s)||function(t,e){if(m.has(t))return m.get(t);const s=(0,i.fI)(p,e);return p++,m.set(t,s),s}(t,e)}},23528(t,e,s){s.d(e,{$3:()=>m,$O:()=>k,$j:()=>g,ED:()=>o,JE:()=>S,OQ:()=>$,PU:()=>H,Ph:()=>l,Uf:()=>x,W1:()=>p,Wr:()=>d,Z:()=>c,gF:()=>f,iY:()=>y,jU:()=>a,nN:()=>w,p3:()=>h,pJ:()=>u,r_:()=>n,sz:()=>_});s(74423),s(18111),s(13579);var i=s(28978),r=s(380),o=function(t){return t[t.NONE=0]="NONE",t[t.ARITHMETIC=1]="ARITHMETIC",t[t.CIRCULAR=2]="CIRCULAR",t}({});const a=66649!=s.j?["entity_not_recorded","entity_no_longer_recorded","state_class_removed","units_changed","mean_type_changed","no_state"]:null,n=["L","gal","ft³","m³","CCF","MCF"],c=t=>t.sendMessagePromise({type:"recorder/info"}),h=(t,e)=>t.callWS({type:"recorder/list_statistic_ids",statistic_type:e}),d=(t,e)=>t.callWS({type:"recorder/get_statistics_metadata",statistic_ids:e}),_=(t,e,s,i,r="hour",o,a)=>t.callWS({type:"recorder/statistics_during_period",start_time:e.toISOString(),end_time:s?.toISOString(),statistic_ids:i,period:r,units:o,types:a}),u=(t,e,s,i)=>t.callWS({type:"recorder/statistic_during_period",statistic_id:e,units:i,fixed_period:s.fixed_period?{start_time:s.fixed_period.start instanceof Date?s.fixed_period.start.toISOString():s.fixed_period.start,end_time:s.fixed_period.end instanceof Date?s.fixed_period.end.toISOString():s.fixed_period.end}:void 0,calendar:s.calendar?{..."week"===s.calendar.period?{first_weekday:(0,r.D)(t.locale).substring(0,3)}:{},...s.calendar}:void 0,rolling_window:s.rolling_window}),l=t=>t.callWS({type:"recorder/validate_statistics"}),p=(t,e,s,i)=>t.callWS({type:"recorder/update_statistics_metadata",statistic_id:e,unit_of_measurement:s,unit_class:i}),m=(t,e)=>t.callWS({type:"recorder/clear_statistics",statistic_ids:e}),g=t=>{let e=null;if(!t)return null;for(const s of t)null!==s.change&&void 0!==s.change&&(null===e?e=s.change:e+=s.change);return e},f=(t,e)=>{let s=null;for(const i of e){if(!(i in t))continue;const e=g(t[i]);null!==e&&(null===s?s=e:s+=e)}return s},y=(t,e)=>t.some(t=>void 0!==t[e]&&null!==t[e]),b=["mean","min","max"],v=["sum","state","change"],w=(t,e)=>!(!b.includes(e)||0===t.mean_type)||!(!v.includes(e)||!t.has_sum),x=(t,e,s,i,r)=>{const o=new Date(s).toISOString();return t.callWS({type:"recorder/adjust_sum_statistics",statistic_id:e,start_time:o,adjustment:i,adjustment_unit_of_measurement:r})},k=(t,e,s)=>{const r=t.states[e];return r?(0,i.u)(r):s?.name||e},S=(t,e,s)=>{let i;return e&&(i=t.states[e]?.attributes.unit_of_measurement),void 0===i?s?.statistics_unit_of_measurement:i},$=t=>t.includes(":"),H=t=>t.callWS({type:"recorder/update_statistics_issues"})},41544(t,e,s){s.a(t,async function(t,i){try{s.r(e),s.d(e,{DEFAULT_HOURS_TO_SHOW:()=>v,HuiHistoryGraphCard:()=>w});s(18111),s(7588),s(61701);var r=s(62826),o=s(5124),a=s(22441),n=s(6412),c=s(79468),h=s(36312),d=s(6030),_=s(66737),u=s(38962),l=(s(76776),s(43661),s(34127)),p=s(25064),m=s(23528),g=s(64808),f=s(784),y=s(20939),b=t([_,u,l,p]);[_,u,l,p]=b.then?(await b)():b;const v=24;class w extends o.WF{static async getConfigElement(){return await Promise.all([s.e(99143),s.e(66990),s.e(38076),s.e(36810)]).then(s.bind(s,67801)),document.createElement("hui-history-graph-card-editor")}static getStubConfig(){return{type:"history-graph",entities:["sun.sun"]}}getCardSize(){return this._config?.title?2:0+2*(this._entityIds?.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||v,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,g.KL)(this.hass))}catch(e){return void(this._subscribed===t&&(this._subscribed=void 0))}this.isConnected&&this._subscribed===t?(this._subscribed=(0,p.IQ)(this.hass,t=>{this._subscribed&&(this._stateHistory=(0,p.Mm)(this.hass,t,this._entityIds,this.hass.localize,e,this._config?.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(){this._stateHistory&&(this._history=(0,p.tG)(this._stateHistory,this._statisticsHistory,this._config?.split_device_classes))}async _fetchStatistics(t){if(this._hoursToShow<1)return;const e=new Date,s=new Date;s.setHours(s.getHours()-this._hoursToShow-1);const i=await(0,m.sz)(this.hass,s,e,this._entityIds,"hour",void 0,["mean","state"]);this._statisticsHistory=(0,p._1)(this.hass,i,this._entityIds,t,this._config?.split_device_classes),this._mergeHistory()}_redrawGraph(){this._history&&(this._history={...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=>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,f.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")||e?.entities===this._config.entities&&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(){if(!this.hass||!this._config)return o.s6;const t=new Date;t.setHours(t.getHours()-this._hoursToShow);const e=`/history?${(0,d.KH)({entity_id:this._entityIds.join(","),back:"1",start_date:t.toISOString()})}`,s=this._config.grid_options?.columns??12,i="number"==typeof s&&s<=12,r="number"==typeof this._config.grid_options?.rows;return o.qy` <ha-card> ${this._config.title?o.qy` <h1 class="card-header"> ${this._config.title} <a id="${this._historyLinkId}" href="${e}" aria-label="${this.hass.localize("panel.history")}"> <ha-icon-next></ha-icon-next> </a> <ha-tooltip for="${this._historyLinkId}" placement="left"> ${this.hass.localize("panel.history")} </ha-tooltip> </h1> `:o.s6} <div class="content ${(0,n.H)({"has-header":!!this._config.title,"has-rows":!!this._config.grid_options?.rows,"has-height":r})}"> ${this._error?o.qy` <ha-alert alert-type="error"> ${this.hass.localize("ui.components.history_charts.error")}: ${this._error.message||this._error.code} </ha-alert> `:o.qy` <state-history-charts .hass="${this.hass}" .isLoadingData="${!this._history}" .historyData="${this._history}" .names="${this._names}" up-to-now .hoursToShow="${this._hoursToShow}" .showNames="${void 0===this._config.show_names||this._config.show_names}" .logarithmicScale="${this._config.logarithmic_scale||!1}" .minYAxis="${this._config.min_y_axis}" .maxYAxis="${this._config.max_y_axis}" .fitYData="${this._config.fit_y_data||!1}" .colors="${this._colors}" .height="${r?"100%":void 0}" .narrow="${i}" .expandLegend="${this._config.expand_legend}"></state-history-charts> `} </div> </ha-card> `}constructor(...t){super(...t),this._names={},this._colors={},this._entityIds=[],this._entities=[],this._historyLinkId=`history-${Math.random().toString(36).substring(2,9)}`,this._hoursToShow=v}}w.styles=o.AH`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,a.MZ)({attribute:!1})],w.prototype,"hass",void 0),(0,r.Cg)([(0,a.wk)()],w.prototype,"_history",void 0),(0,r.Cg)([(0,a.wk)()],w.prototype,"_statisticsHistory",void 0),(0,r.Cg)([(0,a.wk)()],w.prototype,"_config",void 0),(0,r.Cg)([(0,a.wk)()],w.prototype,"_error",void 0),w=(0,r.Cg)([(0,a.EM)("hui-history-graph-card")],w),i()}catch(t){i(t)}})},6116(t,e,s){s.d(e,{o:()=>o});var i=s(6439),r=s(83339);function o(t,e,s){const o=(0,r.b)(t,e)/6e4;return(0,i.u)(s?.roundingMethod)(o)}}};