c.62767b73.js 175 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985
  1. import{aR as e,aS as t,aT as i,aU as a,aV as o,aW as n,aX as s,aY as d,aZ as r,a_ as l,a$ as c,b0 as u,b1 as h,b2 as v,d as g,_ as p,j as m,e as f,t as y,i as k,y as _,b3 as b,k as $,E as x,G as w,J as C,ad as z,n as M,m as A,aB as O,aC as T,b4 as P,b5 as U,b6 as E,b7 as j,b8 as F,b9 as I,ba as S,bb as L,bc as N,aD as B,bd as D,be as q,bf as W,bg as R,bh as K,bi as V,a5 as X,as as Y,ar as G,bj as J,bk as H,bl as Q,bm as Z,bn as ee,bo as te,bp as ie,bq as ae,P as oe,Q as ne,U as se,C as de,I as re,br as le}from"./main-ec7846c8.js";import{d as ce}from"./c.10855172.js";import{c as ue}from"./c.55291b50.js";import{s as he,c as ve}from"./c.874c8cfd.js";import{L as ge,s as pe}from"./c.eea05cf6.js";import{d as me}from"./c.541a83df.js";import{f as fe,c as ye}from"./c.8d65df0a.js";import"./c.23dcece3.js";import{s as ke}from"./c.468b43fb.js";import{e as _e}from"./c.3f62d98e.js";import{c as be}from"./c.6eb9fcd4.js";import{e as $e,c as xe,a as we}from"./c.84dcc549.js";import{d as Ce}from"./c.05172f3d.js";import{s as ze,a as Me,b as Ae}from"./c.cb96fbc8.js";import"./c.2f01b935.js";import{d as Oe}from"./c.0e3055bd.js";import"./c.f490cc01.js";import"./c.980b1140.js";import"./c.0a3ec415.js";import{f as Te}from"./c.fad05014.js";import{c as Pe}from"./c.fa0ef026.js";import"./c.40adef15.js";import"./c.fb45139f.js";import"./c.8e28b461.js";import"./c.3db34379.js";import"./c.417318ff.js";import"./c.227858d9.js";import"./c.128a6b66.js";import"./c.aaeac12d.js";import"./c.743a15a1.js";import"./c.2610e8cd.js";import"./c.a0946910.js";import"./c.d8036e66.js";import"./c.1024e243.js";import"./c.d2f13ac1.js";import"./c.811f664e.js";import"./c.04ecc0ad.js";import"./c.5fe2e3ab.js";import"./c.749b9503.js";import"./c.79c8c092.js";import"./c.4f015773.js";import"./c.87e5362a.js";import"./c.07e395f8.js";const Ue={condition:e,delay:t,event:i,play_media:a,activate_scene:o,service:n,wait_template:s,wait_for_trigger:d,repeat:r,choose:l,if:c,device_id:u,stop:h,parallel:v},Ee=g`
  2. #sortable a:nth-of-type(2n) paper-icon-item {
  3. animation-name: keyframes1;
  4. animation-iteration-count: infinite;
  5. transform-origin: 50% 10%;
  6. animation-delay: -0.75s;
  7. animation-duration: 0.25s;
  8. }
  9. #sortable a:nth-of-type(2n-1) paper-icon-item {
  10. animation-name: keyframes2;
  11. animation-iteration-count: infinite;
  12. animation-direction: alternate;
  13. transform-origin: 30% 5%;
  14. animation-delay: -0.5s;
  15. animation-duration: 0.33s;
  16. }
  17. #sortable a {
  18. height: 48px;
  19. display: flex;
  20. }
  21. #sortable {
  22. outline: none;
  23. display: block !important;
  24. }
  25. .hidden-panel {
  26. display: flex !important;
  27. }
  28. .sortable-fallback {
  29. display: none;
  30. }
  31. .sortable-ghost {
  32. opacity: 0.4;
  33. }
  34. .sortable-fallback {
  35. opacity: 0;
  36. }
  37. @keyframes keyframes1 {
  38. 0% {
  39. transform: rotate(-1deg);
  40. animation-timing-function: ease-in;
  41. }
  42. 50% {
  43. transform: rotate(1.5deg);
  44. animation-timing-function: ease-out;
  45. }
  46. }
  47. @keyframes keyframes2 {
  48. 0% {
  49. transform: rotate(1deg);
  50. animation-timing-function: ease-in;
  51. }
  52. 50% {
  53. transform: rotate(-1.5deg);
  54. animation-timing-function: ease-out;
  55. }
  56. }
  57. .show-panel,
  58. .hide-panel {
  59. display: none;
  60. position: absolute;
  61. top: 0;
  62. right: 4px;
  63. --mdc-icon-button-size: 40px;
  64. }
  65. :host([rtl]) .show-panel {
  66. right: initial;
  67. left: 4px;
  68. }
  69. .hide-panel {
  70. top: 4px;
  71. right: 8px;
  72. }
  73. :host([rtl]) .hide-panel {
  74. right: initial;
  75. left: 8px;
  76. }
  77. :host([expanded]) .hide-panel {
  78. display: block;
  79. }
  80. :host([expanded]) .show-panel {
  81. display: inline-flex;
  82. }
  83. paper-icon-item.hidden-panel,
  84. paper-icon-item.hidden-panel span,
  85. paper-icon-item.hidden-panel ha-icon[slot="item-icon"] {
  86. color: var(--secondary-text-color);
  87. cursor: pointer;
  88. }
  89. `;let je;const Fe=async()=>(je||(je=(await import("./c.c177bbc3.js")).default),je);class Ie extends TypeError{constructor(e,t){let i;const{message:a,...o}=e,{path:n}=e;super(0===n.length?a:"At path: "+n.join(".")+" -- "+a),this.value=void 0,this.key=void 0,this.type=void 0,this.refinement=void 0,this.path=void 0,this.branch=void 0,this.failures=void 0,Object.assign(this,o),this.name=this.constructor.name,this.failures=()=>{var a;return null!=(a=i)?a:i=[e,...t()]}}}function Se(e){return"object"==typeof e&&null!=e}function Le(e){return"string"==typeof e?JSON.stringify(e):""+e}function Ne(e,t,i,a){if(!0===e)return;!1===e?e={}:"string"==typeof e&&(e={message:e});const{path:o,branch:n}=t,{type:s}=i,{refinement:d,message:r="Expected a value of type `"+s+"`"+(d?" with refinement `"+d+"`":"")+", but received: `"+Le(a)+"`"}=e;return{value:a,type:s,refinement:d,key:o[o.length-1],path:o,branch:n,...e,message:r}}function*Be(e,t,i,a){(function(e){return Se(e)&&"function"==typeof e[Symbol.iterator]})(e)||(e=[e]);for(const o of e){const e=Ne(o,t,i,a);e&&(yield e)}}function*De(e,t,i){void 0===i&&(i={});const{path:a=[],branch:o=[e],coerce:n=!1,mask:s=!1}=i,d={path:a,branch:o};if(n&&(e=t.coercer(e,d),s&&"type"!==t.type&&Se(t.schema)&&Se(e)&&!Array.isArray(e)))for(const i in e)void 0===t.schema[i]&&delete e[i];let r=!0;for(const i of t.validator(e,d))r=!1,yield[i,void 0];for(let[i,l,c]of t.entries(e,d)){const t=De(l,c,{path:void 0===i?a:[...a,i],branch:void 0===i?o:[...o,l],coerce:n,mask:s});for(const a of t)a[0]?(r=!1,yield[a[0],void 0]):n&&(l=a[1],void 0===i?e=l:e instanceof Map?e.set(i,l):e instanceof Set?e.add(l):Se(e)&&(e[i]=l))}if(r)for(const i of t.refiner(e,d))r=!1,yield[i,void 0];r&&(yield[void 0,e])}class qe{constructor(e){this.TYPE=void 0,this.type=void 0,this.schema=void 0,this.coercer=void 0,this.validator=void 0,this.refiner=void 0,this.entries=void 0;const{type:t,schema:i,validator:a,refiner:o,coercer:n=(e=>e),entries:s=function*(){}}=e;this.type=t,this.schema=i,this.entries=s,this.coercer=n,this.validator=a?(e,t)=>Be(a(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>Be(o(e,t),t,this,e):()=>[]}assert(e){return We(e,this)}create(e){return function(e,t){const i=Ke(e,t,{coerce:!0});if(i[0])throw i[0];return i[1]}(e,this)}is(e){return Re(e,this)}mask(e){return function(e,t){const i=Ke(e,t,{coerce:!0,mask:!0});if(i[0])throw i[0];return i[1]}(e,this)}validate(e,t){return void 0===t&&(t={}),Ke(e,this,t)}}function We(e,t){const i=Ke(e,t);if(i[0])throw i[0]}function Re(e,t){return!Ke(e,t)[0]}function Ke(e,t,i){void 0===i&&(i={});const a=De(e,t,i),o=function(e){const{done:t,value:i}=e.next();return t?void 0:i}(a);if(o[0]){const e=new Ie(o[0],(function*(){for(const e of a)e[0]&&(yield e[0])}));return[e,void 0]}return[void 0,o[1]]}function Ve(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];const a="type"===t[0].type,o=t.map((e=>e.schema)),n=Object.assign({},...o);return a?it(n):Ze(n)}function Xe(e,t){return new qe({type:e,schema:null,validator:t})}function Ye(){return Xe("any",(()=>!0))}function Ge(e){return new qe({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[i,a]of t.entries())yield[i,a,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||"Expected an array value, but received: "+Le(e)})}function Je(){return Xe("boolean",(e=>"boolean"==typeof e))}function He(e){const t=Le(e),i=typeof e;return new qe({type:"literal",schema:"string"===i||"number"===i||"boolean"===i?e:null,validator:i=>i===e||"Expected the literal `"+t+"`, but received: "+Le(i)})}function Qe(){return Xe("number",(e=>"number"==typeof e&&!isNaN(e)||"Expected a number, but received: "+Le(e)))}function Ze(e){const t=e?Object.keys(e):[],i=Xe("never",(()=>!1));return new qe({type:"object",schema:e||null,*entries(a){if(e&&Se(a)){const o=new Set(Object.keys(a));for(const i of t)o.delete(i),yield[i,a[i],e[i]];for(const e of o)yield[e,a[e],i]}},validator:e=>Se(e)||"Expected an object, but received: "+Le(e),coercer:e=>Se(e)?{...e}:e})}function et(e){return new qe({...e,validator:(t,i)=>void 0===t||e.validator(t,i),refiner:(t,i)=>void 0===t||e.refiner(t,i)})}function tt(){return Xe("string",(e=>"string"==typeof e||"Expected a string, but received: "+Le(e)))}function it(e){const t=Object.keys(e);return new qe({type:"type",schema:e,*entries(i){if(Se(i))for(const a of t)yield[a,i[a],e[a]]},validator:e=>Se(e)||"Expected an object, but received: "+Le(e)})}function at(e){const t=e.map((e=>e.type)).join(" | ");return new qe({type:"union",schema:null,coercer(t,i){const a=e.find((e=>{const[i]=e.validate(t,{coerce:!0});return!i}))||Xe("unknown",(()=>!0));return a.coercer(t,i)},validator(i,a){const o=[];for(const t of e){const[...e]=De(i,t,a),[n]=e;if(!n[0])return[];for(const[t]of e)t&&o.push(t)}return["Expected the value to satisfy a union of `"+t+"`, but received: "+Le(i),...o]}})}const ot=(e,t)=>{if(!(t instanceof Ie))return{warnings:[t.message],errors:void 0};const i=[],a=[];for(const o of t.failures())if(void 0===o.value)i.push(e.localize("ui.errors.config.key_missing","key",o.path.join(".")));else if("never"===o.type)a.push(e.localize("ui.errors.config.key_not_expected","key",o.path.join(".")));else{if("union"===o.type)continue;"enums"===o.type?a.push(e.localize("ui.errors.config.key_wrong_type","key",o.path.join("."),"type_correct",o.message.replace("Expected ","").split(", ")[0],"type_wrong",JSON.stringify(o.value))):a.push(e.localize("ui.errors.config.key_wrong_type","key",o.path.join("."),"type_correct",o.refinement||o.type,"type_wrong",JSON.stringify(o.value)))}return{warnings:a,errors:i}};p([M("ha-expansion-panel")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({type:Boolean,reflect:!0})],key:"expanded",value:()=>!1},{kind:"field",decorators:[f({type:Boolean,reflect:!0})],key:"outlined",value:()=>!1},{kind:"field",decorators:[f({type:Boolean,reflect:!0})],key:"leftChevron",value:()=>!1},{kind:"field",decorators:[f()],key:"header",value:void 0},{kind:"field",decorators:[f()],key:"secondary",value:void 0},{kind:"field",decorators:[y()],key:"_showContent",value(){return this.expanded}},{kind:"field",decorators:[k(".container")],key:"_container",value:void 0},{kind:"method",key:"render",value:function(){return _`
  90. <div class="top">
  91. <div
  92. id="summary"
  93. @click=${this._toggleContainer}
  94. @keydown=${this._toggleContainer}
  95. @focus=${this._focusChanged}
  96. @blur=${this._focusChanged}
  97. role="button"
  98. tabindex="0"
  99. aria-expanded=${this.expanded}
  100. aria-controls="sect1"
  101. >
  102. ${this.leftChevron?_`
  103. <ha-svg-icon
  104. .path=${b}
  105. class="summary-icon ${$({expanded:this.expanded})}"
  106. ></ha-svg-icon>
  107. `:""}
  108. <slot name="header">
  109. <div class="header">
  110. ${this.header}
  111. <slot class="secondary" name="secondary">${this.secondary}</slot>
  112. </div>
  113. </slot>
  114. ${this.leftChevron?"":_`
  115. <ha-svg-icon
  116. .path=${b}
  117. class="summary-icon ${$({expanded:this.expanded})}"
  118. ></ha-svg-icon>
  119. `}
  120. </div>
  121. <slot name="icons"></slot>
  122. </div>
  123. <div
  124. class="container ${$({expanded:this.expanded})}"
  125. @transitionend=${this._handleTransitionEnd}
  126. role="region"
  127. aria-labelledby="summary"
  128. aria-hidden=${!this.expanded}
  129. tabindex="-1"
  130. >
  131. ${this._showContent?_`<slot></slot>`:""}
  132. </div>
  133. `}},{kind:"method",key:"willUpdate",value:function(e){x(w(i.prototype),"willUpdate",this).call(this,e),e.has("expanded")&&this.expanded&&(this._showContent=this.expanded,setTimeout((()=>{this.expanded&&(this._container.style.overflow="initial")}),300))}},{kind:"method",key:"_handleTransitionEnd",value:function(){this._container.style.removeProperty("height"),this._container.style.overflow=this.expanded?"initial":"hidden",this._showContent=this.expanded}},{kind:"method",key:"_toggleContainer",value:async function(e){if(e.defaultPrevented)return;if("keydown"===e.type&&"Enter"!==e.key&&" "!==e.key)return;e.preventDefault();const t=!this.expanded;C(this,"expanded-will-change",{expanded:t}),this._container.style.overflow="hidden",t&&(this._showContent=!0,await z());const i=this._container.scrollHeight;this._container.style.height=`${i}px`,t||setTimeout((()=>{this._container.style.height="0px"}),0),this.expanded=t,C(this,"expanded-changed",{expanded:this.expanded})}},{kind:"method",key:"_focusChanged",value:function(e){this.shadowRoot.querySelector(".top").classList.toggle("focused","focus"===e.type)}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  134. :host {
  135. display: block;
  136. }
  137. .top {
  138. display: flex;
  139. align-items: center;
  140. }
  141. .top.focused {
  142. background: var(--input-fill-color);
  143. }
  144. :host([outlined]) {
  145. box-shadow: none;
  146. border-width: 1px;
  147. border-style: solid;
  148. border-color: var(
  149. --ha-card-border-color,
  150. var(--divider-color, #e0e0e0)
  151. );
  152. border-radius: var(--ha-card-border-radius, 16px);
  153. }
  154. .summary-icon {
  155. margin-left: 8px;
  156. }
  157. :host([leftchevron]) .summary-icon {
  158. margin-left: 0;
  159. margin-right: 8px;
  160. }
  161. #summary {
  162. flex: 1;
  163. display: flex;
  164. padding: var(--expansion-panel-summary-padding, 0 8px);
  165. min-height: 48px;
  166. align-items: center;
  167. cursor: pointer;
  168. overflow: hidden;
  169. font-weight: 500;
  170. outline: none;
  171. }
  172. .summary-icon {
  173. transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
  174. direction: var(--direction);
  175. }
  176. .summary-icon.expanded {
  177. transform: rotate(180deg);
  178. }
  179. .header,
  180. ::slotted([slot="header"]) {
  181. flex: 1;
  182. }
  183. .container {
  184. padding: var(--expansion-panel-content-padding, 0 8px);
  185. overflow: hidden;
  186. transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1);
  187. height: 0px;
  188. }
  189. .container.expanded {
  190. height: auto;
  191. }
  192. .secondary {
  193. display: block;
  194. color: var(--secondary-text-color);
  195. font-size: 12px;
  196. }
  197. `}}]}}),m);const nt=(e,t)=>e.callWS({type:"validate_config",...t}),st=Ze({alias:et(tt()),enabled:et(Je())}),dt=Ze({entity_id:et(at([tt(),Ge(tt())])),device_id:et(at([tt(),Ge(tt())])),area_id:et(at([tt(),Ge(tt())]))});Ve(st,Ze({service:et(tt()),service_template:et(tt()),entity_id:et(tt()),target:et(dt),data:et(Ze())}));const rt=Ve(st,Ze({service:He("media_player.play_media"),target:et(Ze({entity_id:et(tt())})),entity_id:et(tt()),data:Ze({media_content_id:tt(),media_content_type:tt()}),metadata:Ze()})),lt=Ve(st,Ze({service:He("scene.turn_on"),target:et(Ze({entity_id:et(tt())})),entity_id:et(tt()),metadata:Ze()})),ct=e=>{if("delay"in e)return"delay";if("wait_template"in e)return"wait_template";if(["condition","and","or","not"].some((t=>t in e)))return"check_condition";if("event"in e)return"fire_event";if("device_id"in e)return"device_action";if("scene"in e)return"activate_scene";if("repeat"in e)return"repeat";if("choose"in e)return"choose";if("if"in e)return"if";if("wait_for_trigger"in e)return"wait_for_trigger";if("variables"in e)return"variables";if("stop"in e)return"stop";if("parallel"in e)return"parallel";if("service"in e){if("metadata"in e){if(Re(e,lt))return"activate_scene";if(Re(e,rt))return"play_media"}return"service"}return"unknown"},ut=e=>e<10?`0${e}`:e,ht=e=>{const t=e.days||0,i=e.hours||0,a=e.minutes||0,o=e.seconds||0,n=e.milliseconds||0;return t>0?`${t} day${1===t?"":"s"} ${i}:${ut(a)}:${ut(o)}`:i>0?`${i}:${ut(a)}:${ut(o)}`:a>0?`${a}:${ut(o)}`:o>0?`${o} second${1===o?"":"s"}`:n>0?`${n} millisecond${1===n?"":"s"}`:null},vt=new RegExp("{%|{{"),gt=e=>vt.test(e),pt=e=>{if(!e)return!1;if("string"==typeof e)return gt(e);if("object"==typeof e){return(Array.isArray(e)?e:Object.values(e)).some((e=>e&&pt(e)))}return!1},mt=(e,t)=>e.callWS({type:"device_automation/action/list",device_id:t}),ft=(e,t)=>e.callWS({type:"device_automation/condition/list",device_id:t}),yt=(e,t)=>e.callWS({type:"device_automation/trigger/list",device_id:t}),kt=["device_id","domain","entity_id","type","subtype","event","condition","platform"],_t=(e,t)=>{if(typeof e!=typeof t)return!1;for(const i in e)if(kt.includes(i)&&!Object.is(e[i],t[i]))return!1;for(const i in t)if(kt.includes(i)&&!Object.is(e[i],t[i]))return!1;return!0},bt=(e,t)=>{const i=t.entity_id?e.states[t.entity_id]:void 0;return e.localize(`component.${t.domain}.device_automation.action_type.${t.type}`,"entity_name",i?be(i):t.entity_id||"<unknown>","subtype",t.subtype?e.localize(`component.${t.domain}.device_automation.action_subtype.${t.subtype}`)||t.subtype:"")||(t.subtype?`"${t.subtype}" ${t.type}`:t.type)},$t=(e,t)=>{const i=t.entity_id?e.states[t.entity_id]:void 0;return e.localize(`component.${t.domain}.device_automation.condition_type.${t.type}`,"entity_name",i?be(i):t.entity_id||"<unknown>","subtype",t.subtype?e.localize(`component.${t.domain}.device_automation.condition_subtype.${t.subtype}`)||t.subtype:"")||(t.subtype?`"${t.subtype}" ${t.type}`:t.type)},xt=(e,t)=>{const i=t.entity_id?e.states[t.entity_id]:void 0;return e.localize(`component.${t.domain}.device_automation.trigger_type.${t.type}`,"entity_name",i?be(i):t.entity_id||"<unknown>","subtype",t.subtype?e.localize(`component.${t.domain}.device_automation.trigger_subtype.${t.subtype}`)||t.subtype:"")||(t.subtype?`"${t.subtype}" ${t.type}`:t.type)},wt=(e,t)=>{var i,a,o,n;return null===(i=e.metadata)||void 0===i||!i.secondary||null!==(a=t.metadata)&&void 0!==a&&a.secondary?null!==(o=e.metadata)&&void 0!==o&&o.secondary||null===(n=t.metadata)||void 0===n||!n.secondary?0:-1:1},Ct=(e,t,i=!1)=>{if(e.alias&&!i)return e.alias;if("event"===e.platform&&e.event_type){let t="";if(Array.isArray(e.event_type))for(const[i,a]of e.event_type.entries())t+=`${i>0?",":""} ${e.event_type.length>1&&i===e.event_type.length-1?"or":""} ${a}`;else t=e.event_type.toString();return`When ${t} event is fired`}if("homeassistant"===e.platform&&e.event)return"When Home Assistant is "+("start"===e.event?"started":"shutdown");if("numeric_state"===e.platform&&e.entity_id){let i="When";const a=t.states[e.entity_id],o=a?be(a):e.entity_id;if(e.attribute&&(i+=` ${fe(e.attribute)} from`),i+=` ${o} is`,void 0!==e.above&&(i+=` above ${e.above}`),void 0!==e.below&&void 0!==e.above&&(i+=" and"),void 0!==e.below&&(i+=` below ${e.below}`),e.for){let t;t="number"==typeof e.for?ke(e.for):"string"==typeof e.for?e.for:ht(e.for),t&&(i+=` for ${t}`)}return i}if("state"===e.platform){let i="When",a="";const o=t.states;if(e.attribute&&(i+=` ${fe(e.attribute)} from`),Array.isArray(e.entity_id))for(const[t,i]of e.entity_id.entries())o[i]&&(a+=`${t>0?",":""} ${e.entity_id.length>1&&t===e.entity_id.length-1?"or":""} ${be(o[i])||i}`);else e.entity_id&&(a=o[e.entity_id]?be(o[e.entity_id]):e.entity_id);if(a||(a="something"),i+=` ${a} changes`,e.from){let t="";if(Array.isArray(e.from))for(const[i,a]of e.from.entries())t+=`${i>0?",":""} ${e.from.length>1&&i===e.from.length-1?"or":""} ${a}`;else t=e.from.toString();i+=` from ${t}`}if(e.to){let t="";if(Array.isArray(e.to))for(const[i,a]of e.to.entries())t+=`${i>0?",":""} ${e.to.length>1&&i===e.to.length-1?"or":""} ${a}`;else e.to&&(t=e.to.toString());i+=` to ${t}`}if(e.for){let t;t="number"==typeof e.for?ke(e.for):"string"==typeof e.for?e.for:ht(e.for),t&&(i+=` for ${t}`)}return i}if("sun"===e.platform&&e.event){let t="When the sun "+("sunset"===e.event?"sets":"rises");if(e.offset){let i="";e.offset&&(i="number"==typeof e.offset?` offset by ${ke(e.offset)}`:"string"==typeof e.offset?` offset by ${e.offset}`:` offset by ${JSON.stringify(e.offset)}`),t+=i}return t}if("tag"===e.platform)return"When a tag is scanned";if("time"===e.platform&&e.at){const i=_e(e.at).map((e=>e.toString().includes(".")?`entity ${t.states[e]?be(t.states[e]):e}`:e)),a=i.splice(-1,1)[0];return`When the time is equal to ${i.length?`${i.join(", ")} or `:""}${a}`}if("time_pattern"===e.platform)return"Time pattern trigger";if("zone"===e.platform&&e.entity_id&&e.zone){let i="",a="",o=!1;const n=t.states;if(Array.isArray(e.entity_id))for(const[t,a]of e.entity_id.entries())n[a]&&(i+=`${t>0?",":""} ${e.entity_id.length>1&&t===e.entity_id.length-1?"or":""} ${be(n[a])||a}`);else i=n[e.entity_id]?be(n[e.entity_id]):e.entity_id;if(Array.isArray(e.zone)){e.zone.length>1&&(o=!0);for(const[t,i]of e.zone.entries())n[i]&&(a+=`${t>0?",":""} ${e.zone.length>1&&t===e.zone.length-1?"or":""} ${be(n[i])||i}`)}else a=n[e.zone]?be(n[e.zone]):e.zone;return`When ${i} ${e.event}s ${a} ${o?"zones":"zone"}`}if("geo_location"===e.platform&&e.source&&e.zone){let i="",a="",o=!1;const n=t.states;if(Array.isArray(e.source))for(const[t,a]of e.source.entries())i+=`${t>0?",":""} ${e.source.length>1&&t===e.source.length-1?"or":""} ${a}`;else i=e.source;if(Array.isArray(e.zone)){e.zone.length>1&&(o=!0);for(const[t,i]of e.zone.entries())n[i]&&(a+=`${t>0?",":""} ${e.zone.length>1&&t===e.zone.length-1?"or":""} ${be(n[i])||i}`)}else a=n[e.zone]?be(n[e.zone]):e.zone;return`When ${i} ${e.event}s ${a} ${o?"zones":"zone"}`}if("mqtt"===e.platform)return"When an MQTT message has been received";if("template"===e.platform)return"When a template triggers";if("webhook"===e.platform)return"When a Webhook payload has been received";if("device"===e.platform){if(!e.device_id)return"Device trigger";const i=e,a=xt(t,i);if(a)return a;const o=t.states[i.entity_id];return`${o?be(o):i.entity_id} ${i.type}`}return`${e.platform?e.platform.replace(/_/g," "):"Unknown"} trigger`},zt=(e,t,i=!1)=>{if(e.alias&&!i)return e.alias;if(!e.condition){const t=["and","or","not"];for(const i of t)i in e&&_e(e[i])&&(e={condition:i,conditions:e[i]})}if("or"===e.condition){const t=_e(e.conditions);if(!t||0===t.length)return"Test if any condition matches";const i=t.length;return`Test if any of ${i} condition${1===i?"":"s"} matches`}if("and"===e.condition){const t=_e(e.conditions);if(!t||0===t.length)return"Test if multiple conditions match";const i=t.length;return`Test if ${i} condition${1===i?"":"s"} match${1===i?"es":""}`}if("not"===e.condition){const t=_e(e.conditions);return t&&0!==t.length?1===t.length?"Test if 1 condition does not match":`Test if none of ${t.length} conditions match`:"Test if no condition matches"}if("state"===e.condition){let i="Confirm";const a=t.states[e.entity_id],o=a?be(a):e.entity_id?e.entity_id:"an entity";"attribute"in e&&(i+=` ${e.attribute} from`);let n="";if(Array.isArray(e.state))for(const[t,i]of e.state.entries())n+=`${t>0?",":""} ${e.state.length>1&&t===e.state.length-1?"or":""} ${i}`;else e.state&&(n=e.state.toString());if(n||(n="a state"),i+=` ${o} is ${n}`,e.for){let t;t="number"==typeof e.for?ke(e.for):"string"==typeof e.for?e.for:ht(e.for),t&&(i+=` for ${t}`)}return i}if("numeric_state"===e.condition&&e.entity_id){let i="Confirm";const a=t.states[e.entity_id],o=a?be(a):e.entity_id;return"attribute"in e&&(i+=` ${e.attribute} from`),i+=` ${o} is`,"above"in e&&(i+=` above ${e.above}`),"below"in e&&"above"in e&&(i+=" and"),"below"in e&&(i+=` below ${e.below}`),i}if("sun"===e.condition&&("before"in e||"after"in e)){let t="Confirm";if(!e.after&&!e.before)return t+=" sun",t;if(t+=" sun",e.after){let i="";e.after_offset&&(i="number"==typeof e.after_offset?` offset by ${ke(e.after_offset)}`:"string"==typeof e.after_offset?` offset by ${e.after_offset}`:` offset by ${JSON.stringify(e.after_offset)}`),t+=` after ${e.after}${i}`}return e.before&&(t+=` before ${e.before}`),t}if("zone"===e.condition&&e.entity_id&&e.zone){let i="",a=!1,o="",n=!1;const s=t.states;if(Array.isArray(e.entity_id)){e.entity_id.length>1&&(a=!0);for(const[t,a]of e.entity_id.entries())s[a]&&(i+=`${t>0?",":""} ${e.entity_id.length>1&&t===e.entity_id.length-1?"or":""} ${be(s[a])||a}`)}else i=s[e.entity_id]?be(s[e.entity_id]):e.entity_id;if(Array.isArray(e.zone)){e.zone.length>1&&(n=!0);for(const[t,i]of e.zone.entries())s[i]&&(o+=`${t>0?",":""} ${e.zone.length>1&&t===e.zone.length-1?"or":""} ${be(s[i])||i}`)}else o=s[e.zone]?be(s[e.zone]):e.zone;return`Confirm ${i} ${a?"are":"is"} in ${o} ${n?"zones":"zone"}`}if("device"===e.condition){if(!e.device_id)return"Device condition";const i=e,a=$t(t,i);if(a)return a;const o=t.states[i.entity_id];return`${o?be(o):i.entity_id} ${i.type}`}return"trigger"===e.condition?e.id?`When triggered by ${e.id}`:"Trigger condition":`${e.condition?e.condition.replace(/_/g," "):"Unknown"} condition`},Mt=(e,t,i,a=!1)=>{if(t.alias&&!a)return t.alias;if(i||(i=ct(t)),"service"===i){const i=t;let a;if(i.service_template||i.service&&gt(i.service))a="Call a service based on a template";else{if(!i.service)return"Call a service";{const[t,o]=i.service.split(".",2),n=e.services[t][o];a=n?`${Ce(e.localize,t)}: ${n.name}`:`Call service: ${i.service}`}}if(i.target){const t=[];for(const[a,o]of Object.entries({area_id:"areas",device_id:"devices",entity_id:"entities"})){if(!(a in i.target))continue;const n=Array.isArray(i.target[a])?i.target[a]:[i.target[a]];for(const i of n){if(gt(i)){t.push(`templated ${o}`);break}if("entity_id"===a)if(i.includes(".")){const a=e.states[i];a?t.push(be(a)):t.push(i)}else{const a=$e(e.entities)[i];a?t.push(xe(e,a)||i):t.push("unknown entity")}else if("device_id"===a){const a=e.devices[i];a?t.push(we(a,e)):t.push("unknown device")}else if("area_id"===a){const a=e.areas[i];null!=a&&a.name?t.push(a.name):t.push("unknown area")}else t.push(i)}}t.length>0&&(a+=` ${t.join(", ")}`)}return a}if("delay"===i){const e=t;let i;return i="number"==typeof e.delay?`for ${ke(e.delay)}`:"string"==typeof e.delay?gt(e.delay)?"based on a template":`for ${e.delay||"a duration"}`:e.delay?`for ${ht(e.delay)}`:"for a duration",`Delay ${i}`}if("activate_scene"===i){const i=t;let a;var o;if("scene"in i)a=i.scene;else a=(null===(o=i.target)||void 0===o?void 0:o.entity_id)||i.entity_id;if(!a)return"Activate a scene";const n=a?e.states[a]:void 0;return`Activate scene ${n?be(n):a}`}if("play_media"===i){var n;const i=t,a=(null===(n=i.target)||void 0===n?void 0:n.entity_id)||i.entity_id,o=a?e.states[a]:void 0;return`Play ${i.metadata.title||i.data.media_content_id||"media"} on ${o?be(o):a||"a media player"}`}if("wait_for_trigger"===i){const i=_e(t.wait_for_trigger);return i&&0!==i.length?`Wait for ${i.map((t=>Ct(t,e))).join(", ")}`:"Wait for a trigger"}if("variables"===i){const e=t;return`Define variables ${Object.keys(e.variables).join(", ")}`}if("fire_event"===i){const e=t;return gt(e.event)?"Fire event based on a template":`Fire event ${e.event}`}if("wait_template"===i)return"Wait for a template to render true";if("check_condition"===i)return zt(t,e);if("stop"===i){const e=t;return"Stop"+(e.stop?` because: ${e.stop}`:"")}if("if"===i){const i=t;return`Perform an action if: ${i.if?"string"==typeof i.if?i.if:_e(i.if).length>1?`${_e(i.if).length} conditions`:_e(i.if).length?zt(_e(i.if)[0],e):"":""}${i.else?" (or else!)":""}`}if("choose"===i){const e=t;if(e.choose){const t=_e(e.choose).length+(e.default?1:0);return`Choose between ${t} action${1===t?"":"s"}`}return"Choose an action"}if("repeat"===i){const i=t;let a="Repeat an action";if("count"in i.repeat){const e=i.repeat.count;a+=` ${e} time${1===Number(e)?"":"s"}`}else"while"in i.repeat?a+=` while ${_e(i.repeat.while).map((t=>zt(t,e))).join(", ")} is true`:"until"in i.repeat?a+=` until ${_e(i.repeat.until).map((t=>zt(t,e))).join(", ")} is true`:"for_each"in i.repeat&&(a+=` for every item: ${_e(i.repeat.for_each).map((e=>JSON.stringify(e))).join(", ")}`);return a}if("check_condition"===i)return`Test ${zt(t,e)}`;if("device_action"===i){const i=t;if(!i.device_id)return"Device action";const a=bt(e,i);if(a)return a;const o=e.states[i.entity_id];return`${i.type||"Perform action with"} ${o?be(o):i.entity_id}`}if("parallel"===i){const e=_e(t.parallel).length;return`Run ${e} action${1===e?"":"s"} in parallel`}return i},At=(e,t)=>C(e,"hass-notification",t),Ot=["scene"];p([M("ha-automation-action-activate_scene")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f()],key:"action",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{service:"scene.turn_on",target:{entity_id:""},metadata:{}}}},{kind:"method",key:"render",value:function(){let e;var t;"scene"in this.action?e=this.action.scene:e=null===(t=this.action.target)||void 0===t?void 0:t.entity_id;return _`
  198. <ha-entity-picker
  199. .hass=${this.hass}
  200. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.activate_scene.scene")}
  201. .value=${e}
  202. .disabled=${this.disabled}
  203. @value-changed=${this._entityPicked}
  204. .includeDomains=${Ot}
  205. allow-custom-entity
  206. ></ha-entity-picker>
  207. `}},{kind:"method",key:"_entityPicked",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{service:"scene.turn_on",target:{entity_id:e.detail.value},metadata:{}}})}}]}}),m),p([M("ha-automation-action-choose")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f()],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",decorators:[y()],key:"_showDefault",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{choose:[{conditions:[],sequence:[]}]}}},{kind:"method",key:"render",value:function(){const e=this.action;return _`
  208. ${(e.choose?_e(e.choose):[]).map(((e,t)=>_`<ha-card>
  209. <ha-icon-button
  210. .idx=${t}
  211. .disabled=${this.disabled}
  212. @click=${this._removeOption}
  213. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.remove_option")}
  214. .path=${A}
  215. ></ha-icon-button>
  216. <div class="card-content">
  217. <h2>
  218. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.option","number",t+1)}:
  219. </h2>
  220. <h3>
  221. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.conditions")}:
  222. </h3>
  223. <ha-automation-condition
  224. .conditions=${_e(e.conditions)}
  225. .reOrderMode=${this.reOrderMode}
  226. .disabled=${this.disabled}
  227. .hass=${this.hass}
  228. .idx=${t}
  229. @value-changed=${this._conditionChanged}
  230. ></ha-automation-condition>
  231. <h3>
  232. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.sequence")}:
  233. </h3>
  234. <ha-automation-action
  235. .actions=${_e(e.sequence)||[]}
  236. .reOrderMode=${this.reOrderMode}
  237. .disabled=${this.disabled}
  238. .hass=${this.hass}
  239. .idx=${t}
  240. @value-changed=${this._actionChanged}
  241. ></ha-automation-action>
  242. </div>
  243. </ha-card>`))}
  244. <mwc-button
  245. outlined
  246. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.add_option")}
  247. .disabled=${this.disabled}
  248. @click=${this._addOption}
  249. >
  250. <ha-svg-icon .path=${O} slot="icon"></ha-svg-icon>
  251. </mwc-button>
  252. ${this._showDefault||e.default?_`
  253. <h2>
  254. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.default")}:
  255. </h2>
  256. <ha-automation-action
  257. .actions=${_e(e.default)||[]}
  258. .reOrderMode=${this.reOrderMode}
  259. .disabled=${this.disabled}
  260. @value-changed=${this._defaultChanged}
  261. .hass=${this.hass}
  262. ></ha-automation-action>
  263. `:_`<div class="link-button-row">
  264. <button
  265. class="link"
  266. @click=${this._addDefault}
  267. .disabled=${this.disabled}
  268. >
  269. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.choose.add_default")}
  270. </button>
  271. </div>`}
  272. `}},{kind:"method",key:"_addDefault",value:function(){this._showDefault=!0}},{kind:"method",key:"_conditionChanged",value:function(e){e.stopPropagation();const t=e.detail.value,i=e.target.idx,a=this.action.choose?[..._e(this.action.choose)]:[];a[i].conditions=t,C(this,"value-changed",{value:{...this.action,choose:a}})}},{kind:"method",key:"_actionChanged",value:function(e){e.stopPropagation();const t=e.detail.value,i=e.target.idx,a=this.action.choose?[..._e(this.action.choose)]:[];a[i].sequence=t,C(this,"value-changed",{value:{...this.action,choose:a}})}},{kind:"method",key:"_addOption",value:function(){const e=this.action.choose?[..._e(this.action.choose)]:[];e.push({conditions:[],sequence:[]}),C(this,"value-changed",{value:{...this.action,choose:e}})}},{kind:"method",key:"_removeOption",value:function(e){const t=e.currentTarget.idx,i=this.action.choose?[..._e(this.action.choose)]:[];i.splice(t,1),C(this,"value-changed",{value:{...this.action,choose:i}})}},{kind:"method",key:"_defaultChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,default:t}})}},{kind:"get",static:!0,key:"styles",value:function(){return[T,g`
  273. ha-card {
  274. margin: 16px 0;
  275. }
  276. .add-card mwc-button {
  277. display: block;
  278. text-align: center;
  279. }
  280. ha-icon-button {
  281. position: absolute;
  282. right: 0;
  283. padding: 4px;
  284. }
  285. ha-svg-icon {
  286. height: 20px;
  287. }
  288. .link-button-row {
  289. padding: 14px;
  290. }
  291. `]}}]}}),m);const Tt={device:u,and:P,or:U,not:E,state:j,numeric_state:F,sun:I,template:s,time:S,trigger:L,zone:N},Pt=e=>e.preventDefault();p([M("ha-automation-condition-row")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"hideMenu",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_yamlMode",value:()=>!1},{kind:"field",decorators:[y()],key:"_warnings",value:void 0},{kind:"field",decorators:[y()],key:"_testing",value:()=>!1},{kind:"field",decorators:[y()],key:"_testingResult",value:void 0},{kind:"method",key:"render",value:function(){return this.condition?_`
  292. <ha-card outlined>
  293. ${!1===this.condition.enabled?_`<div class="disabled-bar">
  294. ${this.hass.localize("ui.panel.config.automation.editor.actions.disabled")}
  295. </div>`:""}
  296. <ha-expansion-panel leftChevron>
  297. <h3 slot="header">
  298. <ha-svg-icon
  299. class="condition-icon"
  300. .path=${Tt[this.condition.condition]}
  301. ></ha-svg-icon>
  302. ${ye(zt(this.condition,this.hass))}
  303. </h3>
  304. <slot name="icons" slot="icons"></slot>
  305. ${this.hideMenu?"":_`
  306. <ha-button-menu
  307. slot="icons"
  308. fixed
  309. corner="BOTTOM_START"
  310. @action=${this._handleAction}
  311. @click=${Pt}
  312. >
  313. <ha-icon-button
  314. slot="trigger"
  315. .label=${this.hass.localize("ui.common.menu")}
  316. .path=${B}
  317. >
  318. </ha-icon-button>
  319. <mwc-list-item graphic="icon">
  320. ${this.hass.localize("ui.panel.config.automation.editor.conditions.test")}
  321. <ha-svg-icon slot="graphic" .path=${D}></ha-svg-icon>
  322. </mwc-list-item>
  323. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  324. ${this.hass.localize("ui.panel.config.automation.editor.conditions.rename")}
  325. <ha-svg-icon
  326. slot="graphic"
  327. .path=${q}
  328. ></ha-svg-icon>
  329. </mwc-list-item>
  330. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  331. ${this.hass.localize("ui.panel.config.automation.editor.actions.duplicate")}
  332. <ha-svg-icon
  333. slot="graphic"
  334. .path=${W}
  335. ></ha-svg-icon>
  336. </mwc-list-item>
  337. <li divider role="separator"></li>
  338. <mwc-list-item graphic="icon">
  339. ${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
  340. ${this._yamlMode?"":_`<ha-svg-icon
  341. class="selected_menu_item"
  342. slot="graphic"
  343. .path=${R}
  344. ></ha-svg-icon>`}
  345. </mwc-list-item>
  346. <mwc-list-item graphic="icon">
  347. ${this.hass.localize("ui.panel.config.automation.editor.edit_yaml")}
  348. ${this._yamlMode?_`<ha-svg-icon
  349. class="selected_menu_item"
  350. slot="graphic"
  351. .path=${R}
  352. ></ha-svg-icon>`:""}
  353. </mwc-list-item>
  354. <li divider role="separator"></li>
  355. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  356. ${!1===this.condition.enabled?this.hass.localize("ui.panel.config.automation.editor.actions.enable"):this.hass.localize("ui.panel.config.automation.editor.actions.disable")}
  357. <ha-svg-icon
  358. slot="graphic"
  359. .path=${!1===this.condition.enabled?K:V}
  360. ></ha-svg-icon>
  361. </mwc-list-item>
  362. <mwc-list-item
  363. class="warning"
  364. graphic="icon"
  365. .disabled=${this.disabled}
  366. >
  367. ${this.hass.localize("ui.panel.config.automation.editor.actions.delete")}
  368. <ha-svg-icon
  369. class="warning"
  370. slot="graphic"
  371. .path=${A}
  372. ></ha-svg-icon>
  373. </mwc-list-item>
  374. </ha-button-menu>
  375. `}
  376. <div
  377. class=${$({"card-content":!0,disabled:!1===this.condition.enabled})}
  378. >
  379. ${this._warnings?_`<ha-alert
  380. alert-type="warning"
  381. .title=${this.hass.localize("ui.errors.config.editor_not_supported")}
  382. >
  383. ${this._warnings.length>0&&void 0!==this._warnings[0]?_` <ul>
  384. ${this._warnings.map((e=>_`<li>${e}</li>`))}
  385. </ul>`:""}
  386. ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")}
  387. </ha-alert>`:""}
  388. <ha-automation-condition-editor
  389. @ui-mode-not-available=${this._handleUiModeNotAvailable}
  390. @value-changed=${this._handleChangeEvent}
  391. .yamlMode=${this._yamlMode}
  392. .disabled=${this.disabled}
  393. .hass=${this.hass}
  394. .condition=${this.condition}
  395. .reOrderMode=${this.reOrderMode}
  396. ></ha-automation-condition-editor>
  397. </div>
  398. </ha-expansion-panel>
  399. <div
  400. class="testing ${$({active:this._testing,pass:!0===this._testingResult,error:!1===this._testingResult})}"
  401. >
  402. ${this._testingResult?this.hass.localize("ui.panel.config.automation.editor.conditions.testing_pass"):this.hass.localize("ui.panel.config.automation.editor.conditions.testing_error")}
  403. </div>
  404. </ha-card>
  405. `:_``}},{kind:"method",key:"_handleUiModeNotAvailable",value:function(e){e.stopPropagation(),this._warnings=ot(this.hass,e.detail).warnings,this._yamlMode||(this._yamlMode=!0)}},{kind:"method",key:"_handleChangeEvent",value:function(e){e.detail.yaml&&(this._warnings=void 0)}},{kind:"method",key:"_handleAction",value:async function(e){switch(e.detail.index){case 0:await this._testCondition();break;case 1:await this._renameCondition();break;case 2:C(this,"duplicate");break;case 3:this._switchUiMode(),this.expand();break;case 4:this._switchYamlMode(),this.expand();break;case 5:this._onDisable();break;case 6:this._onDelete()}}},{kind:"method",key:"_onDisable",value:function(){var e;const t=!(null===(e=this.condition.enabled)||void 0===e||e),i={...this.condition,enabled:t};C(this,"value-changed",{value:i})}},{kind:"method",key:"_onDelete",value:function(){ze(this,{title:this.hass.localize("ui.panel.config.automation.editor.conditions.delete_confirm_title"),text:this.hass.localize("ui.panel.config.automation.editor.conditions.delete_confirm_text"),dismissText:this.hass.localize("ui.common.cancel"),confirmText:this.hass.localize("ui.common.delete"),destructive:!0,confirm:()=>{C(this,"value-changed",{value:null})}})}},{kind:"method",key:"_switchUiMode",value:function(){this._warnings=void 0,this._yamlMode=!1}},{kind:"method",key:"_switchYamlMode",value:function(){this._warnings=void 0,this._yamlMode=!0}},{kind:"method",key:"_testCondition",value:async function(){if(this._testing)return;this._testingResult=void 0,this._testing=!0;const e=this.condition;try{const t=await nt(this.hass,{condition:e});if(this.condition!==e)return void(this._testing=!1);if(!t.condition.valid)return Me(this,{title:this.hass.localize("ui.panel.config.automation.editor.conditions.invalid_condition"),text:t.condition.error}),void(this._testing=!1);let i;try{i=await((e,t,i)=>e.callWS({type:"test_condition",condition:t,variables:i}))(this.hass,e)}catch(t){return this.condition!==e||Me(this,{title:this.hass.localize("ui.panel.config.automation.editor.conditions.test_failed"),text:t.message}),void(this._testing=!1)}this._testingResult=i.result}finally{setTimeout((()=>{this._testing=!1}),2500)}}},{kind:"method",key:"_renameCondition",value:async function(){const e=await Ae(this,{title:this.hass.localize("ui.panel.config.automation.editor.conditions.change_alias"),inputLabel:this.hass.localize("ui.panel.config.automation.editor.conditions.alias"),inputType:"string",placeholder:ye(zt(this.condition,this.hass,!0)),defaultValue:this.condition.alias,confirmText:this.hass.localize("ui.common.submit")}),t={...this.condition};e?t.alias=e:delete t.alias,C(this,"value-changed",{value:t})}},{kind:"method",key:"expand",value:function(){this.updateComplete.then((()=>{this.shadowRoot.querySelector("ha-expansion-panel").expanded=!0}))}},{kind:"get",static:!0,key:"styles",value:function(){return[T,g`
  406. ha-button-menu {
  407. --mdc-theme-text-primary-on-background: var(--primary-text-color);
  408. }
  409. .disabled {
  410. opacity: 0.5;
  411. pointer-events: none;
  412. }
  413. ha-expansion-panel {
  414. --expansion-panel-summary-padding: 0 0 0 8px;
  415. --expansion-panel-content-padding: 0;
  416. }
  417. h3 {
  418. margin: 0;
  419. font-size: inherit;
  420. font-weight: inherit;
  421. }
  422. .condition-icon {
  423. display: none;
  424. }
  425. @media (min-width: 870px) {
  426. .condition-icon {
  427. display: inline-block;
  428. color: var(--secondary-text-color);
  429. opacity: 0.9;
  430. margin-right: 8px;
  431. }
  432. }
  433. .card-content {
  434. padding: 16px;
  435. }
  436. .disabled-bar {
  437. background: var(--divider-color, #e0e0e0);
  438. text-align: center;
  439. border-top-right-radius: var(--ha-card-border-radius);
  440. border-top-left-radius: var(--ha-card-border-radius);
  441. }
  442. mwc-list-item[disabled] {
  443. --mdc-theme-text-primary-on-background: var(--disabled-text-color);
  444. }
  445. .testing {
  446. position: absolute;
  447. top: 0px;
  448. right: 0px;
  449. left: 0px;
  450. text-transform: uppercase;
  451. font-weight: bold;
  452. font-size: 14px;
  453. background-color: var(--divider-color, #e0e0e0);
  454. color: var(--text-primary-color);
  455. max-height: 0px;
  456. overflow: hidden;
  457. transition: max-height 0.3s;
  458. text-align: center;
  459. border-top-right-radius: var(--ha-card-border-radius, 16px);
  460. border-top-left-radius: var(--ha-card-border-radius, 16px);
  461. }
  462. .testing.active {
  463. max-height: 100px;
  464. }
  465. .testing.error {
  466. background-color: var(--accent-color);
  467. }
  468. .testing.pass {
  469. background-color: var(--success-color);
  470. }
  471. .selected_menu_item {
  472. color: var(--primary-color);
  473. }
  474. li[role="separator"] {
  475. border-bottom-color: var(--divider-color);
  476. }
  477. `]}}]}}),m);const Ut="NO_AUTOMATION",Et="UNKNOWN_AUTOMATION";let jt=p(null,(function(e,t){class i extends t{constructor(t,i,a){super(),e(this),this._localizeDeviceAutomation=t,this._fetchDeviceAutomations=i,this._createNoAutomation=a}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"label",value:void 0},{kind:"field",decorators:[f()],key:"deviceId",value:void 0},{kind:"field",decorators:[f()],key:"value",value:void 0},{kind:"field",decorators:[y()],key:"_automations",value:()=>[]},{kind:"field",decorators:[y()],key:"_renderEmpty",value:()=>!1},{kind:"get",key:"NO_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.actions.no_actions")}},{kind:"get",key:"UNKNOWN_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.actions.unknown_action")}},{kind:"field",key:"_localizeDeviceAutomation",value:void 0},{kind:"field",key:"_fetchDeviceAutomations",value:void 0},{kind:"field",key:"_createNoAutomation",value:void 0},{kind:"get",key:"_value",value:function(){if(!this.value)return"";if(!this._automations.length)return Ut;const e=this._automations.findIndex((e=>_t(e,this.value)));return-1===e?Et:`${this._automations[e].device_id}_${e}`}},{kind:"method",key:"render",value:function(){if(this._renderEmpty)return _``;const e=this._value;return _`
  478. <ha-select
  479. .label=${this.label}
  480. .value=${e}
  481. @selected=${this._automationChanged}
  482. .disabled=${0===this._automations.length}
  483. >
  484. ${e===Ut?_`<mwc-list-item .value=${Ut}>
  485. ${this.NO_AUTOMATION_TEXT}
  486. </mwc-list-item>`:""}
  487. ${e===Et?_`<mwc-list-item .value=${Et}>
  488. ${this.UNKNOWN_AUTOMATION_TEXT}
  489. </mwc-list-item>`:""}
  490. ${this._automations.map(((e,t)=>_`
  491. <mwc-list-item .value=${`${e.device_id}_${t}`}>
  492. ${this._localizeDeviceAutomation(this.hass,e)}
  493. </mwc-list-item>
  494. `))}
  495. </ha-select>
  496. `}},{kind:"method",key:"updated",value:function(e){x(w(i.prototype),"updated",this).call(this,e),e.has("deviceId")&&this._updateDeviceInfo()}},{kind:"method",key:"_updateDeviceInfo",value:async function(){this._automations=this.deviceId?(await this._fetchDeviceAutomations(this.hass,this.deviceId)).sort(wt):[],this.value&&this.value.device_id===this.deviceId||this._setValue(this._automations.length?this._automations[0]:this._createNoAutomation(this.deviceId)),this._renderEmpty=!0,await this.updateComplete,this._renderEmpty=!1}},{kind:"method",key:"_automationChanged",value:function(e){const t=e.target.value;if(!t||[Et,Ut].includes(t))return;const[i,a]=t.split("_"),o=this._automations[a];o.device_id===i&&this._setValue(o)}},{kind:"method",key:"_setValue",value:function(e){if(this.value&&_t(e,this.value))return;const t={...e};delete t.metadata,C(this,"value-changed",{value:t})}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  497. ha-select {
  498. display: block;
  499. }
  500. `}}]}}),m);p([M("ha-device-condition-picker")],(function(e,t){return{F:class extends t{constructor(){super($t,ft,(e=>({device_id:e||"",condition:"device",domain:"",entity_id:""}))),e(this)}},d:[{kind:"get",key:"NO_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.conditions.no_conditions")}},{kind:"get",key:"UNKNOWN_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.conditions.unknown_condition")}}]}}),jt),p([M("ha-automation-condition-device")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Object})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_deviceId",value:void 0},{kind:"field",decorators:[y()],key:"_capabilities",value:void 0},{kind:"field",key:"_origCondition",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{device_id:"",domain:"",entity_id:""}}},{kind:"field",key:"_extraFieldsData",value:()=>X(((e,t)=>{const i={};return t.extra_fields.forEach((t=>{void 0!==e[t.name]&&(i[t.name]=e[t.name])})),i}))},{kind:"method",key:"render",value:function(){var e;const t=this._deviceId||this.condition.device_id;return _`
  501. <ha-device-picker
  502. .value=${t}
  503. @value-changed=${this._devicePicked}
  504. .hass=${this.hass}
  505. .disabled=${this.disabled}
  506. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.type.device.label")}
  507. ></ha-device-picker>
  508. <ha-device-condition-picker
  509. .value=${this.condition}
  510. .deviceId=${t}
  511. @value-changed=${this._deviceConditionPicked}
  512. .hass=${this.hass}
  513. .disabled=${this.disabled}
  514. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.type.device.condition")}
  515. ></ha-device-condition-picker>
  516. ${null!==(e=this._capabilities)&&void 0!==e&&e.extra_fields?_`
  517. <ha-form
  518. .hass=${this.hass}
  519. .data=${this._extraFieldsData(this.condition,this._capabilities)}
  520. .schema=${this._capabilities.extra_fields}
  521. .disabled=${this.disabled}
  522. .computeLabel=${this._extraFieldsComputeLabelCallback(this.hass.localize)}
  523. @value-changed=${this._extraFieldsChanged}
  524. ></ha-form>
  525. `:""}
  526. `}},{kind:"method",key:"firstUpdated",value:function(){this._capabilities||this._getCapabilities(),this.condition&&(this._origCondition=this.condition)}},{kind:"method",key:"updated",value:function(e){const t=e.get("condition");t&&!_t(t,this.condition)&&this._getCapabilities()}},{kind:"method",key:"_getCapabilities",value:async function(){const e=this.condition;this._capabilities=e.domain?await((e,t)=>e.callWS({type:"device_automation/condition/capabilities",condition:t}))(this.hass,e):void 0}},{kind:"method",key:"_devicePicked",value:function(e){e.stopPropagation(),this._deviceId=e.target.value,void 0===this._deviceId&&C(this,"value-changed",{value:{...i.defaultConfig,condition:"device"}})}},{kind:"method",key:"_deviceConditionPicked",value:function(e){e.stopPropagation();let t=e.detail.value;this._origCondition&&_t(this._origCondition,t)&&(t=this._origCondition),C(this,"value-changed",{value:t})}},{kind:"method",key:"_extraFieldsChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.condition,...e.detail.value}})}},{kind:"method",key:"_extraFieldsComputeLabelCallback",value:function(e){return t=>e(`ui.panel.config.automation.editor.conditions.type.device.extra_fields.${t.name}`)||t.name}},{kind:"field",static:!0,key:"styles",value:()=>g`
  527. ha-device-picker {
  528. display: block;
  529. margin-bottom: 24px;
  530. }
  531. `}]}}),m),p([M("ha-automation-condition-numeric_state")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{entity_id:""}}},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"entity_id",required:!0,selector:{entity:{}}},{name:"attribute",selector:{attribute:{entity_id:e,hide_attributes:["access_token","auto_update","available_modes","away_mode","changed_by","code_format","color_modes","current_activity","device_class","editable","effect_list","effect","entity_picture","fan_mode","fan_modes","fan_speed_list","forecast","friendly_name","frontend_stream_type","has_date","has_time","hs_color","hvac_mode","hvac_modes","icon","media_album_name","media_artist","media_content_type","media_position_updated_at","media_title","next_dawn","next_dusk","next_midnight","next_noon","next_rising","next_setting","operation_list","operation_mode","options","preset_mode","preset_modes","release_notes","release_summary","release_url","restored","rgb_color","rgbw_color","shuffle","sound_mode_list","sound_mode","source_list","source_type","source","state_class","supported_features","swing_mode","swing_mode","swing_modes","title","token","unit_of_measurement","xy_color"]}}},{name:"above",selector:{number:{mode:"box",min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER,step:.1}}},{name:"below",selector:{number:{mode:"box",min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER,step:.1}}},{name:"value_template",selector:{template:{}}}]))},{kind:"method",key:"render",value:function(){const e=this._schema(this.condition.entity_id);return _`
  532. <ha-form
  533. .hass=${this.hass}
  534. .data=${this.condition}
  535. .schema=${e}
  536. .disabled=${this.disabled}
  537. @value-changed=${this._valueChanged}
  538. .computeLabel=${this._computeLabelCallback}
  539. ></ha-form>
  540. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>{switch(e.name){case"entity_id":return this.hass.localize("ui.components.entity.entity-picker.entity");case"attribute":return this.hass.localize("ui.components.entity.entity-attribute-picker.attribute");default:return this.hass.localize(`ui.panel.config.automation.editor.triggers.type.numeric_state.${e.name}`)}}}}]}}),m);const Ft=e=>{if(void 0===e)return;if("object"!=typeof e){if("string"==typeof e||isNaN(e)){const t=(null==e?void 0:e.toString().split(":"))||[];return{hours:Number(t[0])||0,minutes:Number(t[1])||0,seconds:Number(t[2])||0,milliseconds:Number(t[3])||0}}return{seconds:e}}if(!("days"in e))return e;const{days:t,minutes:i,seconds:a,milliseconds:o}=e;let n=e.hours||0;return n=(n||0)+24*(t||0),{hours:n,minutes:i,seconds:a,milliseconds:o}},It=Ze({platform:tt(),id:et(tt()),enabled:et(Je())}),St=Ze({days:et(Qe()),hours:et(Qe()),minutes:et(Qe()),seconds:et(Qe())}),Lt=Ze({alias:et(tt()),condition:He("state"),entity_id:et(tt()),attribute:et(tt()),state:et(tt()),for:et(at([tt(),St]))});p([M("ha-automation-condition-state")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{entity_id:"",state:""}}},{kind:"field",key:"_schema",value:()=>X(((e,t)=>[{name:"entity_id",required:!0,selector:{entity:{}}},{name:"attribute",selector:{attribute:{entity_id:e,hide_attributes:["access_token","available_modes","color_modes","editable","effect_list","entity_picture","fan_modes","fan_speed_list","forecast","friendly_name","hvac_modes","icon","operation_list","options","preset_modes","sound_mode_list","source_list","state_class","swing_modes","token"]}}},{name:"state",required:!0,selector:{state:{entity_id:e,attribute:t}}},{name:"for",selector:{duration:{}}}]))},{kind:"method",key:"shouldUpdate",value:function(e){if(e.has("condition"))try{We(this.condition,Lt)}catch(e){return C(this,"ui-mode-not-available",e),!1}return!0}},{kind:"method",key:"render",value:function(){const e=Ft(this.condition.for),t={...this.condition,for:e},i=this._schema(this.condition.entity_id,this.condition.attribute);return _`
  541. <ha-form
  542. .hass=${this.hass}
  543. .data=${t}
  544. .schema=${i}
  545. .disabled=${this.disabled}
  546. @value-changed=${this._valueChanged}
  547. .computeLabel=${this._computeLabelCallback}
  548. ></ha-form>
  549. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;Object.keys(t).forEach((e=>void 0===t[e]||""===t[e]?delete t[e]:{})),t.state||(t.state=""),C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>{switch(e.name){case"entity_id":return this.hass.localize("ui.components.entity.entity-picker.entity");case"attribute":return this.hass.localize("ui.components.entity.entity-attribute-picker.attribute");case"for":return this.hass.localize("ui.panel.config.automation.editor.triggers.type.state.for");default:return this.hass.localize(`ui.panel.config.automation.editor.conditions.type.state.${e.name}`)}}}}]}}),m),p([M("ha-automation-condition-sun")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{}}},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"before",type:"select",required:!0,options:[["sunrise",e("ui.panel.config.automation.editor.conditions.type.sun.sunrise")],["sunset",e("ui.panel.config.automation.editor.conditions.type.sun.sunset")]]},{name:"before_offset",selector:{text:{}}},{name:"after",type:"select",required:!0,options:[["sunrise",e("ui.panel.config.automation.editor.conditions.type.sun.sunrise")],["sunset",e("ui.panel.config.automation.editor.conditions.type.sun.sunset")]]},{name:"after_offset",selector:{text:{}}}]))},{kind:"method",key:"render",value:function(){const e=this._schema(this.hass.localize);return _`
  550. <ha-form
  551. .schema=${e}
  552. .data=${this.condition}
  553. .hass=${this.hass}
  554. .disabled=${this.disabled}
  555. .computeLabel=${this._computeLabelCallback}
  556. @value-changed=${this._valueChanged}
  557. ></ha-form>
  558. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.conditions.type.sun.${e.name}`)}}]}}),m),p([M("ha-automation-condition-template")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{value_template:""}}},{kind:"method",key:"render",value:function(){const{value_template:e}=this.condition;return _`
  559. <p>
  560. ${this.hass.localize("ui.panel.config.automation.editor.conditions.type.template.value_template")}
  561. *
  562. </p>
  563. <ha-code-editor
  564. .name=${"value_template"}
  565. mode="jinja2"
  566. .hass=${this.hass}
  567. .value=${e}
  568. .readOnly=${this.disabled}
  569. autocomplete-entities
  570. @value-changed=${this._valueChanged}
  571. dir="ltr"
  572. ></ha-code-editor>
  573. `}},{kind:"method",key:"_valueChanged",value:function(e){((e,t)=>{var i,a,o;t.stopPropagation();const n=null===(i=t.currentTarget)||void 0===i?void 0:i.name;if(!n)return;const s=(null===(a=t.detail)||void 0===a?void 0:a.value)||(null===(o=t.currentTarget)||void 0===o?void 0:o.value);if((e.condition[n]||"")===s)return;let d;s?d={...e.condition,[n]:s}:(d={...e.condition},delete d[n]),C(e,"value-changed",{value:d})})(this,e)}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  574. p {
  575. margin-top: 0;
  576. }
  577. `}}]}}),m);const Nt=["sun","mon","tue","wed","thu","fri","sat"];p([M("ha-automation-condition-time")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[y()],key:"_inputModeBefore",value:void 0},{kind:"field",decorators:[y()],key:"_inputModeAfter",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{}}},{kind:"field",key:"_schema",value:()=>X(((e,t,i,a)=>{const o=Te(t),n=Nt.slice(o,Nt.length).concat(Nt.slice(0,o));return[{name:"mode_after",type:"select",required:!0,options:[["value",e("ui.panel.config.automation.editor.conditions.type.time.type_value")],["input",e("ui.panel.config.automation.editor.conditions.type.time.type_input")]]},{name:"after",selector:i?{entity:{domain:"input_datetime"}}:{time:{}}},{name:"mode_before",type:"select",required:!0,options:[["value",e("ui.panel.config.automation.editor.conditions.type.time.type_value")],["input",e("ui.panel.config.automation.editor.conditions.type.time.type_input")]]},{name:"before",selector:a?{entity:{domain:"input_datetime"}}:{time:{}}},{type:"multi_select",name:"weekday",options:n.map((t=>[t,e(`ui.panel.config.automation.editor.conditions.type.time.weekdays.${t}`)]))}]}))},{kind:"method",key:"render",value:function(){var e,t,i,a;const o=null!==(e=this._inputModeBefore)&&void 0!==e?e:null===(t=this.condition.before)||void 0===t?void 0:t.startsWith("input_datetime."),n=null!==(i=this._inputModeAfter)&&void 0!==i?i:null===(a=this.condition.after)||void 0===a?void 0:a.startsWith("input_datetime."),s=this._schema(this.hass.localize,this.hass.locale,n,o),d={mode_before:o?"input":"value",mode_after:n?"input":"value",...this.condition};return _`
  578. <ha-form
  579. .hass=${this.hass}
  580. .data=${d}
  581. .schema=${s}
  582. .disabled=${this.disabled}
  583. @value-changed=${this._valueChanged}
  584. .computeLabel=${this._computeLabelCallback}
  585. ></ha-form>
  586. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;this._inputModeAfter="input"===t.mode_after,this._inputModeBefore="input"===t.mode_before,delete t.mode_after,delete t.mode_before,Object.keys(t).forEach((e=>void 0===t[e]||""===t[e]?delete t[e]:{})),C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.conditions.type.time.${e.name}`)}}]}}),m),p([M("ha-automation-condition-trigger")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_triggers",value:()=>[]},{kind:"field",key:"_unsub",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{id:""}}},{kind:"method",key:"connectedCallback",value:function(){x(w(i.prototype),"connectedCallback",this).call(this);const e={callback:e=>this._automationUpdated(e)};C(this,"subscribe-automation-config",e),this._unsub=e.unsub}},{kind:"method",key:"disconnectedCallback",value:function(){x(w(i.prototype),"disconnectedCallback",this).call(this),this._unsub&&this._unsub()}},{kind:"method",key:"render",value:function(){const{id:e}=this.condition;return this._triggers.length?_`<ha-select
  587. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.type.trigger.id")}
  588. .value=${e}
  589. .disabled=${this.disabled}
  590. @selected=${this._triggerPicked}
  591. >
  592. ${this._triggers.map((e=>_`
  593. <mwc-list-item .value=${e.id}> ${e.id} </mwc-list-item>
  594. `))}
  595. </ha-select>`:this.hass.localize("ui.panel.config.automation.editor.conditions.type.trigger.no_triggers")}},{kind:"method",key:"_automationUpdated",value:function(e){const t=new Set;this._triggers=null!=e&&e.trigger?_e(e.trigger).filter((e=>e.id&&!t.has(e.id)&&t.add(e.id))):[]}},{kind:"method",key:"_triggerPicked",value:function(e){if(e.stopPropagation(),!e.target.value)return;const t=e.target.value;this.condition.id!==t&&C(this,"value-changed",{value:{...this.condition,id:t}})}}]}}),m);const Bt=e=>"latitude"in e.attributes&&"longitude"in e.attributes;function Dt(e){return Bt(e)&&"zone"!==Pe(e)}const qt=["zone"];p([M("ha-automation-condition-zone")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{entity_id:"",zone:""}}},{kind:"method",key:"render",value:function(){const{entity_id:e,zone:t}=this.condition;return _`
  596. <ha-entity-picker
  597. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.type.zone.entity")}
  598. .value=${e}
  599. @value-changed=${this._entityPicked}
  600. .hass=${this.hass}
  601. .disabled=${this.disabled}
  602. allow-custom-entity
  603. .entityFilter=${Dt}
  604. ></ha-entity-picker>
  605. <ha-entity-picker
  606. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.type.zone.zone")}
  607. .value=${t}
  608. @value-changed=${this._zonePicked}
  609. .hass=${this.hass}
  610. .disabled=${this.disabled}
  611. allow-custom-entity
  612. .includeDomains=${qt}
  613. ></ha-entity-picker>
  614. <label id="eventlabel">
  615. ${this.hass.localize("ui.panel.config.automation.editor.conditions.type.zone.event")}
  616. </label>
  617. `}},{kind:"method",key:"_entityPicked",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.condition,entity_id:e.detail.value}})}},{kind:"method",key:"_zonePicked",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.condition,zone:e.detail.value}})}},{kind:"field",static:!0,key:"styles",value:()=>g`
  618. ha-entity-picker:first-child {
  619. display: block;
  620. margin-bottom: 24px;
  621. }
  622. `}]}}),m),p([M("ha-automation-condition")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"conditions",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",key:"_focusLastConditionOnChange",value:()=>!1},{kind:"field",key:"_conditionKeys",value:()=>new WeakMap},{kind:"field",key:"_sortable",value:void 0},{kind:"method",key:"updated",value:function(e){if(e.has("reOrderMode")&&(this.reOrderMode?this._createSortable():this._destroySortable()),!e.has("conditions"))return;let t;if(Array.isArray(this.conditions)||(t=[this.conditions]),(t||this.conditions).forEach(((e,i)=>{"string"==typeof e&&(t=t||[...this.conditions],t[i]={condition:"template",value_template:e})})),t)C(this,"value-changed",{value:t});else if(this._focusLastConditionOnChange){this._focusLastConditionOnChange=!1;const e=this.shadowRoot.querySelector("ha-automation-condition-row:last-of-type");e.updateComplete.then((()=>{e.expand(),e.scrollIntoView(),e.focus()}))}}},{kind:"method",key:"render",value:function(){return Array.isArray(this.conditions)?_`
  623. <div class="conditions">
  624. ${ue(this.conditions,(e=>this._getKey(e)),((e,t)=>_`
  625. <ha-automation-condition-row
  626. .index=${t}
  627. .totalConditions=${this.conditions.length}
  628. .condition=${e}
  629. .hideMenu=${this.reOrderMode}
  630. .reOrderMode=${this.reOrderMode}
  631. .disabled=${this.disabled}
  632. @duplicate=${this._duplicateCondition}
  633. @move-condition=${this._move}
  634. @value-changed=${this._conditionChanged}
  635. .hass=${this.hass}
  636. >
  637. ${this.reOrderMode?_`
  638. <ha-icon-button
  639. .index=${t}
  640. slot="icons"
  641. .label=${this.hass.localize("ui.panel.config.automation.editor.move_up")}
  642. .path=${Y}
  643. @click=${this._moveUp}
  644. .disabled=${0===t}
  645. ></ha-icon-button>
  646. <ha-icon-button
  647. .index=${t}
  648. slot="icons"
  649. .label=${this.hass.localize("ui.panel.config.automation.editor.move_down")}
  650. .path=${G}
  651. @click=${this._moveDown}
  652. .disabled=${t===this.conditions.length-1}
  653. ></ha-icon-button>
  654. <div class="handle" slot="icons">
  655. <ha-svg-icon .path=${J}></ha-svg-icon>
  656. </div>
  657. `:""}
  658. </ha-automation-condition-row>
  659. `))}
  660. </div>
  661. <ha-button-menu
  662. fixed
  663. @action=${this._addCondition}
  664. .disabled=${this.disabled}
  665. >
  666. <mwc-button
  667. slot="trigger"
  668. outlined
  669. .disabled=${this.disabled}
  670. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.add")}
  671. >
  672. <ha-svg-icon .path=${O} slot="icon"></ha-svg-icon>
  673. </mwc-button>
  674. ${this._processedTypes(this.hass.localize).map((([e,t,i])=>_`
  675. <mwc-list-item .value=${e} aria-label=${t} graphic="icon">
  676. ${t}<ha-svg-icon slot="graphic" .path=${i}></ha-svg-icon
  677. ></mwc-list-item>
  678. `))}
  679. </ha-button-menu>
  680. `:_``}},{kind:"method",key:"_createSortable",value:async function(){const e=await Fe();this._sortable=new e(this.shadowRoot.querySelector(".conditions"),{animation:150,fallbackClass:"sortable-fallback",handle:".handle",onChoose:e=>{e.item.placeholder=document.createComment("sort-placeholder"),e.item.after(e.item.placeholder)},onEnd:e=>{e.item.placeholder&&(e.item.placeholder.replaceWith(e.item),delete e.item.placeholder),this._dragged(e)}})}},{kind:"method",key:"_destroySortable",value:function(){var e;null===(e=this._sortable)||void 0===e||e.destroy(),this._sortable=void 0}},{kind:"method",key:"_getKey",value:function(e){return this._conditionKeys.has(e)||this._conditionKeys.set(e,Math.random().toString()),this._conditionKeys.get(e)}},{kind:"method",key:"_addCondition",value:function(e){const t=e.currentTarget.items[e.detail.index].value,i=customElements.get(`ha-automation-condition-${t}`),a=this.conditions.concat({condition:t,...i.defaultConfig});this._focusLastConditionOnChange=!0,C(this,"value-changed",{value:a})}},{kind:"method",key:"_moveUp",value:function(e){const t=e.target.index,i=t-1;this._move(t,i)}},{kind:"method",key:"_moveDown",value:function(e){const t=e.target.index,i=t+1;this._move(t,i)}},{kind:"method",key:"_dragged",value:function(e){e.oldIndex!==e.newIndex&&this._move(e.oldIndex,e.newIndex)}},{kind:"method",key:"_move",value:function(e,t){const i=this.conditions.concat(),a=i.splice(e,1)[0];i.splice(t,0,a),C(this,"value-changed",{value:i})}},{kind:"method",key:"_conditionChanged",value:function(e){e.stopPropagation();const t=[...this.conditions],i=e.detail.value,a=e.target.index;if(null===i)t.splice(a,1);else{const e=this._getKey(t[a]);this._conditionKeys.set(i,e),t[a]=i}C(this,"value-changed",{value:t})}},{kind:"method",key:"_duplicateCondition",value:function(e){e.stopPropagation();const t=e.target.index;C(this,"value-changed",{value:this.conditions.concat(ce(this.conditions[t]))})}},{kind:"field",key:"_processedTypes",value:()=>X((e=>Object.entries(Tt).map((([t,i])=>[t,e(`ui.panel.config.automation.editor.conditions.type.${t}.label`),i])).sort(((e,t)=>he(e[1],t[1])))))},{kind:"get",static:!0,key:"styles",value:function(){return[Ee,g`
  681. ha-automation-condition-row {
  682. display: block;
  683. margin-bottom: 16px;
  684. scroll-margin-top: 48px;
  685. }
  686. ha-svg-icon {
  687. height: 20px;
  688. }
  689. .handle {
  690. cursor: move;
  691. padding: 12px;
  692. }
  693. .handle ha-svg-icon {
  694. pointer-events: none;
  695. height: 24px;
  696. }
  697. `]}}]}}),m);let Wt=p([M("ha-automation-condition-logical")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{conditions:[]}}},{kind:"method",key:"render",value:function(){return _`
  698. <ha-automation-condition
  699. .conditions=${this.condition.conditions||[]}
  700. @value-changed=${this._valueChanged}
  701. .hass=${this.hass}
  702. .disabled=${this.disabled}
  703. .reOrderMode=${this.reOrderMode}
  704. ></ha-automation-condition>
  705. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.condition,conditions:e.detail.value}})}}]}}),m);p([M("ha-automation-condition-and")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[]}}),Wt),p([M("ha-automation-condition-not")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[]}}),Wt),p([M("ha-automation-condition-or")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[]}}),Wt),p([M("ha-automation-condition-editor")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"condition",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"yamlMode",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",key:"_processedCondition",value:()=>X((e=>(e=>{if("condition"in e&&Array.isArray(e.condition))return{condition:"and",conditions:e.condition};for(const t of["and","or","not"])if(t in e)return{condition:t,conditions:e[t]};return e})(e)))},{kind:"method",key:"render",value:function(){const e=this._processedCondition(this.condition),t=void 0!==customElements.get(`ha-automation-condition-${e.condition}`),i=this.yamlMode||!t;return _`
  706. ${i?_`
  707. ${t?"":_`
  708. ${this.hass.localize("ui.panel.config.automation.editor.conditions.unsupported_condition","condition",e.condition)}
  709. `}
  710. <ha-yaml-editor
  711. .hass=${this.hass}
  712. .defaultValue=${this.condition}
  713. @value-changed=${this._onYamlChange}
  714. .readOnly=${this.disabled}
  715. ></ha-yaml-editor>
  716. `:_`
  717. <div>
  718. ${me(`ha-automation-condition-${e.condition}`,{hass:this.hass,condition:e,reOrderMode:this.reOrderMode,disabled:this.disabled})}
  719. </div>
  720. `}
  721. `}},{kind:"method",key:"_onYamlChange",value:function(e){e.stopPropagation(),e.detail.isValid&&C(this,"value-changed",{value:e.detail.value,yaml:!0})}},{kind:"field",static:!0,key:"styles",value:()=>T}]}}),m),p([M("ha-automation-action-condition")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f()],key:"action",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{condition:"state"}}},{kind:"method",key:"render",value:function(){return _`
  722. <ha-select
  723. fixedMenuPosition
  724. .label=${this.hass.localize("ui.panel.config.automation.editor.conditions.type_select")}
  725. .disabled=${this.disabled}
  726. .value=${this.action.condition}
  727. naturalMenuWidth
  728. @selected=${this._typeChanged}
  729. >
  730. ${this._processedTypes(this.hass.localize).map((([e,t,i])=>_`
  731. <mwc-list-item .value=${e} aria-label=${t} graphic="icon">
  732. ${t}<ha-svg-icon slot="graphic" .path=${i}></ha-svg-icon
  733. ></mwc-list-item>
  734. `))}
  735. </ha-select>
  736. <ha-automation-condition-editor
  737. .condition=${this.action}
  738. .disabled=${this.disabled}
  739. .hass=${this.hass}
  740. @value-changed=${this._conditionChanged}
  741. ></ha-automation-condition-editor>
  742. `}},{kind:"field",key:"_processedTypes",value:()=>X((e=>Object.entries(Tt).map((([t,i])=>[t,e(`ui.panel.config.automation.editor.conditions.type.${t}.label`),i])).sort(((e,t)=>he(e[1],t[1])))))},{kind:"method",key:"_conditionChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:e.detail.value})}},{kind:"method",key:"_typeChanged",value:function(e){const t=e.target.value;if(!t)return;const i=customElements.get(`ha-automation-condition-${t}`);t!==this.action.condition&&C(this,"value-changed",{value:{condition:t,...i.defaultConfig}})}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  743. ha-select {
  744. margin-bottom: 24px;
  745. }
  746. `}}]}}),m),p([M("ha-automation-action-delay")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[y()],key:"_timeData",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{delay:""}}},{kind:"method",key:"willUpdate",value:function(e){e.has("action")&&(this.action&&pt(this.action)?C(this,"ui-mode-not-available",Error(this.hass.localize("ui.errors.config.no_template_editor_support"))):this._timeData=Ft(this.action.delay))}},{kind:"method",key:"render",value:function(){return _`<ha-duration-input
  747. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.delay.delay")}
  748. .disabled=${this.disabled}
  749. .data=${this._timeData}
  750. enableMillisecond
  751. @value-changed=${this._valueChanged}
  752. ></ha-duration-input>`}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;t&&C(this,"value-changed",{value:{...this.action,delay:t}})}}]}}),m),p([M("ha-device-action-picker")],(function(e,t){return{F:class extends t{constructor(){super(bt,mt,(e=>({device_id:e||"",domain:"",entity_id:""}))),e(this)}},d:[{kind:"get",key:"NO_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.actions.no_actions")}},{kind:"get",key:"UNKNOWN_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.actions.unknown_action")}}]}}),jt),p([M("ha-automation-action-device_id")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({type:Object})],key:"action",value:void 0},{kind:"field",decorators:[y()],key:"_deviceId",value:void 0},{kind:"field",decorators:[y()],key:"_capabilities",value:void 0},{kind:"field",key:"_origAction",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{device_id:"",domain:"",entity_id:""}}},{kind:"field",key:"_extraFieldsData",value:()=>X(((e,t)=>{const i={};return t.extra_fields.forEach((t=>{void 0!==e[t.name]&&(i[t.name]=e[t.name])})),i}))},{kind:"method",key:"render",value:function(){var e;const t=this._deviceId||this.action.device_id;return _`
  753. <ha-device-picker
  754. .value=${t}
  755. .disabled=${this.disabled}
  756. @value-changed=${this._devicePicked}
  757. .hass=${this.hass}
  758. label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.device_id.label")}
  759. ></ha-device-picker>
  760. <ha-device-action-picker
  761. .value=${this.action}
  762. .deviceId=${t}
  763. .disabled=${this.disabled}
  764. @value-changed=${this._deviceActionPicked}
  765. .hass=${this.hass}
  766. label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.device_id.action")}
  767. ></ha-device-action-picker>
  768. ${null!==(e=this._capabilities)&&void 0!==e&&e.extra_fields?_`
  769. <ha-form
  770. .hass=${this.hass}
  771. .data=${this._extraFieldsData(this.action,this._capabilities)}
  772. .schema=${this._capabilities.extra_fields}
  773. .disabled=${this.disabled}
  774. .computeLabel=${this._extraFieldsComputeLabelCallback(this.hass.localize)}
  775. @value-changed=${this._extraFieldsChanged}
  776. ></ha-form>
  777. `:""}
  778. `}},{kind:"method",key:"firstUpdated",value:function(){this._capabilities||this._getCapabilities(),this.action&&(this._origAction=this.action)}},{kind:"method",key:"updated",value:function(e){const t=e.get("action");t&&!_t(t,this.action)&&(this._deviceId=void 0,this._getCapabilities())}},{kind:"method",key:"_getCapabilities",value:async function(){var e,t;this._capabilities=this.action.domain?await(e=this.hass,t=this.action,e.callWS({type:"device_automation/action/capabilities",action:t})):void 0}},{kind:"method",key:"_devicePicked",value:function(e){e.stopPropagation(),this._deviceId=e.target.value,void 0===this._deviceId&&C(this,"value-changed",{value:i.defaultConfig})}},{kind:"method",key:"_deviceActionPicked",value:function(e){e.stopPropagation();let t=e.detail.value;this._origAction&&_t(this._origAction,t)&&(t=this._origAction),C(this,"value-changed",{value:t})}},{kind:"method",key:"_extraFieldsChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.action,...e.detail.value}})}},{kind:"method",key:"_extraFieldsComputeLabelCallback",value:function(e){return t=>e(`ui.panel.config.automation.editor.actions.type.device_id.extra_fields.${t.name}`)||t.name}},{kind:"field",static:!0,key:"styles",value:()=>g`
  779. ha-device-picker {
  780. display: block;
  781. margin-bottom: 16px;
  782. }
  783. ha-device-action-picker {
  784. display: block;
  785. }
  786. `}]}}),m),p([M("ha-automation-action-event")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f()],key:"action",value:void 0},{kind:"field",decorators:[k("ha-yaml-editor",!0)],key:"_yamlEditor",value:void 0},{kind:"field",key:"_actionData",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{event:"",event_data:{}}}},{kind:"method",key:"updated",value:function(e){e.has("action")&&(this._actionData&&this._actionData!==this.action.event_data&&this._yamlEditor&&this._yamlEditor.setValue(this.action.event_data),this._actionData=this.action.event_data)}},{kind:"method",key:"render",value:function(){const{event:e,event_data:t}=this.action;return _`
  787. <ha-textfield
  788. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.event.event")}
  789. .value=${e}
  790. .disabled=${this.disabled}
  791. @change=${this._eventChanged}
  792. ></ha-textfield>
  793. <ha-yaml-editor
  794. .hass=${this.hass}
  795. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.event.event_data")}
  796. .name=${"event_data"}
  797. .readOnly=${this.disabled}
  798. .defaultValue=${t}
  799. @value-changed=${this._dataChanged}
  800. ></ha-yaml-editor>
  801. `}},{kind:"method",key:"_dataChanged",value:function(e){e.stopPropagation(),e.detail.isValid&&(this._actionData=e.detail.value,ui(this,e))}},{kind:"method",key:"_eventChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.action,event:e.target.value}})}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  802. ha-textfield {
  803. display: block;
  804. }
  805. `}}]}}),m),p([M("ha-automation-action-if")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",decorators:[y()],key:"_showElse",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{if:[],then:[]}}},{kind:"method",key:"render",value:function(){const e=this.action;return _`
  806. <h3>
  807. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.if.if")}*:
  808. </h3>
  809. <ha-automation-condition
  810. .conditions=${e.if}
  811. .reOrderMode=${this.reOrderMode}
  812. .disabled=${this.disabled}
  813. @value-changed=${this._ifChanged}
  814. .hass=${this.hass}
  815. ></ha-automation-condition>
  816. <h3>
  817. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.if.then")}*:
  818. </h3>
  819. <ha-automation-action
  820. .actions=${e.then}
  821. .reOrderMode=${this.reOrderMode}
  822. .disabled=${this.disabled}
  823. @value-changed=${this._thenChanged}
  824. .hass=${this.hass}
  825. ></ha-automation-action>
  826. ${this._showElse||e.else?_`
  827. <h3>
  828. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.if.else")}:
  829. </h3>
  830. <ha-automation-action
  831. .actions=${e.else||[]}
  832. .reOrderMode=${this.reOrderMode}
  833. .disabled=${this.disabled}
  834. @value-changed=${this._elseChanged}
  835. .hass=${this.hass}
  836. ></ha-automation-action>
  837. `:_` <div class="link-button-row">
  838. <button
  839. class="link"
  840. @click=${this._addElse}
  841. .disabled=${this.disabled}
  842. >
  843. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.if.add_else")}
  844. </button>
  845. </div>`}
  846. `}},{kind:"method",key:"_addElse",value:function(){this._showElse=!0}},{kind:"method",key:"_ifChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,if:t}})}},{kind:"method",key:"_thenChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,then:t}})}},{kind:"method",key:"_elseChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,else:t}})}},{kind:"get",static:!0,key:"styles",value:function(){return[T,g`
  847. .link-button-row {
  848. padding: 14px;
  849. }
  850. `]}}]}}),m),p([M("ha-automation-action-parallel")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{parallel:[]}}},{kind:"method",key:"render",value:function(){const e=this.action;return _`
  851. <ha-automation-action
  852. .actions=${e.parallel}
  853. .reOrderMode=${this.reOrderMode}
  854. .disabled=${this.disabled}
  855. @value-changed=${this._actionsChanged}
  856. .hass=${this.hass}
  857. ></ha-automation-action>
  858. `}},{kind:"method",key:"_actionsChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,parallel:t}})}},{kind:"get",static:!0,key:"styles",value:function(){return T}}]}}),m),p([M("ha-automation-action-play_media")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"narrow",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{service:"media_player.play_media",target:{entity_id:""},data:{media_content_id:"",media_content_type:""},metadata:{}}}},{kind:"field",key:"_getSelectorValue",value:()=>X((e=>{var t,i,a;return{entity_id:(null===(t=e.target)||void 0===t?void 0:t.entity_id)||e.entity_id,media_content_id:null===(i=e.data)||void 0===i?void 0:i.media_content_id,media_content_type:null===(a=e.data)||void 0===a?void 0:a.media_content_type,metadata:e.metadata}}))},{kind:"method",key:"render",value:function(){return _`
  859. <ha-selector-media
  860. .hass=${this.hass}
  861. .disabled=${this.disabled}
  862. .value=${this._getSelectorValue(this.action)}
  863. @value-changed=${this._valueChanged}
  864. ></ha-selector-media>
  865. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{service:"media_player.play_media",target:{entity_id:e.detail.value.entity_id},data:{media_content_id:e.detail.value.media_content_id,media_content_type:e.detail.value.media_content_type},metadata:e.detail.value.metadata||{}}})}}]}}),m);const Rt=["count","while","until"],Kt=e=>Rt.find((t=>t in e));p([M("ha-automation-action-repeat")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{repeat:{count:2,sequence:[]}}}},{kind:"method",key:"render",value:function(){const e=this.action.repeat,t=Kt(e);return _`
  866. <ha-select
  867. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.repeat.type_select")}
  868. .value=${t}
  869. .disabled=${this.disabled}
  870. @selected=${this._typeChanged}
  871. >
  872. ${Rt.map((e=>_`
  873. <mwc-list-item .value=${e}>
  874. ${this.hass.localize(`ui.panel.config.automation.editor.actions.type.repeat.type.${e}.label`)}
  875. </mwc-list-item>
  876. `))}
  877. </ha-select>
  878. <div>
  879. ${"count"===t?_`
  880. <ha-textfield
  881. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.repeat.type.count.label")}
  882. name="count"
  883. .value=${e.count||"0"}
  884. .disabled=${this.disabled}
  885. @change=${this._countChanged}
  886. ></ha-textfield>
  887. `:"while"===t?_` <h3>
  888. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.repeat.type.while.conditions")}:
  889. </h3>
  890. <ha-automation-condition
  891. .conditions=${e.while||[]}
  892. .hass=${this.hass}
  893. .disabled=${this.disabled}
  894. @value-changed=${this._conditionChanged}
  895. ></ha-automation-condition>`:"until"===t?_` <h3>
  896. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.repeat.type.until.conditions")}:
  897. </h3>
  898. <ha-automation-condition
  899. .conditions=${e.until||[]}
  900. .hass=${this.hass}
  901. .disabled=${this.disabled}
  902. @value-changed=${this._conditionChanged}
  903. ></ha-automation-condition>`:""}
  904. </div>
  905. <h3>
  906. ${this.hass.localize("ui.panel.config.automation.editor.actions.type.repeat.sequence")}:
  907. </h3>
  908. <ha-automation-action
  909. .actions=${e.sequence}
  910. .reOrderMode=${this.reOrderMode}
  911. .disabled=${this.disabled}
  912. @value-changed=${this._actionChanged}
  913. .hass=${this.hass}
  914. ></ha-automation-action>
  915. `}},{kind:"method",key:"_typeChanged",value:function(e){const t=e.target.value;if(!t||t===Kt(this.action.repeat))return;const i="count"===t?2:[];C(this,"value-changed",{value:{...this.action,repeat:{[t]:i,sequence:this.action.repeat.sequence}}})}},{kind:"method",key:"_conditionChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,repeat:{...this.action.repeat,[Kt(this.action.repeat)]:t}}})}},{kind:"method",key:"_actionChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:{...this.action,repeat:{...this.action.repeat,sequence:t}}})}},{kind:"method",key:"_countChanged",value:function(e){const t=e.target.value;this.action.repeat.count!==t&&C(this,"value-changed",{value:{...this.action,repeat:{...this.action.repeat,count:t}}})}},{kind:"get",static:!0,key:"styles",value:function(){return[T,g`
  916. ha-textfield {
  917. margin-top: 16px;
  918. }
  919. `]}}]}}),m);const Vt=e=>"all"===e||(e=>e.includes("."))(e),Xt=Ze({alias:et(tt()),service:et(tt()),entity_id:et((Yt=tt(),Gt="entity ID (domain.entity or all)",Jt=Vt,new qe({...Yt,*refiner(e,t){yield*Yt.refiner(e,t);const i=Be(Jt(e,t),t,Yt,e);for(const e of i)yield{...e,refinement:Gt}}}))),target:et(Ye()),data:et(Ye())});var Yt,Gt,Jt;p([M("ha-automation-action-service")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"narrow",value:()=>!1},{kind:"field",decorators:[y()],key:"_action",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{service:"",data:{}}}},{kind:"method",key:"willUpdate",value:function(e){if(e.has("action")){try{We(this.action,Xt)}catch(e){return void C(this,"ui-mode-not-available",e)}this.action&&pt(this.action)?C(this,"ui-mode-not-available",Error(this.hass.localize("ui.errors.config.no_template_editor_support"))):this.action.entity_id?(this._action={...this.action,data:{...this.action.data,entity_id:this.action.entity_id}},delete this._action.entity_id):this._action=this.action}}},{kind:"method",key:"render",value:function(){var e;return _`
  920. <ha-service-control
  921. .narrow=${this.narrow}
  922. .hass=${this.hass}
  923. .value=${this._action}
  924. .disabled=${this.disabled}
  925. .showAdvanced=${null===(e=this.hass.userData)||void 0===e?void 0:e.showAdvanced}
  926. @value-changed=${this._actionChanged}
  927. ></ha-service-control>
  928. `}},{kind:"method",key:"_actionChanged",value:function(e){e.detail.value===this._action&&e.stopPropagation()}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  929. ha-service-control {
  930. display: block;
  931. margin: 0 -16px;
  932. }
  933. `}}]}}),m),p([M("ha-automation-action-stop")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{stop:""}}},{kind:"method",key:"render",value:function(){const{error:e,stop:t}=this.action;return _`
  934. <ha-textfield
  935. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.stop.stop")}
  936. .value=${t}
  937. .disabled=${this.disabled}
  938. @change=${this._stopChanged}
  939. ></ha-textfield>
  940. <ha-formfield
  941. .disabled=${this.disabled}
  942. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.stop.error")}
  943. >
  944. <ha-switch
  945. .disabled=${this.disabled}
  946. .checked=${null!=e&&e}
  947. @change=${this._errorChanged}
  948. ></ha-switch>
  949. </ha-formfield>
  950. `}},{kind:"method",key:"_stopChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.action,stop:e.target.value}})}},{kind:"method",key:"_errorChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.action,error:e.target.checked}})}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  951. ha-textfield {
  952. display: block;
  953. margin-bottom: 24px;
  954. }
  955. `}}]}}),m);const Ht={calendar:H,device:u,event:i,state:j,geo_location:Q,homeassistant:Z,mqtt:ee,numeric_state:F,sun:I,tag:te,template:s,time:S,time_pattern:ie,webhook:ae,zone:N};p([M("ha-automation-trigger-calendar")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"entity_id",required:!0,selector:{entity:{domain:"calendar"}}},{name:"event",type:"select",required:!0,options:[["start",e("ui.panel.config.automation.editor.triggers.type.calendar.start")],["end",e("ui.panel.config.automation.editor.triggers.type.calendar.end")]]},{name:"offset",selector:{duration:{enable_day:!0}}},{name:"offset_type",type:"select",required:!0,options:[["before",e("ui.panel.config.automation.editor.triggers.type.calendar.before")],["after",e("ui.panel.config.automation.editor.triggers.type.calendar.after")]]}]))},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{event:"start",offset:0}}},{kind:"method",key:"render",value:function(){const e=this._schema(this.hass.localize),t=this.trigger.offset,i=Ft(t);let a="after";("object"==typeof t&&i.hours<0||"string"==typeof t&&t.startsWith("-"))&&(i.hours=Math.abs(i.hours),a="before");const o={...this.trigger,offset:i,offset_type:a};return _`
  956. <ha-form
  957. .schema=${e}
  958. .data=${o}
  959. .hass=${this.hass}
  960. .disabled=${this.disabled}
  961. .computeLabel=${this._computeLabelCallback}
  962. @value-changed=${this._valueChanged}
  963. ></ha-form>
  964. `}},{kind:"method",key:"_valueChanged",value:function(e){var t,i,a;e.stopPropagation();const o=e.detail.value.offset,n="before"===e.detail.value.offset_type?"-":"",s={...e.detail.value,offset:`${n}${null!==(t=o.hours)&&void 0!==t?t:0}:${null!==(i=o.minutes)&&void 0!==i?i:0}:${null!==(a=o.seconds)&&void 0!==a?a:0}`};delete s.offset_type,C(this,"value-changed",{value:s})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.calendar.${e.name}`)}}]}}),m),p([M("ha-device-trigger-picker")],(function(e,t){return{F:class extends t{constructor(){super(xt,yt,(e=>({device_id:e||"",platform:"device",domain:"",entity_id:""}))),e(this)}},d:[{kind:"get",key:"NO_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.triggers.no_triggers")}},{kind:"get",key:"UNKNOWN_AUTOMATION_TEXT",value:function(){return this.hass.localize("ui.panel.config.devices.automation.triggers.unknown_trigger")}}]}}),jt),p([M("ha-automation-trigger-device")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Object})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_deviceId",value:void 0},{kind:"field",decorators:[y()],key:"_capabilities",value:void 0},{kind:"field",key:"_origTrigger",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{device_id:"",domain:"",entity_id:""}}},{kind:"field",key:"_extraFieldsData",value:()=>X(((e,t)=>{const i={};return t.extra_fields.forEach((t=>{void 0!==e[t.name]&&(i[t.name]=e[t.name])})),i}))},{kind:"method",key:"render",value:function(){var e;const t=this._deviceId||this.trigger.device_id;return _`
  965. <ha-device-picker
  966. .value=${t}
  967. @value-changed=${this._devicePicked}
  968. .hass=${this.hass}
  969. .disabled=${this.disabled}
  970. label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.device.label")}
  971. ></ha-device-picker>
  972. <ha-device-trigger-picker
  973. .value=${this.trigger}
  974. .deviceId=${t}
  975. @value-changed=${this._deviceTriggerPicked}
  976. .hass=${this.hass}
  977. .disabled=${this.disabled}
  978. label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.device.trigger")}
  979. ></ha-device-trigger-picker>
  980. ${null!==(e=this._capabilities)&&void 0!==e&&e.extra_fields?_`
  981. <ha-form
  982. .hass=${this.hass}
  983. .data=${this._extraFieldsData(this.trigger,this._capabilities)}
  984. .schema=${this._capabilities.extra_fields}
  985. .disabled=${this.disabled}
  986. .computeLabel=${this._extraFieldsComputeLabelCallback(this.hass.localize)}
  987. @value-changed=${this._extraFieldsChanged}
  988. ></ha-form>
  989. `:""}
  990. `}},{kind:"method",key:"firstUpdated",value:function(){this._capabilities||this._getCapabilities(),this.trigger&&(this._origTrigger=this.trigger)}},{kind:"method",key:"updated",value:function(e){if(!e.has("trigger"))return;const t=e.get("trigger");t&&!_t(t,this.trigger)&&this._getCapabilities()}},{kind:"method",key:"_getCapabilities",value:async function(){const e=this.trigger;this._capabilities=e.domain?await((e,t)=>e.callWS({type:"device_automation/trigger/capabilities",trigger:t}))(this.hass,e):void 0}},{kind:"method",key:"_devicePicked",value:function(e){e.stopPropagation(),this._deviceId=e.target.value,void 0===this._deviceId&&C(this,"value-changed",{value:{...i.defaultConfig,platform:"device"}})}},{kind:"method",key:"_deviceTriggerPicked",value:function(e){e.stopPropagation();let t=e.detail.value;this._origTrigger&&_t(this._origTrigger,t)&&(t=this._origTrigger),this.trigger.id&&(t.id=this.trigger.id),C(this,"value-changed",{value:t})}},{kind:"method",key:"_extraFieldsChanged",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.trigger,...e.detail.value}})}},{kind:"method",key:"_extraFieldsComputeLabelCallback",value:function(e){return t=>e(`ui.panel.config.automation.editor.triggers.type.device.extra_fields.${t.name}`)||t.name}},{kind:"field",static:!0,key:"styles",value:()=>g`
  991. ha-device-picker {
  992. display: block;
  993. margin-bottom: 24px;
  994. }
  995. `}]}}),m);const Qt={},Zt=oe(class extends ne{constructor(){super(...arguments),this.ot=Qt}render(e,t){return t()}update(e,[t,i]){if(Array.isArray(t)){if(Array.isArray(this.ot)&&this.ot.length===t.length&&t.every(((e,t)=>e===this.ot[t])))return se}else if(this.ot===t)return se;return this.ot=Array.isArray(t)?Array.from(t):t,this.render(t,i)}}),ei=async e=>e.callWS({type:"config/auth/list"});p([M("ha-user-badge")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"user",value:void 0},{kind:"field",decorators:[y()],key:"_personPicture",value:void 0},{kind:"field",key:"_personEntityId",value:void 0},{kind:"method",key:"willUpdate",value:function(e){if(x(w(i.prototype),"willUpdate",this).call(this,e),e.has("user"))return void this._getPersonPicture();const t=e.get("hass");if(this._personEntityId&&t&&this.hass.states[this._personEntityId]!==t.states[this._personEntityId]){const e=this.hass.states[this._personEntityId];e?this._personPicture=e.attributes.entity_picture:this._getPersonPicture()}else!this._personEntityId&&t&&this._getPersonPicture()}},{kind:"method",key:"render",value:function(){if(!this.hass||!this.user)return _``;const e=this._personPicture;if(e)return _`<div
  996. style=${de({backgroundImage:`url(${e})`})}
  997. class="picture"
  998. ></div>`;const t=(e=>e?e.trim().split(" ").slice(0,3).map((e=>e.substring(0,1))).join(""):"?")(this.user.name);return _`<div
  999. class="initials ${$({long:t.length>2})}"
  1000. >
  1001. ${t}
  1002. </div>`}},{kind:"method",key:"_getPersonPicture",value:function(){if(this._personEntityId=void 0,this._personPicture=void 0,this.hass&&this.user)for(const e of Object.values(this.hass.states))if(e.attributes.user_id===this.user.id&&"person"===Pe(e)){this._personEntityId=e.entity_id,this._personPicture=e.attributes.entity_picture;break}}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1003. :host {
  1004. display: contents;
  1005. }
  1006. .picture {
  1007. width: 40px;
  1008. height: 40px;
  1009. background-size: cover;
  1010. border-radius: 50%;
  1011. }
  1012. .initials {
  1013. display: inline-block;
  1014. box-sizing: border-box;
  1015. width: 40px;
  1016. line-height: 40px;
  1017. border-radius: 50%;
  1018. text-align: center;
  1019. background-color: var(--light-primary-color);
  1020. text-decoration: none;
  1021. color: var(--text-light-primary-color, var(--primary-text-color));
  1022. overflow: hidden;
  1023. }
  1024. .initials.long {
  1025. font-size: 80%;
  1026. }
  1027. `}}]}}),m),p([M("ha-list-item")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"get",static:!0,key:"styles",value:function(){return[pe,g`
  1028. :host {
  1029. padding-left: var(--mdc-list-side-padding, 20px);
  1030. padding-right: var(--mdc-list-side-padding, 20px);
  1031. }
  1032. :host([graphic="avatar"]:not([twoLine])),
  1033. :host([graphic="icon"]:not([twoLine])) {
  1034. height: 48px;
  1035. }
  1036. span.material-icons:first-of-type {
  1037. margin-inline-start: 0px !important;
  1038. margin-inline-end: var(
  1039. --mdc-list-item-graphic-margin,
  1040. 16px
  1041. ) !important;
  1042. direction: var(--direction);
  1043. }
  1044. span.material-icons:last-of-type {
  1045. margin-inline-start: auto !important;
  1046. margin-inline-end: 0px !important;
  1047. direction: var(--direction);
  1048. }
  1049. `]}}]}}),ge);let ti=p(null,(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"label",value:void 0},{kind:"field",decorators:[f()],key:"noUserLabel",value:void 0},{kind:"field",decorators:[f()],key:"value",value:()=>""},{kind:"field",decorators:[f()],key:"users",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_sortedUsers",value:()=>X((e=>e?e.filter((e=>!e.system_generated)).sort(((e,t)=>he(e.name,t.name))):[]))},{kind:"method",key:"render",value:function(){var e,t;return _`
  1050. <ha-select
  1051. .label=${this.label}
  1052. .disabled=${this.disabled}
  1053. .value=${this.value}
  1054. @selected=${this._userChanged}
  1055. >
  1056. ${0===(null===(e=this.users)||void 0===e?void 0:e.length)?_`<mwc-list-item value="">
  1057. ${this.noUserLabel||(null===(t=this.hass)||void 0===t?void 0:t.localize("ui.components.user-picker.no_user"))}
  1058. </mwc-list-item>`:""}
  1059. ${this._sortedUsers(this.users).map((e=>_`
  1060. <ha-list-item graphic="avatar" .value=${e.id}>
  1061. <ha-user-badge
  1062. .hass=${this.hass}
  1063. .user=${e}
  1064. slot="graphic"
  1065. ></ha-user-badge>
  1066. ${e.name}
  1067. </ha-list-item>
  1068. `))}
  1069. </ha-select>
  1070. `}},{kind:"method",key:"firstUpdated",value:function(e){x(w(i.prototype),"firstUpdated",this).call(this,e),void 0===this.users&&ei(this.hass).then((e=>{this.users=e}))}},{kind:"method",key:"_userChanged",value:function(e){const t=e.target.value;t!==this.value&&(this.value=t,setTimeout((()=>{C(this,"value-changed",{value:t}),C(this,"change")}),0))}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1071. :host {
  1072. display: inline-block;
  1073. }
  1074. mwc-list {
  1075. display: block;
  1076. }
  1077. `}}]}}),m);customElements.define("ha-user-picker",ti),p([M("ha-users-picker")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"value",value:void 0},{kind:"field",decorators:[f({attribute:"picked-user-label"})],key:"pickedUserLabel",value:void 0},{kind:"field",decorators:[f({attribute:"pick-user-label"})],key:"pickUserLabel",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"users",value:void 0},{kind:"method",key:"firstUpdated",value:function(e){x(w(i.prototype),"firstUpdated",this).call(this,e),void 0===this.users&&ei(this.hass).then((e=>{this.users=e}))}},{kind:"method",key:"render",value:function(){if(!this.hass||!this.users)return _``;const e=this._notSelectedUsers(this.users,this.value);return _`
  1078. ${Zt([e],(()=>{var t;return null===(t=this.value)||void 0===t?void 0:t.map(((t,i)=>_`
  1079. <div>
  1080. <ha-user-picker
  1081. .label=${this.pickedUserLabel}
  1082. .noUserLabel=${this.hass.localize("ui.components.user-picker.remove_user")}
  1083. .index=${i}
  1084. .hass=${this.hass}
  1085. .value=${t}
  1086. .users=${this._notSelectedUsersAndSelected(t,this.users,e)}
  1087. @value-changed=${this._userChanged}
  1088. ></ha-user-picker>
  1089. <ha-icon-button
  1090. .userId=${t}
  1091. .label=${this.hass.localize("ui.components.user-picker.remove_user")}
  1092. .path=${re}
  1093. @click=${this._removeUser}
  1094. >
  1095. ></ha-icon-button
  1096. >
  1097. </div>
  1098. `))}))}
  1099. <ha-user-picker
  1100. .label=${this.pickUserLabel||this.hass.localize("ui.components.user-picker.add_user")}
  1101. .hass=${this.hass}
  1102. .users=${e}
  1103. .disabled=${!(null!=e&&e.length)}
  1104. @value-changed=${this._addUser}
  1105. ></ha-user-picker>
  1106. `}},{kind:"field",key:"_notSelectedUsers",value:()=>X(((e,t)=>t?null==e?void 0:e.filter((e=>!e.system_generated&&!t.includes(e.id))):null==e?void 0:e.filter((e=>!e.system_generated))))},{kind:"field",key:"_notSelectedUsersAndSelected",value:()=>(e,t,i)=>{const a=null==t?void 0:t.find((t=>t.id===e));return a?i?[...i,a]:[a]:i}},{kind:"get",key:"_currentUsers",value:function(){return this.value||[]}},{kind:"method",key:"_updateUsers",value:async function(e){this.value=e,C(this,"value-changed",{value:e})}},{kind:"method",key:"_userChanged",value:function(e){e.stopPropagation();const t=e.currentTarget.index,i=e.detail.value,a=[...this._currentUsers];""===i?a.splice(t,1):a.splice(t,1,i),this._updateUsers(a)}},{kind:"method",key:"_addUser",value:async function(e){e.stopPropagation();const t=e.detail.value;if(e.currentTarget.value="",!t)return;const i=this._currentUsers;i.includes(t)||this._updateUsers([...i,t])}},{kind:"method",key:"_removeUser",value:function(e){const t=e.currentTarget.userId;this._updateUsers(this._currentUsers.filter((e=>e!==t)))}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1107. :host {
  1108. display: block;
  1109. }
  1110. div {
  1111. display: flex;
  1112. align-items: center;
  1113. }
  1114. `}}]}}),m),p([M("ha-automation-trigger-event")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{event_type:""}}},{kind:"method",key:"render",value:function(){const{event_type:e,event_data:t,context:i}=this.trigger;return _`
  1115. <ha-textfield
  1116. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.event.event_type")}
  1117. name="event_type"
  1118. .value=${e}
  1119. .disabled=${this.disabled}
  1120. @change=${this._valueChanged}
  1121. ></ha-textfield>
  1122. <ha-yaml-editor
  1123. .hass=${this.hass}
  1124. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.event.event_data")}
  1125. .name=${"event_data"}
  1126. .readOnly=${this.disabled}
  1127. .defaultValue=${t}
  1128. @value-changed=${this._dataChanged}
  1129. ></ha-yaml-editor>
  1130. <br />
  1131. ${this.hass.localize("ui.panel.config.automation.editor.triggers.type.event.context_users")}
  1132. <ha-users-picker
  1133. .pickedUserLabel=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.event.context_user_picked")}
  1134. .pickUserLabel=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.event.context_user_pick")}
  1135. .hass=${this.hass}
  1136. .disabled=${this.disabled}
  1137. .value=${this._wrapUsersInArray(null==i?void 0:i.user_id)}
  1138. @value-changed=${this._usersChanged}
  1139. ></ha-users-picker>
  1140. `}},{kind:"method",key:"_wrapUsersInArray",value:function(e){return e?"string"==typeof e?[e]:e:[]}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation(),di(this,e)}},{kind:"method",key:"_dataChanged",value:function(e){e.stopPropagation(),e.detail.isValid&&di(this,e)}},{kind:"method",key:"_usersChanged",value:function(e){e.stopPropagation();const t={...this.trigger};!e.detail.value.length&&t.context?delete t.context.user_id:(t.context||(t.context={}),t.context.user_id=e.detail.value),C(this,"value-changed",{value:t})}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1141. ha-textfield {
  1142. display: block;
  1143. }
  1144. `}}]}}),m),p([M("ha-automation-trigger-geo_location")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"source",selector:{text:{}}},{name:"zone",selector:{entity:{domain:"zone"}}},{name:"event",type:"select",required:!0,options:[["enter",e("ui.panel.config.automation.editor.triggers.type.geo_location.enter")],["leave",e("ui.panel.config.automation.editor.triggers.type.geo_location.leave")]]}]))},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{source:"",zone:"",event:"enter"}}},{kind:"method",key:"render",value:function(){return _`
  1145. <ha-form
  1146. .schema=${this._schema(this.hass.localize)}
  1147. .data=${this.trigger}
  1148. .hass=${this.hass}
  1149. .disabled=${this.disabled}
  1150. .computeLabel=${this._computeLabelCallback}
  1151. @value-changed=${this._valueChanged}
  1152. ></ha-form>
  1153. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.geo_location.${e.name}`)}}]}}),m),p([M("ha-automation-trigger-homeassistant")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"event",type:"select",required:!0,options:[["start",e("ui.panel.config.automation.editor.triggers.type.homeassistant.start")],["shutdown",e("ui.panel.config.automation.editor.triggers.type.homeassistant.shutdown")]]}]))},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{event:"start"}}},{kind:"method",key:"render",value:function(){return _`
  1154. <ha-form
  1155. .schema=${this._schema(this.hass.localize)}
  1156. .data=${this.trigger}
  1157. .hass=${this.hass}
  1158. .disabled=${this.disabled}
  1159. .computeLabel=${this._computeLabelCallback}
  1160. @value-changed=${this._valueChanged}
  1161. ></ha-form>
  1162. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.homeassistant.${e.name}`)}},{kind:"field",static:!0,key:"styles",value:()=>g`
  1163. label {
  1164. display: flex;
  1165. align-items: center;
  1166. }
  1167. `}]}}),m);const ii=[{name:"topic",required:!0,selector:{text:{}}},{name:"payload",selector:{text:{}}}];p([M("ha-automation-trigger-mqtt")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{topic:""}}},{kind:"method",key:"render",value:function(){return _`
  1168. <ha-form
  1169. .schema=${ii}
  1170. .data=${this.trigger}
  1171. .hass=${this.hass}
  1172. .disabled=${this.disabled}
  1173. .computeLabel=${this._computeLabelCallback}
  1174. @value-changed=${this._valueChanged}
  1175. ></ha-form>
  1176. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.mqtt.${e.name}`)}}]}}),m),p([M("ha-automation-trigger-numeric_state")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"entity_id",required:!0,selector:{entity:{}}},{name:"attribute",selector:{attribute:{entity_id:e,hide_attributes:["access_token","auto_update","available_modes","away_mode","changed_by","code_format","color_modes","current_activity","device_class","editable","effect_list","effect","entity_picture","fan_mode","fan_modes","fan_speed_list","forecast","friendly_name","frontend_stream_type","has_date","has_time","hs_color","hvac_mode","hvac_modes","icon","media_album_name","media_artist","media_content_type","media_position_updated_at","media_title","next_dawn","next_dusk","next_midnight","next_noon","next_rising","next_setting","operation_list","operation_mode","options","preset_mode","preset_modes","release_notes","release_summary","release_url","restored","rgb_color","rgbw_color","shuffle","sound_mode_list","sound_mode","source_list","source_type","source","state_class","supported_features","swing_mode","swing_mode","swing_modes","title","token","unit_of_measurement","xy_color"]}}},{name:"above",selector:{number:{mode:"box",min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER,step:.1}}},{name:"below",selector:{number:{mode:"box",min:Number.MIN_SAFE_INTEGER,max:Number.MAX_SAFE_INTEGER,step:.1}}},{name:"value_template",selector:{template:{}}},{name:"for",selector:{duration:{}}}]))},{kind:"method",key:"willUpdate",value:function(e){e.has("trigger")&&this.trigger&&pt(this.trigger.for)&&C(this,"ui-mode-not-available",Error(this.hass.localize("ui.errors.config.no_template_editor_support")))}},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{entity_id:""}}},{kind:"method",key:"render",value:function(){const e=Ft(this.trigger.for),t={...this.trigger,for:e},i=this._schema(this.trigger.entity_id);return _`
  1177. <ha-form
  1178. .hass=${this.hass}
  1179. .data=${t}
  1180. .schema=${i}
  1181. .disabled=${this.disabled}
  1182. @value-changed=${this._valueChanged}
  1183. .computeLabel=${this._computeLabelCallback}
  1184. ></ha-form>
  1185. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>{switch(e.name){case"entity_id":return this.hass.localize("ui.components.entity.entity-picker.entity");case"attribute":return this.hass.localize("ui.components.entity.entity-attribute-picker.attribute");case"for":return this.hass.localize("ui.panel.config.automation.editor.triggers.type.state.for");default:return this.hass.localize(`ui.panel.config.automation.editor.triggers.type.numeric_state.${e.name}`)}}}}]}}),m);const ai=Ve(It,Ze({alias:et(tt()),platform:He("state"),entity_id:et(at([tt(),Ge(tt())])),attribute:et(tt()),from:et(tt()),to:et(tt()),for:et(at([tt(),St]))}));p([M("ha-automation-trigger-state")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{entity_id:[]}}},{kind:"field",key:"_schema",value:()=>X(((e,t)=>[{name:"entity_id",required:!0,selector:{entity:{multiple:!0}}},{name:"attribute",selector:{attribute:{entity_id:e?e[0]:void 0,hide_attributes:["access_token","available_modes","color_modes","device_class","editable","effect_list","entity_picture","fan_modes","fan_speed_list","friendly_name","has_date","has_time","hvac_modes","icon","operation_list","options","preset_modes","sound_mode_list","source_list","state_class","supported_features","swing_modes","token","unit_of_measurement"]}}},{name:"from",selector:{state:{entity_id:e?e[0]:void 0,attribute:t}}},{name:"to",selector:{state:{entity_id:e?e[0]:void 0,attribute:t}}},{name:"for",selector:{duration:{}}}]))},{kind:"method",key:"shouldUpdate",value:function(e){if(!e.has("trigger"))return!0;if(this.trigger.for&&"object"==typeof this.trigger.for&&0===this.trigger.for.milliseconds&&delete this.trigger.for.milliseconds,this.trigger&&pt(this.trigger))return C(this,"ui-mode-not-available",Error(this.hass.localize("ui.errors.config.no_template_editor_support"))),!1;try{We(this.trigger,ai)}catch(e){return C(this,"ui-mode-not-available",e),!1}return!0}},{kind:"method",key:"render",value:function(){const e=Ft(this.trigger.for),t={...this.trigger,entity_id:_e(this.trigger.entity_id),for:e},i=this._schema(this.trigger.entity_id,this.trigger.attribute);return _`
  1186. <ha-form
  1187. .hass=${this.hass}
  1188. .data=${t}
  1189. .schema=${i}
  1190. @value-changed=${this._valueChanged}
  1191. .computeLabel=${this._computeLabelCallback}
  1192. .disabled=${this.disabled}
  1193. ></ha-form>
  1194. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;Object.keys(t).forEach((e=>void 0===t[e]||""===t[e]?delete t[e]:{})),C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize("entity_id"===e.name?"ui.components.entity.entity-picker.entity":`ui.panel.config.automation.editor.triggers.type.state.${e.name}`)}}]}}),m),p([M("ha-automation-trigger-sun")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_schema",value:()=>X((e=>[{name:"event",type:"select",required:!0,options:[["sunrise",e("ui.panel.config.automation.editor.triggers.type.sun.sunrise")],["sunset",e("ui.panel.config.automation.editor.triggers.type.sun.sunset")]]},{name:"offset",selector:{text:{}}}]))},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{event:"sunrise",offset:0}}},{kind:"method",key:"render",value:function(){const e=this._schema(this.hass.localize);return _`
  1195. <ha-form
  1196. .schema=${e}
  1197. .data=${this.trigger}
  1198. .hass=${this.hass}
  1199. .disabled=${this.disabled}
  1200. .computeLabel=${this._computeLabelCallback}
  1201. @value-changed=${this._valueChanged}
  1202. ></ha-form>
  1203. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.sun.${e.name}`)}}]}}),m);p([M("ha-automation-trigger-tag")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_tags",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{tag_id:""}}},{kind:"method",key:"firstUpdated",value:function(e){x(w(i.prototype),"firstUpdated",this).call(this,e),this._fetchTags()}},{kind:"method",key:"render",value:function(){return this._tags?_`
  1204. <ha-select
  1205. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.tag.label")}
  1206. .disabled=${this.disabled||0===this._tags.length}
  1207. .value=${this.trigger.tag_id}
  1208. @selected=${this._tagChanged}
  1209. >
  1210. ${this._tags.map((e=>_`
  1211. <mwc-list-item .value=${e.id}>
  1212. ${e.name||e.id}
  1213. </mwc-list-item>
  1214. `))}
  1215. </ha-select>
  1216. `:_``}},{kind:"method",key:"_fetchTags",value:async function(){this._tags=(await(async e=>e.callWS({type:"tag/list"}))(this.hass)).sort(((e,t)=>ve(e.name||e.id,t.name||t.id)))}},{kind:"method",key:"_tagChanged",value:function(e){e.target.value&&this._tags&&this.trigger.tag_id!==e.target.value&&C(this,"value-changed",{value:{...this.trigger,tag_id:e.target.value}})}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1217. ha-select {
  1218. display: block;
  1219. }
  1220. `}}]}}),m),p([M("ha-automation-trigger-template")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{value_template:""}}},{kind:"method",key:"render",value:function(){const{value_template:e}=this.trigger;return _`
  1221. <p>
  1222. ${this.hass.localize("ui.panel.config.automation.editor.triggers.type.template.value_template")}
  1223. *
  1224. </p>
  1225. <ha-code-editor
  1226. .name=${"value_template"}
  1227. mode="jinja2"
  1228. .hass=${this.hass}
  1229. .value=${e}
  1230. .readOnly=${this.disabled}
  1231. autocomplete-entities
  1232. @value-changed=${this._valueChanged}
  1233. dir="ltr"
  1234. ></ha-code-editor>
  1235. `}},{kind:"method",key:"_valueChanged",value:function(e){di(this,e)}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1236. p {
  1237. margin-top: 0;
  1238. }
  1239. `}}]}}),m),p([M("ha-automation-trigger-time")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_inputMode",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{at:""}}},{kind:"field",key:"_schema",value:()=>X(((e,t)=>{const i=t?{entity:{domain:"input_datetime"}}:{time:{}};return[{name:"mode",type:"select",required:!0,options:[["value",e("ui.panel.config.automation.editor.triggers.type.time.type_value")],["input",e("ui.panel.config.automation.editor.triggers.type.time.type_input")]]},{name:"at",selector:i}]}))},{kind:"method",key:"willUpdate",value:function(e){e.has("trigger")&&this.trigger&&Array.isArray(this.trigger.at)&&C(this,"ui-mode-not-available",Error(this.hass.localize("ui.errors.config.editor_not_supported")))}},{kind:"method",key:"render",value:function(){var e;const t=this.trigger.at;if(Array.isArray(t))return _``;const i=null!==(e=this._inputMode)&&void 0!==e?e:(null==t?void 0:t.startsWith("input_datetime."))||(null==t?void 0:t.startsWith("sensor.")),a=this._schema(this.hass.localize,i),o={mode:i?"input":"value",...this.trigger};return _`
  1240. <ha-form
  1241. .hass=${this.hass}
  1242. .data=${o}
  1243. .schema=${a}
  1244. .disabled=${this.disabled}
  1245. @value-changed=${this._valueChanged}
  1246. .computeLabel=${this._computeLabelCallback}
  1247. ></ha-form>
  1248. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;this._inputMode="input"===t.mode,delete t.mode,Object.keys(t).forEach((e=>void 0===t[e]||""===t[e]?delete t[e]:{})),C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.time.${e.name}`)}}]}}),m);const oi=[{name:"hours",selector:{text:{}}},{name:"minutes",selector:{text:{}}},{name:"seconds",selector:{text:{}}}];p([M("ha-automation-trigger-time_pattern")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{}}},{kind:"method",key:"render",value:function(){return _`
  1249. <ha-form
  1250. .hass=${this.hass}
  1251. .schema=${oi}
  1252. .data=${this.trigger}
  1253. .disabled=${this.disabled}
  1254. .computeLabel=${this._computeLabelCallback}
  1255. @value-changed=${this._valueChanged}
  1256. ></ha-form>
  1257. `}},{kind:"method",key:"_valueChanged",value:function(e){e.stopPropagation();const t=e.detail.value;C(this,"value-changed",{value:t})}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.triggers.type.time_pattern.${e.name}`)}}]}}),m);function ni(e){return Bt(e)&&"zone"!==Pe(e)}p([M("ha-automation-trigger-webhook")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_config",value:void 0},{kind:"field",key:"_unsub",value:void 0},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{webhook_id:""}}},{kind:"method",key:"connectedCallback",value:function(){x(w(i.prototype),"connectedCallback",this).call(this);const e={callback:e=>{this._config=e}};C(this,"subscribe-automation-config",e),this._unsub=e.unsub}},{kind:"method",key:"disconnectedCallback",value:function(){x(w(i.prototype),"disconnectedCallback",this).call(this),this._unsub&&this._unsub()}},{kind:"method",key:"_generateWebhookId",value:function(){var e;const t=crypto.getRandomValues(new Uint8Array(18)),i=btoa(String.fromCharCode(...t)).replace(/\+/g,"-").replace(/\//g,"_"),a=((e,t="_")=>{const i="àáäâãåăæąçćčđďèéěėëêęğǵḧìíïîįłḿǹńňñòóöôœøṕŕřßşśšșťțùúüûǘůűūųẃẍÿýźžż·/_,:;",a=`aaaaaaaaacccddeeeeeeegghiiiiilmnnnnooooooprrsssssttuuuuuuuuuwxyyzzz${t}${t}${t}${t}${t}${t}`,o=new RegExp(i.split("").join("|"),"g");return e.toString().toLowerCase().replace(/\s+/g,t).replace(o,(e=>a.charAt(i.indexOf(e)))).replace(/&/g,`${t}and${t}`).replace(/[^\w-]+/g,"").replace(/-/g,t).replace(new RegExp(`(${t})\\1+`,"g"),"$1").replace(new RegExp(`^${t}+`),"").replace(new RegExp(`${t}+$`),"")})((null===(e=this._config)||void 0===e?void 0:e.alias)||"","-");return`${a}-${i}`}},{kind:"method",key:"willUpdate",value:function(e){x(w(i.prototype),"willUpdate",this).call(this,e),e.has("trigger")&&""===this.trigger.webhook_id&&(this.trigger.webhook_id=this._generateWebhookId())}},{kind:"method",key:"render",value:function(){const{webhook_id:e}=this.trigger;return _`
  1258. <ha-textfield
  1259. name="webhook_id"
  1260. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.webhook.webhook_id")}
  1261. .helper=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.webhook.webhook_id_helper")}
  1262. .disabled=${this.disabled}
  1263. iconTrailing
  1264. .value=${e||""}
  1265. @input=${this._valueChanged}
  1266. >
  1267. <ha-icon-button
  1268. @click=${this._copyUrl}
  1269. slot="trailingIcon"
  1270. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.webhook.copy_url")}
  1271. .path=${le}
  1272. ></ha-icon-button>
  1273. </ha-textfield>
  1274. `}},{kind:"method",key:"_valueChanged",value:function(e){di(this,e)}},{kind:"method",key:"_copyUrl",value:async function(e){const t=e.target.parentElement,i=this.hass.hassUrl(`/api/webhook/${t.value}`);await(async e=>{if(navigator.clipboard)try{return void await navigator.clipboard.writeText(e)}catch{}const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)})(i),At(this,{message:this.hass.localize("ui.common.copied_clipboard")})}},{kind:"field",static:!0,key:"styles",value:()=>g`
  1275. ha-textfield {
  1276. display: block;
  1277. }
  1278. ha-textfield > ha-icon-button {
  1279. --mdc-icon-button-size: 24px;
  1280. --mdc-icon-size: 18px;
  1281. }
  1282. `}]}}),m);const si=["zone"];p([M("ha-automation-trigger-zone")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{entity_id:"",zone:"",event:"enter"}}},{kind:"method",key:"render",value:function(){const{entity_id:e,zone:t,event:i}=this.trigger;return _`
  1283. <ha-entity-picker
  1284. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.zone.entity")}
  1285. .value=${e}
  1286. .disabled=${this.disabled}
  1287. @value-changed=${this._entityPicked}
  1288. .hass=${this.hass}
  1289. allow-custom-entity
  1290. .entityFilter=${ni}
  1291. ></ha-entity-picker>
  1292. <ha-entity-picker
  1293. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.zone.zone")}
  1294. .value=${t}
  1295. .disabled=${this.disabled}
  1296. @value-changed=${this._zonePicked}
  1297. .hass=${this.hass}
  1298. allow-custom-entity
  1299. .includeDomains=${si}
  1300. ></ha-entity-picker>
  1301. <label>
  1302. ${this.hass.localize("ui.panel.config.automation.editor.triggers.type.zone.event")}
  1303. <ha-formfield
  1304. .disabled=${this.disabled}
  1305. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.zone.enter")}
  1306. >
  1307. <ha-radio
  1308. name="event"
  1309. value="enter"
  1310. .disabled=${this.disabled}
  1311. .checked=${"enter"===i}
  1312. @change=${this._radioGroupPicked}
  1313. ></ha-radio>
  1314. </ha-formfield>
  1315. <ha-formfield
  1316. .disabled=${this.disabled}
  1317. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.type.zone.leave")}
  1318. >
  1319. <ha-radio
  1320. name="event"
  1321. value="leave"
  1322. .disabled=${this.disabled}
  1323. .checked=${"leave"===i}
  1324. @change=${this._radioGroupPicked}
  1325. ></ha-radio>
  1326. </ha-formfield>
  1327. </label>
  1328. `}},{kind:"method",key:"_entityPicked",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.trigger,entity_id:e.detail.value}})}},{kind:"method",key:"_zonePicked",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.trigger,zone:e.detail.value}})}},{kind:"method",key:"_radioGroupPicked",value:function(e){e.stopPropagation(),C(this,"value-changed",{value:{...this.trigger,event:e.target.value}})}},{kind:"field",static:!0,key:"styles",value:()=>g`
  1329. label {
  1330. display: flex;
  1331. align-items: center;
  1332. }
  1333. ha-entity-picker {
  1334. display: block;
  1335. margin-bottom: 24px;
  1336. }
  1337. `}]}}),m);const di=(e,t)=>{var i,a;t.stopPropagation();const o=null===(i=t.currentTarget)||void 0===i?void 0:i.name;if(!o)return;const n=null===(a=t.target)||void 0===a?void 0:a.value;if((e.trigger[o]||"")===n)return;let s;void 0===n||""===n?(s={...e.trigger},delete s[o]):s={...e.trigger,[o]:n},C(e,"value-changed",{value:s})},ri=e=>e.preventDefault();p([M("ha-automation-trigger-row")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"trigger",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"hideMenu",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[y()],key:"_warnings",value:void 0},{kind:"field",decorators:[y()],key:"_yamlMode",value:()=>!1},{kind:"field",decorators:[y()],key:"_requestShowId",value:()=>!1},{kind:"field",decorators:[y()],key:"_triggered",value:void 0},{kind:"field",decorators:[y()],key:"_triggerColor",value:()=>!1},{kind:"field",decorators:[k("ha-yaml-editor")],key:"_yamlEditor",value:void 0},{kind:"field",key:"_triggerUnsub",value:void 0},{kind:"method",key:"render",value:function(){const e=void 0!==customElements.get(`ha-automation-trigger-${this.trigger.platform}`),t=this._yamlMode||!e,i="id"in this.trigger||this._requestShowId;return _`
  1338. <ha-card outlined>
  1339. ${!1===this.trigger.enabled?_`
  1340. <div class="disabled-bar">
  1341. ${this.hass.localize("ui.panel.config.automation.editor.actions.disabled")}
  1342. </div>
  1343. `:""}
  1344. <ha-expansion-panel leftChevron>
  1345. <h3 slot="header">
  1346. <ha-svg-icon
  1347. class="trigger-icon"
  1348. .path=${Ht[this.trigger.platform]}
  1349. ></ha-svg-icon>
  1350. ${ye(Ct(this.trigger,this.hass))}
  1351. </h3>
  1352. <slot name="icons" slot="icons"></slot>
  1353. ${this.hideMenu?"":_`
  1354. <ha-button-menu
  1355. slot="icons"
  1356. fixed
  1357. corner="BOTTOM_START"
  1358. @action=${this._handleAction}
  1359. @click=${ri}
  1360. >
  1361. <ha-icon-button
  1362. slot="trigger"
  1363. .label=${this.hass.localize("ui.common.menu")}
  1364. .path=${B}
  1365. ></ha-icon-button>
  1366. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1367. ${this.hass.localize("ui.panel.config.automation.editor.triggers.rename")}
  1368. <ha-svg-icon
  1369. slot="graphic"
  1370. .path=${q}
  1371. ></ha-svg-icon>
  1372. </mwc-list-item>
  1373. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1374. ${this.hass.localize("ui.panel.config.automation.editor.actions.duplicate")}
  1375. <ha-svg-icon
  1376. slot="graphic"
  1377. .path=${W}
  1378. ></ha-svg-icon>
  1379. </mwc-list-item>
  1380. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1381. ${this.hass.localize("ui.panel.config.automation.editor.triggers.edit_id")}
  1382. <ha-svg-icon
  1383. slot="graphic"
  1384. .path=${L}
  1385. ></ha-svg-icon>
  1386. </mwc-list-item>
  1387. <li divider role="separator"></li>
  1388. <mwc-list-item .disabled=${!e} graphic="icon">
  1389. ${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
  1390. ${t?"":_`<ha-svg-icon
  1391. class="selected_menu_item"
  1392. slot="graphic"
  1393. .path=${R}
  1394. ></ha-svg-icon>`}
  1395. </mwc-list-item>
  1396. <mwc-list-item .disabled=${!e} graphic="icon">
  1397. ${this.hass.localize("ui.panel.config.automation.editor.edit_yaml")}
  1398. ${t?_`<ha-svg-icon
  1399. class="selected_menu_item"
  1400. slot="graphic"
  1401. .path=${R}
  1402. ></ha-svg-icon>`:""}
  1403. </mwc-list-item>
  1404. <li divider role="separator"></li>
  1405. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1406. ${!1===this.trigger.enabled?this.hass.localize("ui.panel.config.automation.editor.actions.enable"):this.hass.localize("ui.panel.config.automation.editor.actions.disable")}
  1407. <ha-svg-icon
  1408. slot="graphic"
  1409. .path=${!1===this.trigger.enabled?K:V}
  1410. ></ha-svg-icon>
  1411. </mwc-list-item>
  1412. <mwc-list-item
  1413. class="warning"
  1414. graphic="icon"
  1415. .disabled=${this.disabled}
  1416. >
  1417. ${this.hass.localize("ui.panel.config.automation.editor.actions.delete")}
  1418. <ha-svg-icon
  1419. class="warning"
  1420. slot="graphic"
  1421. .path=${A}
  1422. ></ha-svg-icon>
  1423. </mwc-list-item>
  1424. </ha-button-menu>
  1425. `}
  1426. <div
  1427. class=${$({"card-content":!0,disabled:!1===this.trigger.enabled})}
  1428. >
  1429. ${this._warnings?_`<ha-alert
  1430. alert-type="warning"
  1431. .title=${this.hass.localize("ui.errors.config.editor_not_supported")}
  1432. >
  1433. ${this._warnings.length&&void 0!==this._warnings[0]?_` <ul>
  1434. ${this._warnings.map((e=>_`<li>${e}</li>`))}
  1435. </ul>`:""}
  1436. ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")}
  1437. </ha-alert>`:""}
  1438. ${t?_`
  1439. ${e?"":_`
  1440. ${this.hass.localize("ui.panel.config.automation.editor.triggers.unsupported_platform","platform",this.trigger.platform)}
  1441. `}
  1442. <ha-yaml-editor
  1443. .hass=${this.hass}
  1444. .defaultValue=${this.trigger}
  1445. .readOnly=${this.disabled}
  1446. @value-changed=${this._onYamlChange}
  1447. ></ha-yaml-editor>
  1448. `:_`
  1449. ${i?_`
  1450. <ha-textfield
  1451. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.id")}
  1452. .value=${this.trigger.id||""}
  1453. .disabled=${this.disabled}
  1454. @change=${this._idChanged}
  1455. >
  1456. </ha-textfield>
  1457. `:""}
  1458. <div @ui-mode-not-available=${this._handleUiModeNotAvailable}>
  1459. ${me(`ha-automation-trigger-${this.trigger.platform}`,{hass:this.hass,trigger:this.trigger,disabled:this.disabled})}
  1460. </div>
  1461. `}
  1462. </div>
  1463. </ha-expansion-panel>
  1464. <div
  1465. class="triggered ${$({active:void 0!==this._triggered,accent:this._triggerColor})}"
  1466. @click=${this._showTriggeredInfo}
  1467. >
  1468. ${this.hass.localize("ui.panel.config.automation.editor.triggers.triggered")}
  1469. </div>
  1470. </ha-card>
  1471. `}},{kind:"method",key:"updated",value:function(e){x(w(i.prototype),"updated",this).call(this,e),e.has("trigger")&&this._subscribeTrigger()}},{kind:"method",key:"connectedCallback",value:function(){x(w(i.prototype),"connectedCallback",this).call(this),this.hasUpdated&&this.trigger&&this._subscribeTrigger()}},{kind:"method",key:"disconnectedCallback",value:function(){x(w(i.prototype),"disconnectedCallback",this).call(this),this._triggerUnsub&&(this._triggerUnsub.then((e=>e())),this._triggerUnsub=void 0),this._doSubscribeTrigger.cancel()}},{kind:"method",key:"_subscribeTrigger",value:function(){this._triggerUnsub&&(this._triggerUnsub.then((e=>e())),this._triggerUnsub=void 0),this._doSubscribeTrigger()}},{kind:"field",key:"_doSubscribeTrigger",value(){return Oe((async()=>{let e;const t=this.trigger;this._triggerUnsub&&(this._triggerUnsub.then((e=>e())),this._triggerUnsub=void 0);if(!(await nt(this.hass,{trigger:t})).trigger.valid||this.trigger!==t)return;const i=((e,t,i,a)=>e.connection.subscribeMessage(t,{type:"subscribe_trigger",trigger:i,variables:a}))(this.hass,(t=>{void 0!==e?(clearTimeout(e),this._triggerColor=!this._triggerColor):this._triggerColor=!1,this._triggered=t,e=window.setTimeout((()=>{this._triggered=void 0,e=void 0}),5e3)}),t);i.catch((()=>{this._triggerUnsub===i&&(this._triggerUnsub=void 0)})),this._triggerUnsub=i}),5e3)}},{kind:"method",key:"_handleUiModeNotAvailable",value:function(e){this._warnings=ot(this.hass,e.detail).warnings,this._yamlMode||(this._yamlMode=!0)}},{kind:"method",key:"_handleAction",value:async function(e){switch(e.detail.index){case 0:await this._renameTrigger();break;case 1:C(this,"duplicate");break;case 2:this._requestShowId=!0,this.expand();break;case 3:this._switchUiMode(),this.expand();break;case 4:this._switchYamlMode(),this.expand();break;case 5:this._onDisable();break;case 6:this._onDelete()}}},{kind:"method",key:"_onDelete",value:function(){ze(this,{title:this.hass.localize("ui.panel.config.automation.editor.triggers.delete_confirm_title"),text:this.hass.localize("ui.panel.config.automation.editor.triggers.delete_confirm_text"),dismissText:this.hass.localize("ui.common.cancel"),confirmText:this.hass.localize("ui.common.delete"),destructive:!0,confirm:()=>{C(this,"value-changed",{value:null})}})}},{kind:"method",key:"_onDisable",value:function(){var e;const t=!(null===(e=this.trigger.enabled)||void 0===e||e),i={...this.trigger,enabled:t};var a;(C(this,"value-changed",{value:i}),this._yamlMode)&&(null===(a=this._yamlEditor)||void 0===a||a.setValue(i))}},{kind:"method",key:"_idChanged",value:function(e){var t;const i=e.target.value;if(i===(null!==(t=this.trigger.id)&&void 0!==t?t:""))return;this._requestShowId=!0;const a={...this.trigger};i?a.id=i:delete a.id,C(this,"value-changed",{value:a})}},{kind:"method",key:"_onYamlChange",value:function(e){e.stopPropagation(),e.detail.isValid&&(this._warnings=void 0,C(this,"value-changed",{value:e.detail.value}))}},{kind:"method",key:"_switchUiMode",value:function(){this._warnings=void 0,this._yamlMode=!1}},{kind:"method",key:"_switchYamlMode",value:function(){this._warnings=void 0,this._yamlMode=!0}},{kind:"method",key:"_showTriggeredInfo",value:function(){Me(this,{text:_`
  1472. <ha-yaml-editor
  1473. readOnly
  1474. .hass=${this.hass}
  1475. .defaultValue=${this._triggered}
  1476. ></ha-yaml-editor>
  1477. `})}},{kind:"method",key:"_renameTrigger",value:async function(){const e=await Ae(this,{title:this.hass.localize("ui.panel.config.automation.editor.triggers.change_alias"),inputLabel:this.hass.localize("ui.panel.config.automation.editor.triggers.alias"),inputType:"string",placeholder:ye(Ct(this.trigger,this.hass,!0)),defaultValue:this.trigger.alias,confirmText:this.hass.localize("ui.common.submit")}),t={...this.trigger};var i;(e?t.alias=e:delete t.alias,C(this,"value-changed",{value:t}),this._yamlMode)&&(null===(i=this._yamlEditor)||void 0===i||i.setValue(t))}},{kind:"method",key:"expand",value:function(){this.updateComplete.then((()=>{this.shadowRoot.querySelector("ha-expansion-panel").expanded=!0}))}},{kind:"get",static:!0,key:"styles",value:function(){return[T,g`
  1478. ha-button-menu {
  1479. --mdc-theme-text-primary-on-background: var(--primary-text-color);
  1480. }
  1481. .disabled {
  1482. opacity: 0.5;
  1483. pointer-events: none;
  1484. }
  1485. ha-expansion-panel {
  1486. --expansion-panel-summary-padding: 0 0 0 8px;
  1487. --expansion-panel-content-padding: 0;
  1488. }
  1489. h3 {
  1490. margin: 0;
  1491. font-size: inherit;
  1492. font-weight: inherit;
  1493. }
  1494. .trigger-icon {
  1495. display: none;
  1496. }
  1497. @media (min-width: 870px) {
  1498. .trigger-icon {
  1499. display: inline-block;
  1500. color: var(--secondary-text-color);
  1501. opacity: 0.9;
  1502. margin-right: 8px;
  1503. }
  1504. }
  1505. .card-content {
  1506. padding: 16px;
  1507. }
  1508. .disabled-bar {
  1509. background: var(--divider-color, #e0e0e0);
  1510. text-align: center;
  1511. border-top-right-radius: var(--ha-card-border-radius);
  1512. border-top-left-radius: var(--ha-card-border-radius);
  1513. }
  1514. .triggered {
  1515. cursor: pointer;
  1516. position: absolute;
  1517. top: 0px;
  1518. right: 0px;
  1519. left: 0px;
  1520. text-transform: uppercase;
  1521. font-weight: bold;
  1522. font-size: 14px;
  1523. background-color: var(--primary-color);
  1524. color: var(--text-primary-color);
  1525. max-height: 0px;
  1526. overflow: hidden;
  1527. transition: max-height 0.3s;
  1528. text-align: center;
  1529. border-top-right-radius: var(--ha-card-border-radius, 16px);
  1530. border-top-left-radius: var(--ha-card-border-radius, 16px);
  1531. }
  1532. .triggered.active {
  1533. max-height: 100px;
  1534. }
  1535. .triggered:hover {
  1536. opacity: 0.8;
  1537. }
  1538. .triggered.accent {
  1539. background-color: var(--accent-color);
  1540. color: var(--text-accent-color, var(--text-primary-color));
  1541. }
  1542. mwc-list-item[disabled] {
  1543. --mdc-theme-text-primary-on-background: var(--disabled-text-color);
  1544. }
  1545. ha-textfield {
  1546. display: block;
  1547. margin-bottom: 24px;
  1548. }
  1549. .selected_menu_item {
  1550. color: var(--primary-color);
  1551. }
  1552. li[role="separator"] {
  1553. border-bottom-color: var(--divider-color);
  1554. }
  1555. `]}}]}}),m),p([M("ha-automation-trigger")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"triggers",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",key:"_focusLastTriggerOnChange",value:()=>!1},{kind:"field",key:"_triggerKeys",value:()=>new WeakMap},{kind:"field",key:"_sortable",value:void 0},{kind:"method",key:"render",value:function(){return _`
  1556. <div class="triggers">
  1557. ${ue(this.triggers,(e=>this._getKey(e)),((e,t)=>_`
  1558. <ha-automation-trigger-row
  1559. .index=${t}
  1560. .trigger=${e}
  1561. .hideMenu=${this.reOrderMode}
  1562. @duplicate=${this._duplicateTrigger}
  1563. @value-changed=${this._triggerChanged}
  1564. .hass=${this.hass}
  1565. .disabled=${this.disabled}
  1566. >
  1567. ${this.reOrderMode?_`
  1568. <ha-icon-button
  1569. .index=${t}
  1570. slot="icons"
  1571. .label=${this.hass.localize("ui.panel.config.automation.editor.move_up")}
  1572. .path=${Y}
  1573. @click=${this._moveUp}
  1574. .disabled=${0===t}
  1575. ></ha-icon-button>
  1576. <ha-icon-button
  1577. .index=${t}
  1578. slot="icons"
  1579. .label=${this.hass.localize("ui.panel.config.automation.editor.move_down")}
  1580. .path=${G}
  1581. @click=${this._moveDown}
  1582. .disabled=${t===this.triggers.length-1}
  1583. ></ha-icon-button>
  1584. <div class="handle" slot="icons">
  1585. <ha-svg-icon .path=${J}></ha-svg-icon>
  1586. </div>
  1587. `:""}
  1588. </ha-automation-trigger-row>
  1589. `))}
  1590. </div>
  1591. <ha-button-menu @action=${this._addTrigger} .disabled=${this.disabled}>
  1592. <mwc-button
  1593. slot="trigger"
  1594. outlined
  1595. .label=${this.hass.localize("ui.panel.config.automation.editor.triggers.add")}
  1596. .disabled=${this.disabled}
  1597. >
  1598. <ha-svg-icon .path=${O} slot="icon"></ha-svg-icon>
  1599. </mwc-button>
  1600. ${this._processedTypes(this.hass.localize).map((([e,t,i])=>_`
  1601. <mwc-list-item .value=${e} aria-label=${t} graphic="icon">
  1602. ${t}<ha-svg-icon slot="graphic" .path=${i}></ha-svg-icon
  1603. ></mwc-list-item>
  1604. `))}
  1605. </ha-button-menu>
  1606. </div>
  1607. `}},{kind:"method",key:"updated",value:function(e){if(x(w(i.prototype),"updated",this).call(this,e),e.has("reOrderMode")&&(this.reOrderMode?this._createSortable():this._destroySortable()),e.has("triggers")&&this._focusLastTriggerOnChange){this._focusLastTriggerOnChange=!1;const e=this.shadowRoot.querySelector("ha-automation-trigger-row:last-of-type");e.updateComplete.then((()=>{e.expand(),e.scrollIntoView(),e.focus()}))}}},{kind:"method",key:"_createSortable",value:async function(){const e=await Fe();this._sortable=new e(this.shadowRoot.querySelector(".triggers"),{animation:150,fallbackClass:"sortable-fallback",handle:".handle",onChoose:e=>{e.item.placeholder=document.createComment("sort-placeholder"),e.item.after(e.item.placeholder)},onEnd:e=>{e.item.placeholder&&(e.item.placeholder.replaceWith(e.item),delete e.item.placeholder),this._dragged(e)}})}},{kind:"method",key:"_destroySortable",value:function(){var e;null===(e=this._sortable)||void 0===e||e.destroy(),this._sortable=void 0}},{kind:"method",key:"_getKey",value:function(e){return this._triggerKeys.has(e)||this._triggerKeys.set(e,Math.random().toString()),this._triggerKeys.get(e)}},{kind:"method",key:"_addTrigger",value:function(e){const t=e.currentTarget.items[e.detail.index].value,i=customElements.get(`ha-automation-trigger-${t}`),a=this.triggers.concat({platform:t,...i.defaultConfig});this._focusLastTriggerOnChange=!0,C(this,"value-changed",{value:a})}},{kind:"method",key:"_moveUp",value:function(e){const t=e.target.index,i=t-1;this._move(t,i)}},{kind:"method",key:"_moveDown",value:function(e){const t=e.target.index,i=t+1;this._move(t,i)}},{kind:"method",key:"_dragged",value:function(e){e.oldIndex!==e.newIndex&&this._move(e.oldIndex,e.newIndex)}},{kind:"method",key:"_move",value:function(e,t){const i=this.triggers.concat(),a=i.splice(e,1)[0];i.splice(t,0,a),C(this,"value-changed",{value:i})}},{kind:"method",key:"_triggerChanged",value:function(e){e.stopPropagation();const t=[...this.triggers],i=e.detail.value,a=e.target.index;if(null===i)t.splice(a,1);else{const e=this._getKey(t[a]);this._triggerKeys.set(i,e),t[a]=i}C(this,"value-changed",{value:t})}},{kind:"method",key:"_duplicateTrigger",value:function(e){e.stopPropagation();const t=e.target.index;C(this,"value-changed",{value:this.triggers.concat(ce(this.triggers[t]))})}},{kind:"field",key:"_processedTypes",value:()=>X((e=>Object.entries(Ht).map((([t,i])=>[t,e(`ui.panel.config.automation.editor.triggers.type.${t}.label`),i])).sort(((e,t)=>he(e[1],t[1])))))},{kind:"get",static:!0,key:"styles",value:function(){return[Ee,g`
  1608. ha-automation-trigger-row {
  1609. display: block;
  1610. margin-bottom: 16px;
  1611. scroll-margin-top: 48px;
  1612. }
  1613. ha-svg-icon {
  1614. height: 20px;
  1615. }
  1616. .handle {
  1617. cursor: move;
  1618. padding: 12px;
  1619. }
  1620. .handle ha-svg-icon {
  1621. pointer-events: none;
  1622. height: 24px;
  1623. }
  1624. `]}}]}}),m),p([M("ha-automation-action-wait_for_trigger")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{wait_for_trigger:[]}}},{kind:"method",key:"render",value:function(){var e;const t=Ft(this.action.timeout);return _`
  1625. <ha-duration-input
  1626. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.wait_for_trigger.timeout")}
  1627. .data=${t}
  1628. .disabled=${this.disabled}
  1629. enableMillisecond
  1630. @value-changed=${this._timeoutChanged}
  1631. ></ha-duration-input>
  1632. <ha-formfield
  1633. .disabled=${this.disabled}
  1634. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.type.wait_for_trigger.continue_timeout")}
  1635. >
  1636. <ha-switch
  1637. .checked=${null===(e=this.action.continue_on_timeout)||void 0===e||e}
  1638. .disabled=${this.disabled}
  1639. @change=${this._continueChanged}
  1640. ></ha-switch>
  1641. </ha-formfield>
  1642. <ha-automation-trigger
  1643. .triggers=${_e(this.action.wait_for_trigger)}
  1644. .hass=${this.hass}
  1645. .disabled=${this.disabled}
  1646. .name=${"wait_for_trigger"}
  1647. @value-changed=${this._valueChanged}
  1648. ></ha-automation-trigger>
  1649. `}},{kind:"method",key:"_timeoutChanged",value:function(e){e.stopPropagation();const t=e.detail.value;t&&C(this,"value-changed",{value:{...this.action,timeout:t}})}},{kind:"method",key:"_continueChanged",value:function(e){C(this,"value-changed",{value:{...this.action,continue_on_timeout:e.target.checked}})}},{kind:"method",key:"_valueChanged",value:function(e){ui(this,e)}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1650. ha-duration-input {
  1651. display: block;
  1652. margin-bottom: 24px;
  1653. }
  1654. ha-automation-trigger {
  1655. display: block;
  1656. margin-top: 24px;
  1657. }
  1658. `}}]}}),m);const li=[{name:"wait_template",selector:{template:{}}},{name:"timeout",required:!1,selector:{text:{}}},{name:"continue_on_timeout",selector:{boolean:{}}}];p([M("ha-automation-action-wait_template")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({attribute:!1})],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"get",static:!0,key:"defaultConfig",value:function(){return{wait_template:"",continue_on_timeout:!0}}},{kind:"method",key:"render",value:function(){return _`
  1659. <ha-form
  1660. .hass=${this.hass}
  1661. .data=${this.action}
  1662. .schema=${li}
  1663. .disabled=${this.disabled}
  1664. .computeLabel=${this._computeLabelCallback}
  1665. ></ha-form>
  1666. `}},{kind:"field",key:"_computeLabelCallback",value(){return e=>this.hass.localize(`ui.panel.config.automation.editor.actions.type.wait_template.${"continue_on_timeout"===e.name?"continue_timeout":e.name}`)}}]}}),m);const ci=e=>{if(e)return"service"in e||"scene"in e?ct(e):["and","or","not"].some((t=>t in e))?"condition":Object.keys(Ue).find((t=>t in e))},ui=(e,t)=>{var i,a;t.stopPropagation();const o=null===(i=t.target)||void 0===i?void 0:i.name;if(!o)return;const n=(null===(a=t.detail)||void 0===a?void 0:a.value)||t.target.value;if((e.action[o]||"")===n)return;let s;n?s={...e.action,[o]:n}:(s={...e.action},delete s[o]),C(e,"value-changed",{value:s})},hi=e=>e.preventDefault();p([M("ha-automation-action-row")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"action",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"narrow",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"hideMenu",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",decorators:[y()],key:"_warnings",value:void 0},{kind:"field",decorators:[y()],key:"_uiModeAvailable",value:()=>!0},{kind:"field",decorators:[y()],key:"_yamlMode",value:()=>!1},{kind:"field",decorators:[k("ha-yaml-editor")],key:"_yamlEditor",value:void 0},{kind:"method",key:"willUpdate",value:function(e){e.has("action")&&(this._uiModeAvailable=void 0!==ci(this.action),this._uiModeAvailable||this._yamlMode||(this._yamlMode=!0))}},{kind:"method",key:"updated",value:function(e){if(e.has("action")&&this._yamlMode){const e=this._yamlEditor;e&&e.value!==this.action&&e.setValue(this.action)}}},{kind:"method",key:"render",value:function(){const e=ci(this.action),t=this._yamlMode;return _`
  1667. <ha-card outlined>
  1668. ${!1===this.action.enabled?_`<div class="disabled-bar">
  1669. ${this.hass.localize("ui.panel.config.automation.editor.actions.disabled")}
  1670. </div>`:""}
  1671. <ha-expansion-panel leftChevron>
  1672. <h3 slot="header">
  1673. <ha-svg-icon
  1674. class="action-icon"
  1675. .path=${Ue[e]}
  1676. ></ha-svg-icon>
  1677. ${ye(Mt(this.hass,this.action))}
  1678. </h3>
  1679. <slot name="icons" slot="icons"></slot>
  1680. ${this.hideMenu?"":_`
  1681. <ha-button-menu
  1682. slot="icons"
  1683. fixed
  1684. corner="BOTTOM_START"
  1685. @action=${this._handleAction}
  1686. @click=${hi}
  1687. >
  1688. <ha-icon-button
  1689. slot="trigger"
  1690. .label=${this.hass.localize("ui.common.menu")}
  1691. .path=${B}
  1692. ></ha-icon-button>
  1693. <mwc-list-item graphic="icon">
  1694. ${this.hass.localize("ui.panel.config.automation.editor.actions.run")}
  1695. <ha-svg-icon slot="graphic" .path=${a}></ha-svg-icon>
  1696. </mwc-list-item>
  1697. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1698. ${this.hass.localize("ui.panel.config.automation.editor.actions.rename")}
  1699. <ha-svg-icon
  1700. slot="graphic"
  1701. .path=${q}
  1702. ></ha-svg-icon>
  1703. </mwc-list-item>
  1704. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1705. ${this.hass.localize("ui.panel.config.automation.editor.actions.duplicate")}
  1706. <ha-svg-icon
  1707. slot="graphic"
  1708. .path=${W}
  1709. ></ha-svg-icon>
  1710. </mwc-list-item>
  1711. <li divider role="separator"></li>
  1712. <mwc-list-item
  1713. .disabled=${!this._uiModeAvailable}
  1714. graphic="icon"
  1715. >
  1716. ${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
  1717. ${t?"":_`<ha-svg-icon
  1718. class="selected_menu_item"
  1719. slot="graphic"
  1720. .path=${R}
  1721. ></ha-svg-icon>`}
  1722. </mwc-list-item>
  1723. <mwc-list-item
  1724. .disabled=${!this._uiModeAvailable}
  1725. graphic="icon"
  1726. >
  1727. ${this.hass.localize("ui.panel.config.automation.editor.edit_yaml")}
  1728. ${t?_`<ha-svg-icon
  1729. class="selected_menu_item"
  1730. slot="graphic"
  1731. .path=${R}
  1732. ></ha-svg-icon>`:""}
  1733. </mwc-list-item>
  1734. <li divider role="separator"></li>
  1735. <mwc-list-item graphic="icon" .disabled=${this.disabled}>
  1736. ${!1===this.action.enabled?this.hass.localize("ui.panel.config.automation.editor.actions.enable"):this.hass.localize("ui.panel.config.automation.editor.actions.disable")}
  1737. <ha-svg-icon
  1738. slot="graphic"
  1739. .path=${!1===this.action.enabled?K:V}
  1740. ></ha-svg-icon>
  1741. </mwc-list-item>
  1742. <mwc-list-item
  1743. class="warning"
  1744. graphic="icon"
  1745. .disabled=${this.disabled}
  1746. >
  1747. ${this.hass.localize("ui.panel.config.automation.editor.actions.delete")}
  1748. <ha-svg-icon
  1749. class="warning"
  1750. slot="graphic"
  1751. .path=${A}
  1752. ></ha-svg-icon>
  1753. </mwc-list-item>
  1754. </ha-button-menu>
  1755. `}
  1756. <div
  1757. class=${$({"card-content":!0,disabled:!1===this.action.enabled})}
  1758. >
  1759. ${this._warnings?_`<ha-alert
  1760. alert-type="warning"
  1761. .title=${this.hass.localize("ui.errors.config.editor_not_supported")}
  1762. >
  1763. ${this._warnings.length>0&&void 0!==this._warnings[0]?_` <ul>
  1764. ${this._warnings.map((e=>_`<li>${e}</li>`))}
  1765. </ul>`:""}
  1766. ${this.hass.localize("ui.errors.config.edit_in_yaml_supported")}
  1767. </ha-alert>`:""}
  1768. ${t?_`
  1769. ${void 0===e?_`
  1770. ${this.hass.localize("ui.panel.config.automation.editor.actions.unsupported_action","action",e)}
  1771. `:""}
  1772. <ha-yaml-editor
  1773. .hass=${this.hass}
  1774. .defaultValue=${this.action}
  1775. .readOnly=${this.disabled}
  1776. @value-changed=${this._onYamlChange}
  1777. ></ha-yaml-editor>
  1778. `:_`
  1779. <div @ui-mode-not-available=${this._handleUiModeNotAvailable}>
  1780. ${me(`ha-automation-action-${e}`,{hass:this.hass,action:this.action,narrow:this.narrow,reOrderMode:this.reOrderMode,disabled:this.disabled})}
  1781. </div>
  1782. `}
  1783. </div>
  1784. </ha-expansion-panel>
  1785. </ha-card>
  1786. `}},{kind:"method",key:"_handleUiModeNotAvailable",value:function(e){e.stopPropagation(),this._warnings=ot(this.hass,e.detail).warnings,this._yamlMode||(this._yamlMode=!0)}},{kind:"method",key:"_handleAction",value:async function(e){switch(e.detail.index){case 0:this._runAction();break;case 1:await this._renameAction();break;case 2:C(this,"duplicate");break;case 3:this._switchUiMode(),this.expand();break;case 4:this._switchYamlMode(),this.expand();break;case 5:this._onDisable();break;case 6:this._onDelete()}}},{kind:"method",key:"_onDisable",value:function(){var e;const t=!(null===(e=this.action.enabled)||void 0===e||e),i={...this.action,enabled:t};var a;(C(this,"value-changed",{value:i}),this._yamlMode)&&(null===(a=this._yamlEditor)||void 0===a||a.setValue(i))}},{kind:"method",key:"_runAction",value:async function(){const e=await nt(this.hass,{action:this.action});if(e.action.valid){try{await(t=this.hass,i=this.action,t.callWS({type:"execute_script",sequence:i}))}catch(e){return void Me(this,{title:this.hass.localize("ui.panel.config.automation.editor.actions.run_action_error"),text:e.message||e})}var t,i;At(this,{message:this.hass.localize("ui.panel.config.automation.editor.actions.run_action_success")})}else Me(this,{title:this.hass.localize("ui.panel.config.automation.editor.actions.invalid_action"),text:e.action.error})}},{kind:"method",key:"_onDelete",value:function(){ze(this,{title:this.hass.localize("ui.panel.config.automation.editor.actions.delete_confirm_title"),text:this.hass.localize("ui.panel.config.automation.editor.actions.delete_confirm_text"),dismissText:this.hass.localize("ui.common.cancel"),confirmText:this.hass.localize("ui.common.delete"),destructive:!0,confirm:()=>{C(this,"value-changed",{value:null})}})}},{kind:"method",key:"_onYamlChange",value:function(e){e.stopPropagation(),e.detail.isValid&&C(this,"value-changed",{value:e.detail.value})}},{kind:"method",key:"_switchUiMode",value:function(){this._warnings=void 0,this._yamlMode=!1}},{kind:"method",key:"_switchYamlMode",value:function(){this._warnings=void 0,this._yamlMode=!0}},{kind:"method",key:"_renameAction",value:async function(){const e=await Ae(this,{title:this.hass.localize("ui.panel.config.automation.editor.actions.change_alias"),inputLabel:this.hass.localize("ui.panel.config.automation.editor.actions.alias"),inputType:"string",placeholder:ye(Mt(this.hass,this.action,void 0,!0)),defaultValue:this.action.alias,confirmText:this.hass.localize("ui.common.submit")}),t={...this.action};var i;(e?t.alias=e:delete t.alias,C(this,"value-changed",{value:t}),this._yamlMode)&&(null===(i=this._yamlEditor)||void 0===i||i.setValue(t))}},{kind:"method",key:"expand",value:function(){this.updateComplete.then((()=>{this.shadowRoot.querySelector("ha-expansion-panel").expanded=!0}))}},{kind:"get",static:!0,key:"styles",value:function(){return[T,g`
  1787. ha-button-menu,
  1788. ha-icon-button {
  1789. --mdc-theme-text-primary-on-background: var(--primary-text-color);
  1790. }
  1791. .disabled {
  1792. opacity: 0.5;
  1793. pointer-events: none;
  1794. }
  1795. ha-expansion-panel {
  1796. --expansion-panel-summary-padding: 0 0 0 8px;
  1797. --expansion-panel-content-padding: 0;
  1798. }
  1799. h3 {
  1800. margin: 0;
  1801. font-size: inherit;
  1802. font-weight: inherit;
  1803. }
  1804. .action-icon {
  1805. display: none;
  1806. }
  1807. @media (min-width: 870px) {
  1808. .action-icon {
  1809. display: inline-block;
  1810. color: var(--secondary-text-color);
  1811. opacity: 0.9;
  1812. margin-right: 8px;
  1813. }
  1814. }
  1815. .card-content {
  1816. padding: 16px;
  1817. }
  1818. .disabled-bar {
  1819. background: var(--divider-color, #e0e0e0);
  1820. text-align: center;
  1821. border-top-right-radius: var(--ha-card-border-radius);
  1822. border-top-left-radius: var(--ha-card-border-radius);
  1823. }
  1824. mwc-list-item[disabled] {
  1825. --mdc-theme-text-primary-on-background: var(--disabled-text-color);
  1826. }
  1827. .warning ul {
  1828. margin: 4px 0;
  1829. }
  1830. .selected_menu_item {
  1831. color: var(--primary-color);
  1832. }
  1833. li[role="separator"] {
  1834. border-bottom-color: var(--divider-color);
  1835. }
  1836. `]}}]}}),m),p([M("ha-automation-action")],(function(e,t){class i extends t{constructor(...t){super(...t),e(this)}}return{F:i,d:[{kind:"field",decorators:[f({attribute:!1})],key:"hass",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"narrow",value:()=>!1},{kind:"field",decorators:[f({type:Boolean})],key:"disabled",value:()=>!1},{kind:"field",decorators:[f()],key:"actions",value:void 0},{kind:"field",decorators:[f({type:Boolean})],key:"reOrderMode",value:()=>!1},{kind:"field",key:"_focusLastActionOnChange",value:()=>!1},{kind:"field",key:"_actionKeys",value:()=>new WeakMap},{kind:"field",key:"_sortable",value:void 0},{kind:"method",key:"render",value:function(){return _`
  1837. <div class="actions">
  1838. ${ue(this.actions,(e=>this._getKey(e)),((e,t)=>_`
  1839. <ha-automation-action-row
  1840. .index=${t}
  1841. .action=${e}
  1842. .narrow=${this.narrow}
  1843. .disabled=${this.disabled}
  1844. .hideMenu=${this.reOrderMode}
  1845. .reOrderMode=${this.reOrderMode}
  1846. @duplicate=${this._duplicateAction}
  1847. @value-changed=${this._actionChanged}
  1848. .hass=${this.hass}
  1849. >
  1850. ${this.reOrderMode?_`
  1851. <ha-icon-button
  1852. .index=${t}
  1853. slot="icons"
  1854. .label=${this.hass.localize("ui.panel.config.automation.editor.move_up")}
  1855. .path=${Y}
  1856. @click=${this._moveUp}
  1857. .disabled=${0===t}
  1858. ></ha-icon-button>
  1859. <ha-icon-button
  1860. .index=${t}
  1861. slot="icons"
  1862. .label=${this.hass.localize("ui.panel.config.automation.editor.move_down")}
  1863. .path=${G}
  1864. @click=${this._moveDown}
  1865. .disabled=${t===this.actions.length-1}
  1866. ></ha-icon-button>
  1867. <div class="handle" slot="icons">
  1868. <ha-svg-icon .path=${J}></ha-svg-icon>
  1869. </div>
  1870. `:""}
  1871. </ha-automation-action-row>
  1872. `))}
  1873. </div>
  1874. <ha-button-menu
  1875. fixed
  1876. @action=${this._addAction}
  1877. .disabled=${this.disabled}
  1878. >
  1879. <mwc-button
  1880. slot="trigger"
  1881. outlined
  1882. .disabled=${this.disabled}
  1883. .label=${this.hass.localize("ui.panel.config.automation.editor.actions.add")}
  1884. >
  1885. <ha-svg-icon .path=${O} slot="icon"></ha-svg-icon>
  1886. </mwc-button>
  1887. ${this._processedTypes(this.hass.localize).map((([e,t,i])=>_`
  1888. <mwc-list-item .value=${e} aria-label=${t} graphic="icon">
  1889. ${t}<ha-svg-icon slot="graphic" .path=${i}></ha-svg-icon
  1890. ></mwc-list-item>
  1891. `))}
  1892. </ha-button-menu>
  1893. `}},{kind:"method",key:"updated",value:function(e){if(x(w(i.prototype),"updated",this).call(this,e),e.has("reOrderMode")&&(this.reOrderMode?this._createSortable():this._destroySortable()),e.has("actions")&&this._focusLastActionOnChange){this._focusLastActionOnChange=!1;const e=this.shadowRoot.querySelector("ha-automation-action-row:last-of-type");e.updateComplete.then((()=>{e.expand(),e.scrollIntoView(),e.focus()}))}}},{kind:"method",key:"_createSortable",value:async function(){const e=await Fe();this._sortable=new e(this.shadowRoot.querySelector(".actions"),{animation:150,fallbackClass:"sortable-fallback",handle:".handle",onChoose:e=>{e.item.placeholder=document.createComment("sort-placeholder"),e.item.after(e.item.placeholder)},onEnd:e=>{e.item.placeholder&&(e.item.placeholder.replaceWith(e.item),delete e.item.placeholder),this._dragged(e)}})}},{kind:"method",key:"_destroySortable",value:function(){var e;null===(e=this._sortable)||void 0===e||e.destroy(),this._sortable=void 0}},{kind:"method",key:"_getKey",value:function(e){return this._actionKeys.has(e)||this._actionKeys.set(e,Math.random().toString()),this._actionKeys.get(e)}},{kind:"method",key:"_addAction",value:function(e){const t=e.currentTarget.items[e.detail.index].value,i=customElements.get(`ha-automation-action-${t}`),a=this.actions.concat({...i.defaultConfig});this._focusLastActionOnChange=!0,C(this,"value-changed",{value:a})}},{kind:"method",key:"_moveUp",value:function(e){const t=e.target.index,i=t-1;this._move(t,i)}},{kind:"method",key:"_moveDown",value:function(e){const t=e.target.index,i=t+1;this._move(t,i)}},{kind:"method",key:"_dragged",value:function(e){e.oldIndex!==e.newIndex&&this._move(e.oldIndex,e.newIndex)}},{kind:"method",key:"_move",value:function(e,t){const i=this.actions.concat(),a=i.splice(e,1)[0];i.splice(t,0,a),C(this,"value-changed",{value:i})}},{kind:"method",key:"_actionChanged",value:function(e){e.stopPropagation();const t=[...this.actions],i=e.detail.value,a=e.target.index;if(null===i)t.splice(a,1);else{const e=this._getKey(t[a]);this._actionKeys.set(i,e),t[a]=i}C(this,"value-changed",{value:t})}},{kind:"method",key:"_duplicateAction",value:function(e){e.stopPropagation();const t=e.target.index;C(this,"value-changed",{value:this.actions.concat(ce(this.actions[t]))})}},{kind:"field",key:"_processedTypes",value:()=>X((e=>Object.entries(Ue).map((([t,i])=>[t,e(`ui.panel.config.automation.editor.actions.type.${t}.label`),i])).sort(((e,t)=>he(e[1],t[1])))))},{kind:"get",static:!0,key:"styles",value:function(){return[Ee,g`
  1894. ha-automation-action-row {
  1895. display: block;
  1896. margin-bottom: 16px;
  1897. scroll-margin-top: 48px;
  1898. }
  1899. ha-svg-icon {
  1900. height: 20px;
  1901. }
  1902. .handle {
  1903. cursor: move;
  1904. padding: 12px;
  1905. }
  1906. .handle ha-svg-icon {
  1907. pointer-events: none;
  1908. height: 24px;
  1909. }
  1910. `]}}]}}),m);let vi=p([M("ha-selector-action")],(function(e,t){return{F:class extends t{constructor(...t){super(...t),e(this)}},d:[{kind:"field",decorators:[f()],key:"hass",value:void 0},{kind:"field",decorators:[f()],key:"selector",value:void 0},{kind:"field",decorators:[f()],key:"value",value:void 0},{kind:"field",decorators:[f()],key:"label",value:void 0},{kind:"field",decorators:[f({type:Boolean,reflect:!0})],key:"disabled",value:()=>!1},{kind:"method",key:"render",value:function(){return _`<ha-automation-action
  1911. .disabled=${this.disabled}
  1912. .actions=${this.value||[]}
  1913. .hass=${this.hass}
  1914. ></ha-automation-action>`}},{kind:"get",static:!0,key:"styles",value:function(){return g`
  1915. ha-automation-action {
  1916. display: block;
  1917. margin-bottom: 16px;
  1918. }
  1919. :host([disabled]) ha-automation-action {
  1920. opacity: var(--light-disabled-opacity);
  1921. pointer-events: none;
  1922. }
  1923. `}}]}}),m);export{vi as HaActionSelector};