UNPKG

iobroker.lovelace

Version:

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

1 lines 11.4 kB
export const __rspack_esm_id=52808;export const __rspack_esm_ids=[52808];export const __webpack_modules__={58139(e,t,s){s.d(t,{d:()=>a,t:()=>i});const a=async(e,t)=>new Promise(s=>{const a=t(e,e=>{a(),s(e)})}),i=async e=>new Promise(t=>{const s=e.subscribe(e=>{s(),t(e)})})},64138(e,t,s){s.a(e,async function(e,a){try{s.r(t),s.d(t,{HaIconPicker:()=>b});s(74423),s(44114),s(18111),s(22489),s(7588),s(61701),s(13579);var i=s(62826),o=s(5124),r=s(22441),n=s(22786),l=s(1087),c=s(700),h=(s(75064),s(38508)),d=(s(47680),e([h]));h=(d.then?(await d)():d)[0];let u=[],p=!1;const g=(e,t)=>{const s=`${t}:${e.name}`,a=e.name,i=a.split("-"),o=e.keywords??[],r={iconName:a};return i.forEach((e,t)=>{r[`part${t}`]=e}),o.forEach((e,t)=>{r[`keyword${t}`]=e}),{id:s,primary:s,icon:s,search_labels:r,sorting_label:s}},m=async()=>{p=!0;const e=await s.e(81340).then(s.t.bind(s,25143,19));u=e.default.map(e=>g(e,"mdi"));const t=[];Object.keys(c.y).forEach(e=>{t.push(_(e))}),(await Promise.all(t)).forEach(e=>{u.push(...e)})},_=async e=>{try{const t=c.y[e].getIconList;if("function"!=typeof t)return[];return(await t()).map(t=>g(t,e))}catch(t){return console.warn(`Unable to load icon list for ${e} iconset`),[]}},f=e=>o.qy` <ha-combo-box-item type="button"> <ha-icon .icon="${e.id}" slot="start"></ha-icon> ${e.id} </ha-combo-box-item> `;class b extends o.WF{render(){return o.qy` <ha-generic-picker allow-custom-value .getItems="${this._getIconPickerItems}" .helper="${this.helper}" .disabled="${this.disabled}" .required="${this.required}" .errorMessage="${this.errorMessage}" .invalid="${this.invalid}" .rowRenderer="${f}" .icon="${this._icon}" .label="${this.label}" .value="${this._value}" .searchFn="${this._filterIcons}" @value-changed="${this._valueChanged}"> <slot name="start"></slot> </ha-generic-picker> `}firstUpdated(){p||m().then(()=>{this._getIconPickerItems=()=>u,this.requestUpdate()})}_valueChanged(e){e.stopPropagation(),this._setValue(e.detail.value)}_setValue(e){this.value=e,(0,l.r)(this,"value-changed",{value:this._value},{bubbles:!1,composed:!1})}get _icon(){return this.value?.length?this.value:this.placeholder}get _value(){return this.value||""}constructor(...e){super(...e),this.disabled=!1,this.required=!1,this.invalid=!1,this._getIconPickerItems=()=>u,this._filterIcons=(0,n.A)((e,t,s)=>{const a=e.toLowerCase().replace(/\s+/g,"-"),i=s?.length?s:t;if(!a.length)return i;const o=[];for(const e of i){const t=(e.id.split(":")[1]||e.id).toLowerCase().split("-"),s=e.search_labels?Object.values(e.search_labels).filter(e=>null!==e).map(e=>e.toLowerCase()):[],i=e.id.toLowerCase();t.includes(a)?o.push({item:e,rank:1}):s.includes(a)?o.push({item:e,rank:2}):i.includes(a)?o.push({item:e,rank:3}):s.some(e=>e.includes(a))&&o.push({item:e,rank:4})}return o.sort((e,t)=>e.rank-t.rank).map(e=>e.item)})}}b.styles=o.AH`ha-generic-picker{width:100%;display:block}`,(0,i.Cg)([(0,r.MZ)()],b.prototype,"value",void 0),(0,i.Cg)([(0,r.MZ)()],b.prototype,"label",void 0),(0,i.Cg)([(0,r.MZ)()],b.prototype,"helper",void 0),(0,i.Cg)([(0,r.MZ)()],b.prototype,"placeholder",void 0),(0,i.Cg)([(0,r.MZ)({attribute:"error-message"})],b.prototype,"errorMessage",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean})],b.prototype,"disabled",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean})],b.prototype,"required",void 0),(0,i.Cg)([(0,r.MZ)({type:Boolean})],b.prototype,"invalid",void 0),b=(0,i.Cg)([(0,r.EM)("ha-icon-picker")],b),a()}catch(e){a(e)}})},63891(e,t,s){var a=s(62826),i=s(5124),o=s(22441),r=s(36312),n=s(1087),l=s(49142);s(34296),s(67094);class c extends i.WF{firstUpdated(e){super.firstUpdated(e),this.hass&&(0,r.x)(this.hass.config,"ai_task")&&(0,l.sG)(this.hass).then(e=>{this._aiPrefs=e})}render(){if(!this._aiPrefs||!this._aiPrefs.gen_data_entity_id)return i.s6;let e;switch(this._state.status){case"error":e=this.hass.localize("ui.components.suggest_with_ai.error");break;case"done":e=this.hass.localize("ui.components.suggest_with_ai.done");break;case"suggesting":e=this.hass.localize(`ui.components.suggest_with_ai.suggesting_${this._state.suggestionIndex}`);break;default:e=this.hass.localize("ui.components.suggest_with_ai.label")}return i.qy` <ha-assist-chip @click="${this._suggest}" .label="${e}" ?active="${"suggesting"===this._state.status}" class="${"error"===this._state.status?"error":"done"===this._state.status?"done":""}" style="${this._minWidth?`min-width: ${this._minWidth}`:""}"> <ha-svg-icon slot="icon" .path="${"M12,1L9,9L1,12L9,15L12,23L15,15L23,12L15,9L12,1Z"}"></ha-svg-icon> </ha-assist-chip> `}async _suggest(){if(this.generateTask&&"suggesting"!==this._state.status){this._chip&&(this._minWidth=`${this._chip.offsetWidth}px`),this._state={status:"suggesting",suggestionIndex:1};try{this._intervalId=window.setInterval(()=>{this._state={...this._state,suggestionIndex:this._state.suggestionIndex%3+1}},3e3);const e=await this.generateTask();let t;if("data"!==e.type)throw new Error("Unsupported task type");t=await(0,l.Pj)(this.hass,e.task),(0,n.r)(this,"suggestion",t),this._state={...this._state,status:"done"}}catch(e){console.error("Error generating AI suggestion:",e),this._state={...this._state,status:"error"}}finally{this._intervalId&&(clearInterval(this._intervalId),this._intervalId=void 0),setTimeout(()=>{this._state={...this._state,status:"idle"},this._minWidth=void 0},3e3)}}}constructor(...e){super(...e),this._state={status:"idle",suggestionIndex:1}}}c.styles=i.AH`ha-assist-chip[active]{animation:pulse-glow 1.5s ease-in-out infinite}ha-assist-chip.error{box-shadow:0 0 12px 4px rgba(var(--rgb-error-color),.8)}ha-assist-chip.done{box-shadow:0 0 12px 4px rgba(var(--rgb-primary-color),.8)}@keyframes pulse-glow{0%{box-shadow:0 0 0 0 rgba(var(--rgb-primary-color),0)}50%{box-shadow:0 0 8px 2px rgba(var(--rgb-primary-color),.6)}100%{box-shadow:0 0 0 0 rgba(var(--rgb-primary-color),0)}}`,(0,a.Cg)([(0,o.MZ)({attribute:!1})],c.prototype,"hass",void 0),(0,a.Cg)([(0,o.MZ)({attribute:"task-type"})],c.prototype,"taskType",void 0),(0,a.Cg)([(0,o.MZ)({attribute:!1})],c.prototype,"generateTask",void 0),(0,a.Cg)([(0,o.wk)()],c.prototype,"_aiPrefs",void 0),(0,a.Cg)([(0,o.wk)()],c.prototype,"_state",void 0),(0,a.Cg)([(0,o.wk)()],c.prototype,"_minWidth",void 0),(0,a.Cg)([(0,o.P)("ha-assist-chip")],c.prototype,"_chip",void 0),c=(0,a.Cg)([(0,o.EM)("ha-suggest-with-ai-button")],c)},49142(e,t,s){s.d(t,{HU:()=>o,Pj:()=>r,sG:()=>i,xW:()=>a});var a=66649!=s.j?function(e){return e[e.GENERATE_DATA=1]="GENERATE_DATA",e[e.SUPPORT_ATTACHMENTS=2]="SUPPORT_ATTACHMENTS",e[e.GENERATE_IMAGE=4]="GENERATE_IMAGE",e}({}):null;const i=e=>e.callWS({type:"ai_task/preferences/get"}),o=(e,t)=>e.callWS({type:"ai_task/preferences/set",...t}),r=async(e,t)=>(await e.callService("ai_task","generate_data",t,void 0,!0,!0)).response},36215(e,t,s){s.a(e,async function(e,a){try{s.d(t,{Fn:()=>d,q3:()=>h});s(18111),s(22489),s(20116),s(61701);var i=s(74487),o=s(53289),r=s(91536),n=e([i]);i=(n.then?(await n)():n)[0];const l={name:!0,description:!0,categories:!0,labels:!0},c=new Intl.ListFormat("en",{style:"long",type:"conjunction"});async function h(e,t,s,a,i=[],n=l){const[h,d]=await Promise.all([n.categories?(0,r.jE)(e,s):Promise.resolve(void 0),n.floor?(0,r.q6)(e):Promise.resolve(void 0)]),u={...n.name&&{name:{description:`The name of the ${s}`,required:!0,selector:{text:{}}}},...n.description&&{description:{description:`A short description of the ${s}`,required:!1,selector:{text:{}}}},...n.labels&&{labels:{description:`Labels for the ${s}`,required:!1,selector:{text:{multiple:!0}}}},...n.categories&&h&&{category:{description:`The category of the ${s}`,required:!1,selector:{select:{options:Object.entries(h).map(([e,t])=>({value:e,label:t}))}}}},...n.floor&&d&&{floor:{description:`The floor of the ${s}`,required:!1,selector:{select:{options:Object.values(d).map(e=>({value:e.floor_id,label:e.name}))}}}}},p=[n.name?"a name":null,n.description?"a description":null,n.categories?"a category":null,n.labels?"labels":null,n.floor?"a floor":null].filter(e=>null!==e),g=[n.categories?"category":null,n.labels?"labels":null,n.floor?"floor":null].filter(e=>null!==e),m=c.format(g);return{type:"data",task:{task_name:`frontend__${s}__save`,instructions:[`Suggest in language "${t}" ${p.length?c.format(p):"suggestions"} for the following ioBroker ${s}.`,"",n.name?`The name should be relevant to the ${s}'s purpose.`:`The suggestions should be relevant to the ${s}'s purpose.`,...i.length?[...n.name?[`The name should be in same style and sentence capitalization as existing ${s}s.`]:[],...n.categories||n.labels||n.floor?[`Suggest ${m} if relevant to the ${s}'s purpose.`,`Only suggest ${m} that are already used by existing ${s}s.`]:[]]:n.name?[`The name should be short, descriptive, sentence case, and written in the language ${t}.`]:[],...n.description?[`If the ${s} contains 5+ steps, include a short description.`]:[],"",`For inspiration, here are existing ${s}s:`,i.join("\n"),"",`The ${s} configuration is as follows:`,"",`${(0,o.dump)(a)}`].join("\n"),structure:u}}}async function d(e,t,s,a=l){const[i,o,n]=await Promise.all([a.categories?(0,r.jE)(e,t):Promise.resolve(void 0),a.labels?(0,r.wR)(e):Promise.resolve(void 0),a.floor?(0,r.q6)(e):Promise.resolve(void 0)]),c={name:a.name?s.data.name:void 0,description:a.description?s.data.description:void 0};if(a.categories&&i&&s.data.category){const e=Object.entries(i).find(([,e])=>e===s.data.category)?.[0];e&&(c.category=e)}if(a.labels&&o&&s.data.labels?.length){const e=Object.fromEntries(s.data.labels.map(e=>[e,void 0]));let t=s.data.labels.length;for(const[s,a]of Object.entries(o))if(a in e&&void 0===e[a]&&(e[a]=s,t--,0===t))break;const a=Object.values(e).filter(e=>void 0!==e);a.length&&(c.labels=a)}if(a.floor&&n&&s.data.floor){const e=s.data.floor in n?s.data.floor:Object.entries(n).find(([,e])=>e.name===s.data.floor)?.[0];e&&(c.floor=e)}return c}a()}catch(u){a(u)}})},91536(e,t,s){s.d(t,{RF:()=>p,U3:()=>g,jE:()=>h,q6:()=>u,wR:()=>d});s(18111),s(61701);var a=s(58139),i=s(2514),o=s(76570),r=s(59241),n=s(42961),l=s(92557);const c=e=>e.catch(e=>(console.error("Error fetching data for suggestion: ",e),{})),h=(e,t)=>c((0,o.AH)(e,t).then(e=>Object.fromEntries(e.map(e=>[e.category_id,e.name])))),d=e=>c((0,a.d)(e,l.o5).then(e=>Object.fromEntries(e.map(e=>[e.label_id,e.name])))),u=e=>c((0,a.d)(e,n.e).then(e=>Object.fromEntries(e.map(e=>[e.floor_id,e])))),p=e=>c((0,a.d)(e,i.ft).then(e=>Object.fromEntries(e.map(e=>[e.area_id,e])))),g=e=>c((0,a.d)(e,r.Bz).then(e=>Object.fromEntries(e.map(e=>[e.entity_id,e]))))},97268(e,t,s){s.d(t,{U:()=>r,m:()=>o});s(44114),s(18111),s(22489),s(61701),s(18237);if(66649!=s.j)var a=s(71727);var i=s(91536);const o=async(e,t,s)=>{const[o,r,n]=await Promise.all([(0,i.jE)(e,s),(0,i.U3)(e),(0,i.wR)(e)]);return Object.values(r).reduce((e,i)=>{if(!i||(0,a.m)(i.entity_id)!==s)return e;const r=t[i.entity_id];if(!r||r.attributes.restored||!r.attributes.friendly_name)return e;let l=`- ${r.attributes.friendly_name}`;const c=i.categories[s];if(c&&o[c]&&(l+=` (category: ${o[c]})`),i.labels.length){const e=i.labels.map(e=>n[e]).filter(Boolean);e.length&&(l+=` (labels: ${e.join(", ")})`)}return e.push(l),e},[])},r=async e=>{const[t,s,a]=await Promise.all([(0,i.wR)(e),(0,i.q6)(e),(0,i.RF)(e)]);return Object.values(a).reduce((e,a)=>{if(!a.floor_id)return e;const i=s[a.floor_id]?.name,o=a.labels.map(e=>t[e]).filter(Boolean);return e.push(`- ${a.name} (${i?`floor: ${i}`:"no floor"}${o.length?`, labels: ${o.join(", ")}`:""})`),e},[])}}};