From 22be28029fffb78e6062df33a5cdb9c452a88ce0 Mon Sep 17 00:00:00 2001 From: niels Date: Tue, 1 Sep 2020 20:43:09 +0200 Subject: [PATCH] updated translations, add sorting --- dist/scheduler-card.js | 102 ++++++++++++++++----------------- src/config-parser.ts | 17 ++++-- src/helpers.ts | 1 - src/localize/languages/en.json | 4 +- src/localize/languages/nl.json | 4 +- src/scheduler-card.ts | 28 ++++----- src/types.ts | 1 + 7 files changed, 85 insertions(+), 72 deletions(-) diff --git a/dist/scheduler-card.js b/dist/scheduler-card.js index 5641a1a3..9f482dea 100644 --- a/dist/scheduler-card.js +++ b/dist/scheduler-card.js @@ -66,7 +66,7 @@ class b{constructor(t,e,i){this.__parts=[],this.template=t,this.processor=e,this * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */const _=window.trustedTypes&&trustedTypes.createPolicy("lit-html",{createHTML:t=>t}),w=` ${r} `;class j{constructor(t,e,i,n){this.strings=t,this.values=e,this.type=i,this.processor=n}getHTML(){const t=this.strings.length-1;let e="",i=!1;for(let n=0;n-1||i)&&-1===t.indexOf("--\x3e",o+1);const a=l.exec(t);e+=null===a?t+(i?w:s):t.substr(0,a.index)+a[1]+a[2]+"$lit$"+a[3]+r}return e+=this.strings[t],e}getTemplateElement(){const t=document.createElement("template");let e=this.getHTML();return void 0!==_&&(e=_.createHTML(e)),t.innerHTML=e,t}} + */const _=window.trustedTypes&&trustedTypes.createPolicy("lit-html",{createHTML:t=>t}),w=` ${r} `;class x{constructor(t,e,i,n){this.strings=t,this.values=e,this.type=i,this.processor=n}getHTML(){const t=this.strings.length-1;let e="",i=!1;for(let n=0;n-1||i)&&-1===t.indexOf("--\x3e",o+1);const a=l.exec(t);e+=null===a?t+(i?w:s):t.substr(0,a.index)+a[1]+a[2]+"$lit$"+a[3]+r}return e+=this.strings[t],e}getTemplateElement(){const t=document.createElement("template");let e=this.getHTML();return void 0!==_&&(e=_.createHTML(e)),t.innerHTML=e,t}} /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -79,7 +79,7 @@ class b{constructor(t,e,i){this.__parts=[],this.template=t,this.processor=e,this * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */const x=t=>null===t||!("object"==typeof t||"function"==typeof t),S=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class ${constructor(t,e,i){this.dirty=!0,this.element=t,this.name=e,this.strings=i,this.parts=[];for(let t=0;t{try{const t={get capture(){return P=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})();class N{constructor(t,e,i){this.value=void 0,this.__pendingValue=void 0,this.element=t,this.eventName=e,this.eventContext=i,this.__boundHandleEvent=t=>this.handleEvent(t)}setValue(t){this.__pendingValue=t}commit(){for(;m(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=y,t(this)}if(this.__pendingValue===y)return;const t=this.__pendingValue,e=this.value,i=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),n=null!=t&&(null==e||i);i&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),n&&(this.__options=T(t),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=t,this.__pendingValue=y}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const T=t=>t&&(P?{capture:t.capture,passive:t.passive,once:t.once}:t.capture) + */const j=t=>null===t||!("object"==typeof t||"function"==typeof t),S=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class ${constructor(t,e,i){this.dirty=!0,this.element=t,this.name=e,this.strings=i,this.parts=[];for(let t=0;t{try{const t={get capture(){return P=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})();class N{constructor(t,e,i){this.value=void 0,this.__pendingValue=void 0,this.element=t,this.eventName=e,this.eventContext=i,this.__boundHandleEvent=t=>this.handleEvent(t)}setValue(t){this.__pendingValue=t}commit(){for(;m(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=y,t(this)}if(this.__pendingValue===y)return;const t=this.__pendingValue,e=this.value,i=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),n=null!=t&&(null==e||i);i&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),n&&(this.__options=T(t),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=t,this.__pendingValue=y}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const T=t=>t&&(P?{capture:t.capture,passive:t.passive,once:t.once}:t.capture) /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -132,7 +132,7 @@ class{handleAttributeExpressions(t,e,i,n){const r=e[0];if("."===r){return new C( * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt - */"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.3.0");const V=(t,...e)=>new j(t,e,"html",U) + */"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.3.0");const V=(t,...e)=>new x(t,e,"html",U) /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -183,7 +183,7 @@ const Z=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?Object * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -(window.litElementVersions||(window.litElementVersions=[])).push("2.4.0");const tt={};class et extends J{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const t=this.getStyles();if(Array.isArray(t)){const e=(t,i)=>t.reduceRight((t,i)=>Array.isArray(i)?e(i,t):(t.add(i),t),i),i=e(t,new Set),n=[];i.forEach(t=>n.unshift(t)),this._styles=n}else this._styles=void 0===t?[]:[t];this._styles=this._styles.map(t=>{if(t instanceof CSSStyleSheet&&!Q){const e=Array.prototype.slice.call(t.cssRules).reduce((t,e)=>t+e.cssText,"");return new Y(String(e),X)}return t})}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Q?this.renderRoot.adoptedStyleSheets=t.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){const e=this.render();super.update(t),e!==tt&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){return tt}}et.finalized=!0,et.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const r=i.scopeName,s=z.has(e),o=D&&11===e.nodeType&&!!e.host,a=o&&!L.has(r),c=a?document.createDocumentFragment():e;if(((t,e,i)=>{let r=z.get(e);void 0===r&&(n(e,e.firstChild),z.set(e,r=new A(Object.assign({templateFactory:I},i))),r.appendInto(e)),r.setValue(t),r.commit()})(t,c,Object.assign({templateFactory:F(r)},i)),a){const t=z.get(c);z.delete(c);const i=t.value instanceof b?t.value.template:void 0;q(r,c,i),n(e,e.firstChild),e.appendChild(c),z.set(e,t)}!s&&o&&window.ShadyCSS.styleElement(e.host)};var it="object"==typeof global&&global&&global.Object===Object&&global,nt="object"==typeof self&&self&&self.Object===Object&&self,rt=it||nt||Function("return this")(),st=rt.Symbol,ot=Object.prototype,at=ot.hasOwnProperty,ct=ot.toString,ut=st?st.toStringTag:void 0;var dt=Object.prototype.toString;var lt=st?st.toStringTag:void 0;function ht(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":lt&< in Object(t)?function(t){var e=at.call(t,ut),i=t[ut];try{t[ut]=void 0;var n=!0}catch(t){}var r=ct.call(t);return n&&(e?t[ut]=i:delete t[ut]),r}(t):function(t){return dt.call(t)}(t)}function pt(t){return null!=t&&"object"==typeof t}function ft(t){return"symbol"==typeof t||pt(t)&&"[object Symbol]"==ht(t)}function vt(t,e){for(var i=-1,n=null==t?0:t.length,r=Array(n);++i0){if(++Zt>=800)return arguments[0]}else Zt=0;return Jt.apply(void 0,arguments)});function Yt(t,e){for(var i=-1,n=null==t?0:t.length;++i-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}function fe(t){return null!=t&&pe(t.length)&&!kt(t)}function ve(t,e,i){if(!_t(i))return!1;var n=typeof e;return!!("number"==n?fe(i)&&re(e,i.length):"string"==n&&e in i)&&oe(i[e],t)}var me=Object.prototype;function ye(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||me)}function ge(t){return pt(t)&&"[object Arguments]"==ht(t)}var be=Object.prototype,_e=be.hasOwnProperty,we=be.propertyIsEnumerable,je=ge(function(){return arguments}())?ge:function(t){return pt(t)&&_e.call(t,"callee")&&!we.call(t,"callee")};var xe="object"==typeof t&&t&&!t.nodeType&&t,Se=xe&&"object"==typeof module&&module&&!module.nodeType&&module,$e=Se&&Se.exports===xe?rt.Buffer:void 0,Oe=($e?$e.isBuffer:void 0)||function(){return!1},Ae={};function ke(t){return function(e){return t(e)}}Ae["[object Float32Array]"]=Ae["[object Float64Array]"]=Ae["[object Int8Array]"]=Ae["[object Int16Array]"]=Ae["[object Int32Array]"]=Ae["[object Uint8Array]"]=Ae["[object Uint8ClampedArray]"]=Ae["[object Uint16Array]"]=Ae["[object Uint32Array]"]=!0,Ae["[object Arguments]"]=Ae["[object Array]"]=Ae["[object ArrayBuffer]"]=Ae["[object Boolean]"]=Ae["[object DataView]"]=Ae["[object Date]"]=Ae["[object Error]"]=Ae["[object Function]"]=Ae["[object Map]"]=Ae["[object Number]"]=Ae["[object Object]"]=Ae["[object RegExp]"]=Ae["[object Set]"]=Ae["[object String]"]=Ae["[object WeakMap]"]=!1;var Ce="object"==typeof t&&t&&!t.nodeType&&t,Ee=Ce&&"object"==typeof module&&module&&!module.nodeType&&module,Pe=Ee&&Ee.exports===Ce&&it.process,Ne=function(){try{var t=Ee&&Ee.require&&Ee.require("util").types;return t||Pe&&Pe.binding&&Pe.binding("util")}catch(t){}}(),Te=Ne&&Ne.isTypedArray,Ie=Te?ke(Te):function(t){return pt(t)&&pe(t.length)&&!!Ae[ht(t)]},Me=Object.prototype.hasOwnProperty;function ze(t,e){var i=mt(t),n=!i&&je(t),r=!i&&!n&&Oe(t),s=!i&&!n&&!r&&Ie(t),o=i||n||r||s,a=o?function(t,e){for(var i=-1,n=Array(t);++i1?e[n-1]:void 0,s=n>2?e[2]:void 0;for(r=He.length>3&&"function"==typeof r?(n--,r):void 0,s&&ve(e[0],e[1],s)&&(r=n<3?void 0:r,n=1),t=Object(t);++i-1},ii.prototype.set=function(t,e){var i=this.__data__,n=ti(i,t);return n<0?(++this.size,i.push([t,e])):i[n][1]=e,this};var ni=Ft(rt,"Map");function ri(t,e){var i,n,r=t.__data__;return("string"==(n=typeof(i=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==i:null===i)?r["string"==typeof e?"string":"hash"]:r.map}function si(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e0&&n(c)?i>1?t(c,i-1,n,r,s):pi(s,c):r||(s[s.length]=c)}return s}(t,1):[]}function yi(t){return Xt(le(t,void 0,mi),t+"")}var gi=Ue(Object.getPrototypeOf,Object),bi=Function.prototype,_i=Object.prototype,wi=bi.toString,ji=_i.hasOwnProperty,xi=wi.call(Object);var Si=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");function $i(t){var e=this.__data__=new ii(t);this.size=e.size}$i.prototype.clear=function(){this.__data__=new ii,this.size=0},$i.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},$i.prototype.get=function(t){return this.__data__.get(t)},$i.prototype.has=function(t){return this.__data__.has(t)},$i.prototype.set=function(t,e){var i=this.__data__;if(i instanceof ii){var n=i.__data__;if(!ni||n.length<199)return n.push([t,e]),this.size=++i.size,this;i=this.__data__=new si(n)}return i.set(t,e),this.size=i.size,this};var Oi="object"==typeof t&&t&&!t.nodeType&&t,Ai=Oi&&"object"==typeof module&&module&&!module.nodeType&&module,ki=Ai&&Ai.exports===Oi?rt.Buffer:void 0,Ci=ki?ki.allocUnsafe:void 0;function Ei(t,e){for(var i=-1,n=null==t?0:t.length,r=0,s=[];++ia))return!1;var u=s.get(t);if(u&&s.get(e))return u==e;var d=-1,l=!0,h=2&i?new un:void 0;for(s.set(t,e),s.set(e,t);++d2?e[2]:void 0;for(r&&ve(e[0],e[1],r)&&(n=1);++i-1?n[r?t[s]:s]:void 0});function Hn(t,e){var i=-1,n=fe(t)?Array(t.length):[];return In(t,(function(t,r,s){n[++i]=e(t,r,s)})),n}function Bn(t,e){return(mt(t)?vt:Hn)(t,Cn(e))}var Wn=Object.prototype.hasOwnProperty;function Jn(t,e){return null!=t&&Wn.call(t,e)}function Zn(t){return null==t?[]:function(t,e){return vt(e,(function(e){return t[e]}))}(t,Fe(t))}function Kn(t,e){return e.length<2?t:hi(t,function(t,e,i){var n=-1,r=t.length;e<0&&(e=-e>r?0:r+e),(i=i>r?r:i)<0&&(i+=r),r=e>i?0:i-e>>>0,e>>>=0;for(var s=Array(r);++n1),e})),ue(t,Vi(t),i),n&&(i=cn(i,7,ir));for(var r=e.length;r--;)er(i,e[r]);return i}));function rr(t,e,i,n){if(!_t(t))return t;for(var r=-1,s=(e=di(e,t)).length,o=s-1,a=t;null!=a&&++r-1;)a!==t&&_r.call(a,c,1),_r.call(t,c,1);return t}(t,e):t}));function jr(t){if(null==t)return 0;if(fe(t))return"string"==typeof(e=t)||!mt(e)&&pt(e)&&"[object String]"==ht(e)?yr(t):t.length;var e,i=Ji(t);return"[object Map]"==i||"[object Set]"==i?t.size:De(t).length}var xr={add:"add item",cancel:"cancel",next:"next",save:"save",delete:"delete"},Sr={no_group_selected:"Select a group first",no_entity_selected:"Select an entity first",no_groups_defined:"There are no groups defined",no_entities_for_group:"There are no entities in this group",no_actions_for_entity:"There are no actions for this entity",no_entries_defined:"There are no items to show"},$r={group:"Group",entity:"Entity",action:"Action",days:"Days",time:"Time",options:"Options",day_type_daily:"every day",day_type_weekdays:"weekdays",day_type_custom:"custom"},Or={mon:"mon",tue:"tue",wed:"wed",thu:"thu",fri:"fri",sat:"sat",sun:"sun"},Ar={mon:"monday",tue:"tuesday",wed:"wednesday",thu:"thursday",fri:"friday",sat:"saturday",sun:"sunday"},kr={on:"on",every:"every",and:"and",at:"at",before:"before",after:"after",sunrise:"sunrise",sunset:"sunset"},Cr={turn_on:"turn on",turn_off:"turn off",close_cover:"close",open_cover:"open",set_temperature:"set to"},Er={climate:"climate",cover:"covers",fan:"fans",light:"lights",switch:"switches",vacuum:"vacuum"},Pr={actions:xr,instructions:Sr,fields:$r,days_short:Or,days_long:Ar,words:kr,services:Cr,domains:Er},Nr={add:"Nieuw item",cancel:"annuleren",next:"verder",save:"opslaan",delete:"verwijder"},Tr={no_group_selected:"Selecteer eerst een groep",no_entity_selected:"Selecteer eerst een entiteit",no_groups_defined:"Er zijn geen groepen gedefinieerd",no_entities_for_group:"Deze groep heeft geen entiteiten",no_actions_for_entity:"Deze entiteit heeft geen acties",no_entries_defined:"Er zijn geen items aangemaakt"},Ir={group:"Groep",entity:"Entiteit",action:"Actie",days:"Dagen",time:"Tijdstip",options:"Opties",day_type_daily:"Dagelijks",day_type_weekdays:"Werkdagen",day_type_custom:"Anders"},Mr={mon:"ma",tue:"di",wed:"wo",thu:"do",fri:"vr",sat:"za",sun:"zo"},zr={mon:"maandag",tue:"dinsdag",wed:"woensdag",thu:"donderdag",fri:"vrijdag",sat:"zaterdag",sun:"zondag"},Ur={on:"op",every:"elke",and:"en",at:"om",before:"voor",after:"na",sunrise:"zonsopgang",sunset:"zonsondergang"},Vr={turn_on:"aanzetten",turn_off:"uitzetten",close_cover:"sluiten",open_cover:"openen",set_temperature:"Zet op"},Rr={climate:"verwarming",cover:"zonwering",fan:"ventilatie",light:"verlichting",switch:"schakelaars",vacuum:"stofzuiger"},Dr={actions:Nr,instructions:Tr,fields:Ir,days_short:Mr,days_long:zr,words:Ur,services:Vr,domains:Rr},Fr={en:Object.freeze({__proto__:null,actions:xr,instructions:Sr,fields:$r,days_short:Or,days_long:Ar,words:kr,services:Cr,domains:Er,default:Pr}),nl:Object.freeze({__proto__:null,actions:Nr,instructions:Tr,fields:Ir,days_short:Mr,days_long:zr,words:Ur,services:Vr,domains:Rr,default:Dr})};function Gr(t,e="",i=""){const n=(localStorage.getItem("selectedLanguage")||"en").replace(/['"]+/g,"").replace("-","_");var r;try{r=t.split(".").reduce((t,e)=>t[e],Fr[n])}catch(e){r=t.split(".").reduce((t,e)=>t[e],Fr.en)}return void 0===r&&(r=t.split(".").reduce((t,e)=>t[e],Fr.en)),""!==e&&""!==i&&(r=r.replace(e,i)),r}const Lr={light:{actions:[{service:"turn_on",icon:"lightbulb-outline",name:Gr("services.turn_on")},{service:"turn_off",icon:"lightbulb-off-outline",name:Gr("services.turn_off")}]},switch:{actions:[{service:"turn_on",name:Gr("services.turn_on")},{service:"turn_off",name:Gr("services.turn_off")}]},cover:{actions:[{service:"open_cover",name:Gr("services.open_cover")},{service:"close_cover",name:Gr("services.close_cover")}]},climate:{actions:[{service:"set_temperature",service_data:{temperature:10},name:Gr("services.set_temperature")+" 10C",icon:"thermometer-chevron-down"},{service:"set_temperature",service_data:{temperature:22},name:Gr("services.set_temperature")+" 22C",icon:"thermometer-chevron-up"}]}},qr={group:"",entity:"",action:"",newItem:!1,actionConfirmed:!1,editItem:"",timeHours:"12",timeMinutes:"00",days:[],daysType:"daily",sun:!1};function Hr(t){var e={automation:"robot",camera:"camera",climate:"home-thermometer-outline",cover:"window-shutter",fan:"fan",input_number:"sort-numeric-variant",input_select:"form-select",input_text:"form-textbox",input_time:"clock",light:"lightbulb-outline",media_player:"speaker",script:"script-text",switch:"flash",vacuum:"robot-vacuum"};return t in e?e[t]:"folder-outline"}function Br(t){return"turn_on"==t?"toggle-switch-outline":"turn_off"==t?"toggle-switch-off-outline":"open_cover"==t?"window-shutter-open":"close_cover"==t?"window-shutter":"set_temperature"==t?"thermometer":"flash"}const Wr=/^D([0-7]+)T([0-9SR\-\+]+)([A0-9+]+)$/,Jr=/^(A([0-9]+))+$/,Zr=/^([0-9]{4})?(S[SR])([0-9]{4})?$/,Kr=/^([0-9]{2})([0-9]{2})$/,Qr=/^([\+\-]{1})([0-9]{2}):([0-9]{2})$/;function Xr(t){let e=Kr.exec(t);return e?e[1]+":"+e[2]:null}function Yr(t){if(-1===t.indexOf("."))return"";return String(t.split(".").shift())}function ts(t){let e=Fe(t);e=e.sort();let i={};return e.forEach(e=>i[e]=t[e]),JSON.stringify(Zn(i)).replace(/\W/g," ")}function es(t){return t.match(/^switch.schedule_[0-9a-f]{6}$/)}function is(t){return!t||!t.length||1==t.length&&0==t[0]?"daily":5!=t.length||t.includes(6)||t.includes(7)?"custom":"weekdays"}function ns(t){return t.replace("_"," ")}class rs{constructor(t){this.entities={},this.groups={},t.entities||t.domains||void 0!==t.standardConfiguration&&!t.standardConfiguration?this.userConfig=t:this.userConfig={domains:Lr},t.groups&&Rn(t.groups,this.CreateGroup.bind(this)),this.discoverExisting=void 0===t.discoverExisting||t.discoverExisting}CreateGroup(t,e){let i=Object.assign({},t);var n;this.groups[e]||(Vn(i,{name:(n=e,"climate"==n?Gr("domains.climate"):"cover"==n?Gr("domains.cover"):"fan"==n?Gr("domains.fan"):"light"==n?Gr("domains.light"):"switch"==n?Gr("domains.switches"):"vacuum"==n?Gr("domains.vacuum"):n),domains:[],entities:[]}),this.groups[e]=i)}FindGroupForEntity(t){let e=Yr(t);return!!qn(this.groups,i=>!!(i.domains&&Array.isArray(i.domains)&&i.domains.includes(e))||!!(i.entities&&Array.isArray(i.entities)&&i.entities.includes(t)))}AddEntityToGroup(t){let e=Yr(t);if(this.groups[e]){let i=[...this.groups[e].entities];i.push(t),this.groups[e].entities=i}else this.CreateGroup({entities:[t],icon:Hr(e)},e)}AddEntityInfo(t,e){if(this.entities[t])Object.assign(this.entities[t],nr(Object.assign({},e),"actions")),n="actions",null!=(i=e)&&Sn(i,n,Jn)&&Rn(e.actions,e=>{if(qn(this.entities[t].actions,t=>ts(gr(t,["service","service_data"]))==ts(gr(e,["service","service_data"]))))return;let i=[...this.entities[t].actions];i.push(e),this.entities[t].actions=i});else{let i=Object.assign(Object.assign({},e),{id:t});Vn(i,{actions:[]}),this.entities[t]=i}var i,n;this.FindGroupForEntity(t)||this.AddEntityToGroup(t)}LoadEntities(t){if(Rn(t,t=>{let e=t.entity_id,i=Yr(e);es(e)||(this.userConfig.domains&&i in this.userConfig.domains&&this.AddEntityInfo(e,this.userConfig.domains[i]),this.userConfig.entities&&e in this.userConfig.entities&&this.AddEntityInfo(e,this.userConfig.entities[e]))}),this.discoverExisting){let e=Fn(t,t=>es(t.entity_id));e=Bn(e,t=>t.attributes.actions),e=mi(e),Rn(e,t=>{let e=Object.assign({},t);Yr(e.entity)||(e.entity=Yr(e.service)+"."+e.entity,e.service=e.service.split(".").pop());let i=nr(e,["entity","service"]);i?this.AddEntityInfo(e.entity,{actions:[{service:e.service,service_data:i}]}):this.AddEntityInfo(e.entity,{actions:[gr(e,"service")]})})}Rn(this.entities,(e,i)=>{Vn(e,{name:t[i].attributes.friendly_name,icon:Hr(Yr(i))}),Object.assign(e,{actions:Bn(e.actions,t=>{let e=Object.assign({},t);var i;return Vn(e,{name:(i=t.service,"turn_on"==i?Gr("services.turn_on"):"turn_off"==i?Gr("services.turn_off"):"open_cover"==i?Gr("services.open_cover"):"close_cover"==i?Gr("services.close_cover"):i),icon:Br(t.service)}),Object.assign(e,{id:ts(gr(t,["service","service_data"]))}),e})})}),t["sun.sun"]&&(this.next_sunrise=new Date(t["sun.sun"].attributes.next_rising),this.next_sunset=new Date(t["sun.sun"].attributes.next_setting))}GetGroups(){return tr(this.groups,t=>gr(t,["name","icon"]))}GetEntities(t){let e={};if(t){let i=this.groups[t];e=function(t,e){if(null==t)return{};var i=vt(Vi(t),(function(t){return[t]}));return e=Cn(e),sr(t,i,(function(t,i){return e(t,i[0])}))}(this.entities,(t,e)=>{let n=Yr(e);return!(!i.domains||!i.domains.includes(n))||!(!i.entities||!i.entities.includes(e))})}else e=this.entities;return tr(e,t=>gr(t,["name","icon"]))}GetEntity(t){return this.entities[t]}GetActions(t){let e=this.entities[t];return tr(Yn(e.actions,"id"),t=>gr(t,["name","icon"]))}GetAction(t,e){let i=this.entities[t];if(!i)return null;let n=qn(i.actions,{id:e});return n||null}}const ss=((t,...e)=>{const i=e.reduce((e,i,n)=>e+(t=>{if(t instanceof Y)return t.cssText;if("number"==typeof t)return t;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+t[n+1],t[0]);return new Y(i,X)})` +(window.litElementVersions||(window.litElementVersions=[])).push("2.4.0");const tt={};class et extends J{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const t=this.getStyles();if(Array.isArray(t)){const e=(t,i)=>t.reduceRight((t,i)=>Array.isArray(i)?e(i,t):(t.add(i),t),i),i=e(t,new Set),n=[];i.forEach(t=>n.unshift(t)),this._styles=n}else this._styles=void 0===t?[]:[t];this._styles=this._styles.map(t=>{if(t instanceof CSSStyleSheet&&!Q){const e=Array.prototype.slice.call(t.cssRules).reduce((t,e)=>t+e.cssText,"");return new Y(String(e),X)}return t})}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Q?this.renderRoot.adoptedStyleSheets=t.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){const e=this.render();super.update(t),e!==tt&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){return tt}}et.finalized=!0,et.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const r=i.scopeName,s=z.has(e),o=D&&11===e.nodeType&&!!e.host,a=o&&!L.has(r),c=a?document.createDocumentFragment():e;if(((t,e,i)=>{let r=z.get(e);void 0===r&&(n(e,e.firstChild),z.set(e,r=new A(Object.assign({templateFactory:I},i))),r.appendInto(e)),r.setValue(t),r.commit()})(t,c,Object.assign({templateFactory:F(r)},i)),a){const t=z.get(c);z.delete(c);const i=t.value instanceof b?t.value.template:void 0;q(r,c,i),n(e,e.firstChild),e.appendChild(c),z.set(e,t)}!s&&o&&window.ShadyCSS.styleElement(e.host)};var it="object"==typeof global&&global&&global.Object===Object&&global,nt="object"==typeof self&&self&&self.Object===Object&&self,rt=it||nt||Function("return this")(),st=rt.Symbol,ot=Object.prototype,at=ot.hasOwnProperty,ct=ot.toString,ut=st?st.toStringTag:void 0;var dt=Object.prototype.toString;var lt=st?st.toStringTag:void 0;function ht(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":lt&< in Object(t)?function(t){var e=at.call(t,ut),i=t[ut];try{t[ut]=void 0;var n=!0}catch(t){}var r=ct.call(t);return n&&(e?t[ut]=i:delete t[ut]),r}(t):function(t){return dt.call(t)}(t)}function pt(t){return null!=t&&"object"==typeof t}function ft(t){return"symbol"==typeof t||pt(t)&&"[object Symbol]"==ht(t)}function vt(t,e){for(var i=-1,n=null==t?0:t.length,r=Array(n);++i0){if(++Zt>=800)return arguments[0]}else Zt=0;return Jt.apply(void 0,arguments)});function Yt(t,e){for(var i=-1,n=null==t?0:t.length;++i-1&&t%1==0&&t-1&&t%1==0&&t<=9007199254740991}function fe(t){return null!=t&&pe(t.length)&&!kt(t)}function ve(t,e,i){if(!_t(i))return!1;var n=typeof e;return!!("number"==n?fe(i)&&re(e,i.length):"string"==n&&e in i)&&oe(i[e],t)}var me=Object.prototype;function ye(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||me)}function ge(t){return pt(t)&&"[object Arguments]"==ht(t)}var be=Object.prototype,_e=be.hasOwnProperty,we=be.propertyIsEnumerable,xe=ge(function(){return arguments}())?ge:function(t){return pt(t)&&_e.call(t,"callee")&&!we.call(t,"callee")};var je="object"==typeof t&&t&&!t.nodeType&&t,Se=je&&"object"==typeof module&&module&&!module.nodeType&&module,$e=Se&&Se.exports===je?rt.Buffer:void 0,Oe=($e?$e.isBuffer:void 0)||function(){return!1},Ae={};function ke(t){return function(e){return t(e)}}Ae["[object Float32Array]"]=Ae["[object Float64Array]"]=Ae["[object Int8Array]"]=Ae["[object Int16Array]"]=Ae["[object Int32Array]"]=Ae["[object Uint8Array]"]=Ae["[object Uint8ClampedArray]"]=Ae["[object Uint16Array]"]=Ae["[object Uint32Array]"]=!0,Ae["[object Arguments]"]=Ae["[object Array]"]=Ae["[object ArrayBuffer]"]=Ae["[object Boolean]"]=Ae["[object DataView]"]=Ae["[object Date]"]=Ae["[object Error]"]=Ae["[object Function]"]=Ae["[object Map]"]=Ae["[object Number]"]=Ae["[object Object]"]=Ae["[object RegExp]"]=Ae["[object Set]"]=Ae["[object String]"]=Ae["[object WeakMap]"]=!1;var Ce="object"==typeof t&&t&&!t.nodeType&&t,Ee=Ce&&"object"==typeof module&&module&&!module.nodeType&&module,Pe=Ee&&Ee.exports===Ce&&it.process,Ne=function(){try{var t=Ee&&Ee.require&&Ee.require("util").types;return t||Pe&&Pe.binding&&Pe.binding("util")}catch(t){}}(),Te=Ne&&Ne.isTypedArray,Ie=Te?ke(Te):function(t){return pt(t)&&pe(t.length)&&!!Ae[ht(t)]},Me=Object.prototype.hasOwnProperty;function ze(t,e){var i=mt(t),n=!i&&xe(t),r=!i&&!n&&Oe(t),s=!i&&!n&&!r&&Ie(t),o=i||n||r||s,a=o?function(t,e){for(var i=-1,n=Array(t);++i1?e[n-1]:void 0,s=n>2?e[2]:void 0;for(r=qe.length>3&&"function"==typeof r?(n--,r):void 0,s&&ve(e[0],e[1],s)&&(r=n<3?void 0:r,n=1),t=Object(t);++i-1},ei.prototype.set=function(t,e){var i=this.__data__,n=Ye(i,t);return n<0?(++this.size,i.push([t,e])):i[n][1]=e,this};var ii=Ft(rt,"Map");function ni(t,e){var i,n,r=t.__data__;return("string"==(n=typeof(i=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==i:null===i)?r["string"==typeof e?"string":"hash"]:r.map}function ri(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e0&&i(a)?e>1?vi(a,e-1,i,n,r):hi(r,a):n||(r[r.length]=a)}return r}function mi(t){return(null==t?0:t.length)?vi(t,1):[]}function yi(t){return Xt(le(t,void 0,mi),t+"")}var gi=Ue(Object.getPrototypeOf,Object),bi=Function.prototype,_i=Object.prototype,wi=bi.toString,xi=_i.hasOwnProperty,ji=wi.call(Object);function Si(t){var e=this.__data__=new ei(t);this.size=e.size}Si.prototype.clear=function(){this.__data__=new ei,this.size=0},Si.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},Si.prototype.get=function(t){return this.__data__.get(t)},Si.prototype.has=function(t){return this.__data__.has(t)},Si.prototype.set=function(t,e){var i=this.__data__;if(i instanceof ei){var n=i.__data__;if(!ii||n.length<199)return n.push([t,e]),this.size=++i.size,this;i=this.__data__=new ri(n)}return i.set(t,e),this.size=i.size,this};var $i="object"==typeof t&&t&&!t.nodeType&&t,Oi=$i&&"object"==typeof module&&module&&!module.nodeType&&module,Ai=Oi&&Oi.exports===$i?rt.Buffer:void 0,ki=Ai?Ai.allocUnsafe:void 0;function Ci(t,e){for(var i=-1,n=null==t?0:t.length,r=0,s=[];++ia))return!1;var u=s.get(t);if(u&&s.get(e))return u==e;var d=-1,l=!0,h=2&i?new cn:void 0;for(s.set(t,e),s.set(e,t);++d2?e[2]:void 0;for(r&&ve(e[0],e[1],r)&&(n=1);++i-1?n[r?t[s]:s]:void 0});function Ln(t,e){var i=-1,n=fe(t)?Array(t.length):[];return Nn(t,(function(t,r,s){n[++i]=e(t,r,s)})),n}function qn(t,e){return(mt(t)?vt:Ln)(t,An(e))}var Hn=Object.prototype.hasOwnProperty;function Bn(t,e){return null!=t&&Hn.call(t,e)}function Wn(t){return null==t?[]:function(t,e){return vt(e,(function(e){return t[e]}))}(t,De(t))}function Jn(t,e){return e.length<2?t:li(t,function(t,e,i){var n=-1,r=t.length;e<0&&(e=-e>r?0:r+e),(i=i>r?r:i)<0&&(i+=r),r=e>i?0:i-e>>>0,e>>>=0;for(var s=Array(r);++n1),e})),ue(t,Ui(t),i),n&&(i=an(i,7,tr));for(var r=e.length;r--;)Yn(i,e[r]);return i}));function ir(t,e,i,n){if(!_t(t))return t;for(var r=-1,s=(e=ui(e,t)).length,o=s-1,a=t;null!=a&&++re||s&&o&&c&&!a&&!u||n&&o&&c||!i&&c||!r)return 1;if(!n&&!s&&!u&&t=a?c:c*("desc"==i[n]?-1:1)}return t.index-e.index}(t,e,i)}))}var or=yi((function(t,e){return null==t?{}:function(t,e){return nr(t,e,(function(e,i){return Sn(t,i)}))}(t,e)}));function ar(t,e,i,n){for(var r=i-1,s=t.length;++r-1;)a!==t&&cr.call(a,c,1),cr.call(t,c,1);return t}(t,e):t})),dr=he((function(t,e){if(null==t)return[];var i=e.length;return i>1&&ve(t,e[0],e[1])?e=[]:i>2&&ve(e[0],e[1],e[2])&&(e=[e[0]]),sr(t,vi(e,1),[])})),lr={add:"add item",cancel:"cancel",next:"next",save:"save",delete:"delete"},hr={no_group_selected:"Select a group first",no_entity_selected:"Select an entity first",no_groups_defined:"There are no groups defined",no_entities_for_group:"There are no entities in this group",no_actions_for_entity:"There are no actions for this entity",no_entries_defined:"There are no items to show"},pr={group:"Group",entity:"Entity",action:"Action",days:"Days",time:"Time",options:"Options",day_type_daily:"every day",day_type_weekdays:"weekdays",day_type_custom:"custom",shift_with_sun:"automatically adjust time to sunrise/sunset"},fr={mon:"mon",tue:"tue",wed:"wed",thu:"thu",fri:"fri",sat:"sat",sun:"sun"},vr={mon:"monday",tue:"tuesday",wed:"wednesday",thu:"thursday",fri:"friday",sat:"saturday",sun:"sunday"},mr={on:"on",every:"every",and:"and",at:"at",before:"before",after:"after",sunrise:"sunrise",sunset:"sunset"},yr={turn_on:"turn on",turn_off:"turn off",close_cover:"close",open_cover:"open",set_temperature:"set to"},gr={climate:"climate",cover:"covers",fan:"fans",light:"lights",switch:"switches",vacuum:"vacuum"},br={scheduler:"Scheduler",actions:lr,instructions:hr,fields:pr,days_short:fr,days_long:vr,words:mr,services:yr,domains:gr},_r={add:"Nieuw item",cancel:"annuleren",next:"verder",save:"opslaan",delete:"verwijder"},wr={no_group_selected:"Selecteer eerst een groep",no_entity_selected:"Selecteer eerst een entiteit",no_groups_defined:"Er zijn geen groepen gedefinieerd",no_entities_for_group:"Deze groep heeft geen entiteiten",no_actions_for_entity:"Deze entiteit heeft geen acties",no_entries_defined:"Er zijn geen items aangemaakt"},xr={group:"Groep",entity:"Entiteit",action:"Actie",days:"Dagen",time:"Tijdstip",options:"Opties",day_type_daily:"Dagelijks",day_type_weekdays:"Werkdagen",day_type_custom:"Anders",shift_with_sun:"Automatisch aanpassen aan zonsopgang/zonsondergang"},jr={mon:"ma",tue:"di",wed:"wo",thu:"do",fri:"vr",sat:"za",sun:"zo"},Sr={mon:"maandag",tue:"dinsdag",wed:"woensdag",thu:"donderdag",fri:"vrijdag",sat:"zaterdag",sun:"zondag"},$r={on:"op",every:"elke",and:"en",at:"om",before:"voor",after:"na",sunrise:"zonsopgang",sunset:"zonsondergang"},Or={turn_on:"aanzetten",turn_off:"uitzetten",close_cover:"sluiten",open_cover:"openen",set_temperature:"Zet op"},Ar={climate:"verwarming",cover:"zonwering",fan:"ventilatie",light:"verlichting",switch:"schakelaars",vacuum:"stofzuiger"},kr={scheduler:"Scheduler",actions:_r,instructions:wr,fields:xr,days_short:jr,days_long:Sr,words:$r,services:Or,domains:Ar},Cr={en:Object.freeze({__proto__:null,scheduler:"Scheduler",actions:lr,instructions:hr,fields:pr,days_short:fr,days_long:vr,words:mr,services:yr,domains:gr,default:br}),nl:Object.freeze({__proto__:null,scheduler:"Scheduler",actions:_r,instructions:wr,fields:xr,days_short:jr,days_long:Sr,words:$r,services:Or,domains:Ar,default:kr})};function Er(t,e="",i=""){const n=(localStorage.getItem("selectedLanguage")||"en").replace(/['"]+/g,"").replace("-","_");var r;try{r=t.split(".").reduce((t,e)=>t[e],Cr[n])}catch(e){r=t.split(".").reduce((t,e)=>t[e],Cr.en)}return void 0===r&&(r=t.split(".").reduce((t,e)=>t[e],Cr.en)),""!==e&&""!==i&&(r=r.replace(e,i)),r}const Pr={light:{actions:[{service:"turn_on",icon:"lightbulb-outline",name:Er("services.turn_on")},{service:"turn_off",icon:"lightbulb-off-outline",name:Er("services.turn_off")}]},switch:{actions:[{service:"turn_on",name:Er("services.turn_on")},{service:"turn_off",name:Er("services.turn_off")}]},cover:{actions:[{service:"open_cover",name:Er("services.open_cover")},{service:"close_cover",name:Er("services.close_cover")}]},climate:{actions:[{service:"set_temperature",service_data:{temperature:10},name:Er("services.set_temperature")+" 10C",icon:"thermometer-chevron-down"},{service:"set_temperature",service_data:{temperature:22},name:Er("services.set_temperature")+" 22C",icon:"thermometer-chevron-up"}]}},Nr={group:"",entity:"",action:"",newItem:!1,actionConfirmed:!1,editItem:"",timeHours:"12",timeMinutes:"00",days:[],daysType:"daily",sun:!1};function Tr(t){var e={automation:"robot",camera:"camera",climate:"home-thermometer-outline",cover:"window-shutter",fan:"fan",input_number:"sort-numeric-variant",input_select:"form-select",input_text:"form-textbox",input_time:"clock",light:"lightbulb-outline",media_player:"speaker",script:"script-text",switch:"flash",vacuum:"robot-vacuum"};return t in e?e[t]:"folder-outline"}function Ir(t){return"turn_on"==t?"toggle-switch-outline":"turn_off"==t?"toggle-switch-off-outline":"open_cover"==t?"window-shutter-open":"close_cover"==t?"window-shutter":"set_temperature"==t?"thermometer":"flash"}const Mr=/^D([0-7]+)T([0-9SR\-\+]+)([A0-9+]+)$/,zr=/^(A([0-9]+))+$/,Ur=/^([0-9]{4})?(S[SR])([0-9]{4})?$/,Vr=/^([0-9]{2})([0-9]{2})$/,Rr=/^([\+\-]{1})([0-9]{2}):([0-9]{2})$/;function Dr(t){let e=Vr.exec(t);return e?e[1]+":"+e[2]:null}function Fr(t){if(-1===t.indexOf("."))return"";return String(t.split(".").shift())}function Gr(t){let e=De(t);e=e.sort();let i={};return e.forEach(e=>i[e]=t[e]),JSON.stringify(Wn(i)).replace(/\W/g," ")}function Lr(t){return t.match(/^switch.schedule_[0-9a-f]{6}$/)}function qr(t){return!t||!t.length||1==t.length&&0==t[0]?"daily":5!=t.length||t.includes(6)||t.includes(7)?"custom":"weekdays"}function Hr(t){return t.replace("_"," ")}class Br{constructor(t){this.entities={},this.groups={},t.entities||t.domains||void 0!==t.standardConfiguration&&!t.standardConfiguration?this.userConfig=t:this.userConfig={domains:Pr},t.groups&&Un(t.groups,this.CreateGroup.bind(this)),this.discoverExisting=void 0===t.discoverExisting||t.discoverExisting}CreateGroup(t,e){let i=Object.assign({},t);var n;this.groups[e]||(zn(i,{name:(n=e,"climate"==n?Er("domains.climate"):"cover"==n?Er("domains.cover"):"fan"==n?Er("domains.fan"):"light"==n?Er("domains.light"):"switch"==n?Er("domains.switches"):"vacuum"==n?Er("domains.vacuum"):n),domains:[],entities:[]}),this.groups[e]=i)}FindGroupForEntity(t){let e=Fr(t);return!!Gn(this.groups,i=>!!(i.domains&&Array.isArray(i.domains)&&i.domains.includes(e))||!!(i.entities&&Array.isArray(i.entities)&&i.entities.includes(t)))}AddEntityToGroup(t){let e=Fr(t);if(this.groups[e]){let i=[...this.groups[e].entities];i.push(t),this.groups[e].entities=i}else this.CreateGroup({entities:[t],icon:Tr(e)},e)}AddEntityInfo(t,e){if(this.entities[t])Object.assign(this.entities[t],er(Object.assign({},e),"actions")),n="actions",null!=(i=e)&&jn(i,n,Bn)&&Un(e.actions,e=>{if(Gn(this.entities[t].actions,t=>Gr(or(t,["service","service_data"]))==Gr(or(e,["service","service_data"]))))return;let i=[...this.entities[t].actions];i.push(e),this.entities[t].actions=i});else{let i=Object.assign(Object.assign({},e),{id:t});zn(i,{actions:[]}),this.entities[t]=i}var i,n;this.FindGroupForEntity(t)||this.AddEntityToGroup(t)}LoadEntities(t){if(Un(t,t=>{let e=t.entity_id,i=Fr(e);Lr(e)||(this.userConfig.domains&&i in this.userConfig.domains&&this.AddEntityInfo(e,this.userConfig.domains[i]),this.userConfig.entities&&e in this.userConfig.entities&&this.AddEntityInfo(e,this.userConfig.entities[e]))}),this.discoverExisting){let e=Rn(t,t=>Lr(t.entity_id));e=qn(e,t=>t.attributes.actions),e=mi(e),Un(e,t=>{let e=Object.assign({},t);Fr(e.entity)||(e.entity=Fr(e.service)+"."+e.entity,e.service=e.service.split(".").pop());let i=er(e,["entity","service"]);i?this.AddEntityInfo(e.entity,{actions:[{service:e.service,service_data:i}]}):this.AddEntityInfo(e.entity,{actions:[or(e,"service")]})})}Un(this.entities,(e,i)=>{zn(e,{name:t[i].attributes.friendly_name,icon:Tr(Fr(i))}),Object.assign(e,{actions:qn(e.actions,t=>{let e=Object.assign({},t);var i;return zn(e,{name:(i=t.service,"turn_on"==i?Er("services.turn_on"):"turn_off"==i?Er("services.turn_off"):"open_cover"==i?Er("services.open_cover"):"close_cover"==i?Er("services.close_cover"):i),icon:Ir(t.service)}),Object.assign(e,{id:Gr(or(t,["service","service_data"]))}),e})})}),t["sun.sun"]&&(this.next_sunrise=new Date(t["sun.sun"].attributes.next_rising),this.next_sunset=new Date(t["sun.sun"].attributes.next_setting))}GetGroups(){let t=Xn(this.groups,t=>or(t,["name","icon"]));return Un(t,(t,e)=>{Object.assign(t,{key:e})}),t=dr(t,"name"),t}GetEntities(t){let e={};if(t){let i=this.groups[t];e=function(t,e){if(null==t)return{};var i=vt(Ui(t),(function(t){return[t]}));return e=An(e),nr(t,i,(function(t,i){return e(t,i[0])}))}(this.entities,(t,e)=>{let n=Fr(e);return!(!i.domains||!i.domains.includes(n))||!(!i.entities||!i.entities.includes(e))})}else e=this.entities;let i=Xn(e,t=>or(t,["name","icon"]));return Un(i,(t,e)=>{Object.assign(t,{key:e})}),i=dr(i,"name"),i}GetEntity(t){return this.entities[t]}GetActions(t){let e=this.entities[t],i=Xn(Qn(e.actions,"id"),t=>or(t,["name","icon"]));return Un(i,(t,e)=>{Object.assign(t,{key:e})}),i=dr(i,"name"),i}GetAction(t,e){let i=this.entities[t];if(!i)return null;let n=Gn(i.actions,{id:e});return n||null}}const Wr=((t,...e)=>{const i=e.reduce((e,i,n)=>e+(t=>{if(t instanceof Y)return t.cssText;if("number"==typeof t)return t;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+t[n+1],t[0]);return new Y(i,X)})` /* list view */ div.list-item { @@ -395,59 +395,59 @@ const Z=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?Object .padded-right { margin-right: 11px; } -`;function os(t){return Array.isArray(t)?"array":typeof t==typeof{}?"object":"string"==typeof t?"string":"boolean"==typeof t?"boolean":"number"==typeof t?"number":"unknown"}function as(t,e){return os(t)==e}function cs(t,e,i){return!(!t||!t.hasOwnProperty(e))&&as(t[e],i)}function us(t,e,i){return!t||!t.hasOwnProperty(e)||as(t[e],i)}var ds;console.info("%c SCHEDULER-CARD \n%c Version 1.2.2 ","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"scheduler-card",name:"Scheduler Card",description:"Card to manage schedule entities made with scheduler-component."}),t.SchedulerCard=class extends et{constructor(){super(...arguments),this.entries=[],this.selection=Object.assign({},qr),this.count=0,this.await_update=!0}static get styles(){return ss}set hass(t){this.await_update&&this.Config&&(this._hass||this.Config.LoadEntities(t.states),this.update_entries(t),this._hass=t)}update_entries(t){let e=Fn(t.states,t=>es(t.entity_id)).map(t=>function(t,e){let i=t.attributes.entries.map(t=>{let i=Wr.exec(t),n=Jr.exec(i[3]),r={days:i[1].split("").map(Number),actions:n.map(Number).filter(t=>!isNaN(t))},s=Zr.exec(i[2]);if(null!==Xr(i[2]))Object.assign(r,{time:Xr(i[2])});else if(s){let t;if(t="SR"==s[2]?e.next_sunrise.getHours()+e.next_sunrise.getMinutes()/60:e.next_sunset.getHours()+e.next_sunset.getMinutes()/60,s[1]){let e=t-(Number(s[1].substr(0,2))+Number(s[1].substr(2))/60);Object.assign(r,{event:"SR"==s[2]?"sunrise":"sunset",offset:"-"+Xr(s[1]),time:`${String(Math.floor(e)).padStart(2,"0")}:${String(10*Math.round(6*(e-Math.floor(e)))).padStart(2,"0")}`})}else if(s[3]){let e=t+(Number(s[3].substr(0,2))+Number(s[3].substr(2))/60);Object.assign(r,{event:"SR"==s[2]?"sunrise":"sunset",offset:"+"+Xr(s[3]),time:`${String(Math.floor(e)).padStart(2,"0")}:${String(10*Math.round(6*(e-Math.floor(e)))).padStart(2,"0")}`})}}return r}),n=t.attributes.actions.map(t=>{let i=Yr(t.entity)?t.entity:Yr(t.service)+"."+t.entity,n=t.service,r=nr(t,["service","entity"]);if(Yr(i)==Yr(n)&&(n=n.split(".").pop()),!e.GetEntity(i))return;let s=ts(r?Object.assign({service:n,service_data:r}):Object.assign({service:n}));return e.GetAction(i,s)?{entity:i,action:s}:void 0});return{id:t.entity_id,enabled:"off"!=t.state,entries:i,actions:n}}(t,this.Config)).filter(t=>void 0!==t.actions[0]);e!=this.entries&&(this.entries=e,this.await_update=!1,this.requestUpdate())}awaitUpdate(){this.await_update=!0}render(){return this.selection.newItem||this.selection.editItem?this.selection.newItem&&!this.selection.actionConfirmed?V` +`;function Jr(t){return Array.isArray(t)?"array":typeof t==typeof{}?"object":"string"==typeof t?"string":"boolean"==typeof t?"boolean":"number"==typeof t?"number":"unknown"}function Zr(t,e){return Jr(t)==e}function Kr(t,e,i){return!(!t||!t.hasOwnProperty(e))&&Zr(t[e],i)}function Qr(t,e,i){return!t||!t.hasOwnProperty(e)||Zr(t[e],i)}var Xr;console.info("%c SCHEDULER-CARD \n%c Version 1.2.2 ","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"scheduler-card",name:"Scheduler Card",description:"Card to manage schedule entities made with scheduler-component."}),t.SchedulerCard=class extends et{constructor(){super(...arguments),this.entries=[],this.selection=Object.assign({},Nr),this.count=0,this.await_update=!0}static get styles(){return Wr}set hass(t){this.await_update&&this.Config&&(this._hass||this.Config.LoadEntities(t.states),this.update_entries(t),this._hass=t)}update_entries(t){let e=Rn(t.states,t=>Lr(t.entity_id)).map(t=>function(t,e){let i=t.attributes.entries.map(t=>{let i=Mr.exec(t),n=zr.exec(i[3]),r={days:i[1].split("").map(Number),actions:n.map(Number).filter(t=>!isNaN(t))},s=Ur.exec(i[2]);if(null!==Dr(i[2]))Object.assign(r,{time:Dr(i[2])});else if(s){let t;if(t="SR"==s[2]?e.next_sunrise.getHours()+e.next_sunrise.getMinutes()/60:e.next_sunset.getHours()+e.next_sunset.getMinutes()/60,s[1]){let e=t-(Number(s[1].substr(0,2))+Number(s[1].substr(2))/60);Object.assign(r,{event:"SR"==s[2]?"sunrise":"sunset",offset:"-"+Dr(s[1]),time:`${String(Math.floor(e)).padStart(2,"0")}:${String(10*Math.round(6*(e-Math.floor(e)))).padStart(2,"0")}`})}else if(s[3]){let e=t+(Number(s[3].substr(0,2))+Number(s[3].substr(2))/60);Object.assign(r,{event:"SR"==s[2]?"sunrise":"sunset",offset:"+"+Dr(s[3]),time:`${String(Math.floor(e)).padStart(2,"0")}:${String(10*Math.round(6*(e-Math.floor(e)))).padStart(2,"0")}`})}}return r}),n=t.attributes.actions.map(t=>{let i=Fr(t.entity)?t.entity:Fr(t.service)+"."+t.entity,n=t.service,r=er(t,["service","entity"]);if(Fr(i)==Fr(n)&&(n=n.split(".").pop()),!e.GetEntity(i))return;let s=Gr(r?Object.assign({service:n,service_data:r}):Object.assign({service:n}));return e.GetAction(i,s)?{entity:i,action:s}:void 0});return{id:t.entity_id,enabled:"off"!=t.state,entries:i,actions:n}}(t,this.Config)).filter(t=>void 0!==t.actions[0]);e!=this.entries&&(this.entries=e,this.await_update=!1,this.requestUpdate())}awaitUpdate(){this.await_update=!0}render(){return this.selection.newItem||this.selection.editItem?this.selection.newItem&&!this.selection.actionConfirmed?V` -
Scheduler
+
${Er("scheduler")}
-
${Gr("fields.group")}
+
${Er("fields.group")}
${this.getGroups()}
-
${Gr("fields.entity")}
+
${Er("fields.entity")}
${this.getEntities()}
-
${Gr("fields.action")}
+
${Er("fields.action")}
${this.getActions()}
- ${Gr("actions.cancel")} - ${this.selection.action?V`${Gr("actions.next")}`:V`${Gr("actions.next")}`} + ${Er("actions.cancel")} + ${this.selection.action?V`${Er("actions.next")}`:V`${Er("actions.next")}`}
`:V` -
Scheduler
+
${Er("scheduler")}
${this.showEditor()}
`:V` -
Scheduler
+
${Er("scheduler")}
${this.getEntries()}
- ${Gr("actions.add")} + ${Er("actions.add")}
- `}newItem(){this.selection=Be(Object.assign({},qr),{newItem:!0}),this.requestUpdate()}editItemCancel(){this.selection=Object.assign({},qr),this.requestUpdate()}newItemConfirm(){this.selection=Be(Object.assign({},qr),{newItem:!0,actionConfirmed:!0,entity:this.selection.entity,action:this.selection.action}),this.requestUpdate()}getEntries(){return this.entries&&this.entries.length?this.entries.map(t=>{if(!t.actions[0])return V``;let e=this.Config.GetEntity(t.actions[0].entity),i=this.Config.GetAction(t.actions[0].entity,t.actions[0].action);return V` + `}newItem(){this.selection=He(Object.assign({},Nr),{newItem:!0}),this.requestUpdate()}editItemCancel(){this.selection=Object.assign({},Nr),this.requestUpdate()}newItemConfirm(){this.selection=He(Object.assign({},Nr),{newItem:!0,actionConfirmed:!0,entity:this.selection.entity,action:this.selection.action}),this.requestUpdate()}getEntries(){return this.entries&&this.entries.length?this.entries.map(t=>{if(!t.actions[0])return V``;let e=this.Config.GetEntity(t.actions[0].entity),i=this.Config.GetAction(t.actions[0].entity,t.actions[0].action);return V`
${e.icon?V``:""}
- ${ns(e.name)} + ${Hr(e.name)}
- ${ns(i.name)} + ${Hr(i.name)}
- ${function(t){if("daily"==is(t))return Gr("fields.day_type_daily");if("weekdays"==is(t))return`${Gr("words.on")} ${Gr("fields.day_type_weekdays")}`;{let i=Array();t.includes(1)&&i.push(Gr("days_long.mon")),t.includes(2)&&i.push(Gr("days_long.tue")),t.includes(3)&&i.push(Gr("days_long.wed")),t.includes(4)&&i.push(Gr("days_long.thu")),t.includes(5)&&i.push(Gr("days_long.fri")),t.includes(6)&&i.push(Gr("days_long.sat")),t.includes(7)&&i.push(Gr("days_long.sun"));let n=i.join(", ");var e=n.lastIndexOf(", ");return e&&(n=n.slice(0,e)+n.slice(e).replace(", ",` ${Gr("words.and")} `)),`${Gr("words.every")} ${n}`}}(t.entries[0].days)} + ${function(t){if("daily"==qr(t))return Er("fields.day_type_daily");if("weekdays"==qr(t))return`${Er("words.on")} ${Er("fields.day_type_weekdays")}`;{let i=Array();t.includes(1)&&i.push(Er("days_long.mon")),t.includes(2)&&i.push(Er("days_long.tue")),t.includes(3)&&i.push(Er("days_long.wed")),t.includes(4)&&i.push(Er("days_long.thu")),t.includes(5)&&i.push(Er("days_long.fri")),t.includes(6)&&i.push(Er("days_long.sat")),t.includes(7)&&i.push(Er("days_long.sun"));let n=i.join(", ");var e=n.lastIndexOf(", ");return e&&(n=n.slice(0,e)+n.slice(e).replace(", ",` ${Er("words.and")} `)),`${Er("words.every")} ${n}`}}(t.entries[0].days)}
- ${function(t){if(t.event){let e=Qr.exec(t.offset),i=Number(e[2])+Number(e[3])/60;return Math.abs(i)<1/6?`${Gr("words.at")} ${t.event} (${t.time})`:`${e[2]}:${e[3]} ${"+"==e[1]?Gr("words.after"):Gr("words.before")} ${Gr("words."+t.event)} (${t.time})`}return`${Gr("words.at")} ${t.time}`}(gr(t.entries[0],["time","event","offset"]))} + ${function(t){if(t.event){let e=Rr.exec(t.offset),i=Number(e[2])+Number(e[3])/60;return Math.abs(i)<1/6?`${Er("words.at")} ${t.event} (${t.time})`:`${e[2]}:${e[3]} ${"+"==e[1]?Er("words.after"):Er("words.before")} ${Er("words."+t.event)} (${t.time})`}return`${Er("words.at")} ${t.time}`}(or(t.entries[0],["time","event","offset"]))}
${t.enabled?V``:V``} @@ -455,33 +455,33 @@ const Z=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?Object
`}):[V`
- ${Gr("instructions.no_entries_defined")} + ${Er("instructions.no_entries_defined")}
- `]}toggleDisable(t,e){e.stopPropagation(),!e.target.checked?this._hass.callService("switch","turn_on",{entity_id:t}):this._hass.callService("switch","turn_off",{entity_id:t}),this.awaitUpdate()}editItem(t){let e=qn(this.entries,{id:t});this.selection=Be(Object.assign({},qr),{editItem:t,entity:e.actions[0].entity,action:e.actions[0].action,timeHours:e.entries[0].time.split(":").shift(),timeMinutes:e.entries[0].time.split(":").pop(),days:e.entries[0].days,daysType:is(e.entries[0].days),sun:void 0!==e.entries[0].event}),this.requestUpdate()}getGroups(){let t=this.Config.GetGroups();return jr(t)?Bn(t,(t,e)=>V` - + `]}toggleDisable(t,e){e.stopPropagation(),!e.target.checked?this._hass.callService("switch","turn_on",{entity_id:t}):this._hass.callService("switch","turn_off",{entity_id:t}),this.awaitUpdate()}editItem(t){let e=Gn(this.entries,{id:t});this.selection=He(Object.assign({},Nr),{editItem:t,entity:e.actions[0].entity,action:e.actions[0].action,timeHours:e.entries[0].time.split(":").shift(),timeMinutes:e.entries[0].time.split(":").pop(),days:e.entries[0].days,daysType:qr(e.entries[0].days),sun:void 0!==e.entries[0].event}),this.requestUpdate()}getGroups(){let t=this.Config.GetGroups();return t.length?t.map(t=>V` + ${t.icon?V``:""} - ${ns(t.name)} + ${Hr(t.name)} - `):[V`
${Gr("instructions.no_groups_defined")}
`]}selectGroup(t){Object.assign(this.selection,{group:t,entity:null,action:null}),this.requestUpdate()}getEntities(){if(!this.selection.group)return[V`
${Gr("instructions.no_group_selected")}
`];let t=this.Config.GetEntities(this.selection.group);return jr(t)?Bn(t,(t,e)=>V` - + `):[V`
${Er("instructions.no_groups_defined")}
`]}selectGroup(t){Object.assign(this.selection,{group:t,entity:null,action:null}),this.requestUpdate()}getEntities(){if(!this.selection.group)return[V`
${Er("instructions.no_group_selected")}
`];let t=this.Config.GetEntities(this.selection.group);return t.length?t.map(t=>V` + ${t.icon?V``:""} - ${ns(t.name)} + ${Hr(t.name)} - `):[V`
${Gr("instructions.no_entities_for_group")}
`]}selectEntity(t){Object.assign(this.selection,{entity:t,action:null}),this.requestUpdate()}getActions(){if(!this.selection.entity)return[V`
${Gr("instructions.no_entity_selected")}
`];let t=this.Config.GetActions(this.selection.entity);return jr(t)?Bn(t,(t,e)=>V` - + `):[V`
${Er("instructions.no_entities_for_group")}
`]}selectEntity(t){Object.assign(this.selection,{entity:t,action:null}),this.requestUpdate()}getActions(){if(!this.selection.entity)return[V`
${Er("instructions.no_entity_selected")}
`];let t=this.Config.GetActions(this.selection.entity);return t.length?t.map(t=>V` + ${t.icon?V``:""} - ${ns(t.name)} + ${Hr(t.name)} - `):[V`
${Gr("instructions.no_actions_for_entity")}
`]}selectAction(t){Object.assign(this.selection,{action:t}),this.requestUpdate()}setConfig(t){!function(t){if(void 0!==t.entities)try{if(!cs(t,"entities","object"))throw`Configuration for 'entities' should be of type 'object', but got '${os(t.entities)}'.`;Rn(t.entities,(t,e)=>{if(!as(t,"object"))throw`In '${e}: (...)': expected type 'object', but got '${os(t)}'.`;if(!us(t,"name","string"))throw`In ${e} at 'name: ${t.name}': expected type 'string', but got '${os(t.name)}'.`;if(!us(t,"icon","string"))throw`In ${e} at 'icon: ${t.icon}': expected type 'string', but got '${os(t.icon)}'.`;if(!us(t,"actions","array"))throw`In ${e} at 'actions: (...)': expected type 'array', but got '${os(t.actions)}'.`;t&&Rn(t.actions,t=>{if(!cs(t,"service","string"))throw`In ${e}->actions at 'service: ${t.service}': expected type 'string', but got '${os(t.service)}'.`;if(!us(t,"name","string"))throw`In ${e}->actions at 'name: ${t.name}': expected type 'string', but got '${os(t.name)}'.`;if(!us(t,"icon","string"))throw`In ${e}->actions at 'icon: ${t.icon}': expected type 'string', but got '${os(t.icon)}'.`;if(!us(t,"service_data","object"))throw`In ${e}->actions at 'service_data: ${t.service_data}': expected type 'object', but got '${os(t.service_data)}'.`})})}catch(t){throw new Error("Invalid configuration provided for 'entities'. "+t)}if(void 0!==t.domains)try{if(!cs(t,"domains","object"))throw`Configuration for 'domains' should be of type 'object', but got '${os(t.domains)}'.`;Rn(t.domains,(t,e)=>{if(!as(t,"object"))throw`In '${e}: (...)': expected type 'object', but got '${os(t)}'.`;if(!us(t,"name","string"))throw`In ${e} at 'name: ${t.name}': expected type 'string', but got '${os(t.name)}'.`;if(!us(t,"icon","string"))throw`In ${e} at 'icon: ${t.icon}': expected type 'string', but got '${os(t.icon)}'.`;if(!us(t,"actions","array"))throw`In ${e} at 'actions: (...)': expected type 'array', but got '${os(t.actions)}'.`;t&&Rn(t.actions,t=>{if(!cs(t,"service","string"))throw`In ${e}->actions at 'service: ${t.service}': expected type 'string', but got '${os(t.service)}'.`;if(!us(t,"name","string"))throw`In ${e}->actions at 'name: ${t.name}': expected type 'string', but got '${os(t.name)}'.`;if(!us(t,"icon","string"))throw`In ${e}->actions at 'icon: ${t.icon}': expected type 'string', but got '${os(t.icon)}'.`;if(!us(t,"service_data","object"))throw`In ${e}->actions at 'service_data: ${t.service_data}': expected type 'object', but got '${os(t.service_data)}'.`})})}catch(t){throw new Error("Invalid configuration provided for 'domains'. "+t)}if(void 0!==t.groups)try{if(!cs(t,"groups","object"))throw`Configuration for 'domains' should be of type 'object', but got '${os(t.groups)}'.`;Rn(t.groups,(t,e)=>{if(!as(t,"object"))throw`In '${e}: (...)': expected type 'object', but got '${os(t)}'.`;if(!us(t,"name","string"))throw`In ${e} at 'name: ${t.name}': expected type 'string', but got '${os(t.name)}'.`;if(!us(t,"icon","string"))throw`In ${e} at 'icon: ${t.icon}': expected type 'string', but got '${os(t.icon)}'.`;if(!us(t,"entities","array"))throw`In ${e} at 'icon: ${t.entities}': expected type 'array', but got '${os(t.entities)}'.`;if(!us(t,"domains","array"))throw`In ${e} at 'icon: ${t.domains}': expected type 'array', but got '${os(t.domains)}'.`;t&&(Rn(t.entities,t=>{if(!as(t,"string"))throw`In ${e}->entities at '${t}': expected type 'string', but got '${os(t)}'.`}),Rn(t.domains,t=>{if(!as(t,"string"))throw`In ${e}->domains at '${t}': expected type 'string', but got '${os(t)}'.`}))})}catch(t){throw new Error("Invalid configuration provided for 'groups'. "+t)}if(!us(t,"discoverExisting","boolean"))throw new Error(`Invalid configuration provided for 'discoverExisting': expected type 'boolean', but got '${os(t.discoverExisting)}'.`);if(!us(t,"standardConfiguration","boolean"))throw new Error(`Invalid configuration provided for 'standardConfiguration': expected type 'boolean', but got '${os(t.standardConfiguration)}'.`)}(t),this.Config=new rs(t)}showEditor(){let t=this.Config.GetEntity(this.selection.entity),e=this.Config.GetAction(this.selection.entity,this.selection.action);return V` + `):[V`
${Er("instructions.no_actions_for_entity")}
`]}selectAction(t){Object.assign(this.selection,{action:t}),this.requestUpdate()}setConfig(t){!function(t){if(void 0!==t.entities)try{if(!Kr(t,"entities","object"))throw`Configuration for 'entities' should be of type 'object', but got '${Jr(t.entities)}'.`;Un(t.entities,(t,e)=>{if(!Zr(t,"object"))throw`In '${e}: (...)': expected type 'object', but got '${Jr(t)}'.`;if(!Qr(t,"name","string"))throw`In ${e} at 'name: ${t.name}': expected type 'string', but got '${Jr(t.name)}'.`;if(!Qr(t,"icon","string"))throw`In ${e} at 'icon: ${t.icon}': expected type 'string', but got '${Jr(t.icon)}'.`;if(!Qr(t,"actions","array"))throw`In ${e} at 'actions: (...)': expected type 'array', but got '${Jr(t.actions)}'.`;t&&Un(t.actions,t=>{if(!Kr(t,"service","string"))throw`In ${e}->actions at 'service: ${t.service}': expected type 'string', but got '${Jr(t.service)}'.`;if(!Qr(t,"name","string"))throw`In ${e}->actions at 'name: ${t.name}': expected type 'string', but got '${Jr(t.name)}'.`;if(!Qr(t,"icon","string"))throw`In ${e}->actions at 'icon: ${t.icon}': expected type 'string', but got '${Jr(t.icon)}'.`;if(!Qr(t,"service_data","object"))throw`In ${e}->actions at 'service_data: ${t.service_data}': expected type 'object', but got '${Jr(t.service_data)}'.`})})}catch(t){throw new Error("Invalid configuration provided for 'entities'. "+t)}if(void 0!==t.domains)try{if(!Kr(t,"domains","object"))throw`Configuration for 'domains' should be of type 'object', but got '${Jr(t.domains)}'.`;Un(t.domains,(t,e)=>{if(!Zr(t,"object"))throw`In '${e}: (...)': expected type 'object', but got '${Jr(t)}'.`;if(!Qr(t,"name","string"))throw`In ${e} at 'name: ${t.name}': expected type 'string', but got '${Jr(t.name)}'.`;if(!Qr(t,"icon","string"))throw`In ${e} at 'icon: ${t.icon}': expected type 'string', but got '${Jr(t.icon)}'.`;if(!Qr(t,"actions","array"))throw`In ${e} at 'actions: (...)': expected type 'array', but got '${Jr(t.actions)}'.`;t&&Un(t.actions,t=>{if(!Kr(t,"service","string"))throw`In ${e}->actions at 'service: ${t.service}': expected type 'string', but got '${Jr(t.service)}'.`;if(!Qr(t,"name","string"))throw`In ${e}->actions at 'name: ${t.name}': expected type 'string', but got '${Jr(t.name)}'.`;if(!Qr(t,"icon","string"))throw`In ${e}->actions at 'icon: ${t.icon}': expected type 'string', but got '${Jr(t.icon)}'.`;if(!Qr(t,"service_data","object"))throw`In ${e}->actions at 'service_data: ${t.service_data}': expected type 'object', but got '${Jr(t.service_data)}'.`})})}catch(t){throw new Error("Invalid configuration provided for 'domains'. "+t)}if(void 0!==t.groups)try{if(!Kr(t,"groups","object"))throw`Configuration for 'domains' should be of type 'object', but got '${Jr(t.groups)}'.`;Un(t.groups,(t,e)=>{if(!Zr(t,"object"))throw`In '${e}: (...)': expected type 'object', but got '${Jr(t)}'.`;if(!Qr(t,"name","string"))throw`In ${e} at 'name: ${t.name}': expected type 'string', but got '${Jr(t.name)}'.`;if(!Qr(t,"icon","string"))throw`In ${e} at 'icon: ${t.icon}': expected type 'string', but got '${Jr(t.icon)}'.`;if(!Qr(t,"entities","array"))throw`In ${e} at 'icon: ${t.entities}': expected type 'array', but got '${Jr(t.entities)}'.`;if(!Qr(t,"domains","array"))throw`In ${e} at 'icon: ${t.domains}': expected type 'array', but got '${Jr(t.domains)}'.`;t&&(Un(t.entities,t=>{if(!Zr(t,"string"))throw`In ${e}->entities at '${t}': expected type 'string', but got '${Jr(t)}'.`}),Un(t.domains,t=>{if(!Zr(t,"string"))throw`In ${e}->domains at '${t}': expected type 'string', but got '${Jr(t)}'.`}))})}catch(t){throw new Error("Invalid configuration provided for 'groups'. "+t)}if(!Qr(t,"discoverExisting","boolean"))throw new Error(`Invalid configuration provided for 'discoverExisting': expected type 'boolean', but got '${Jr(t.discoverExisting)}'.`);if(!Qr(t,"standardConfiguration","boolean"))throw new Error(`Invalid configuration provided for 'standardConfiguration': expected type 'boolean', but got '${Jr(t.standardConfiguration)}'.`)}(t),this.Config=new Br(t)}showEditor(){let t=this.Config.GetEntity(this.selection.entity),e=this.Config.GetAction(this.selection.entity,this.selection.action);return V`
-
${Gr("fields.action")}
+
${Er("fields.action")}
${t.icon?V``:""}
- ${ns(t.name)} + ${Hr(t.name)}
@@ -492,31 +492,31 @@ const Z=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?Object ${e.icon?V``:""}
- ${ns(e.name)} + ${Hr(e.name)}
-
${Gr("fields.days")}
+
${Er("fields.days")}
- ${Gr("fields.day_type_daily")} - ${Gr("fields.day_type_weekdays")} - ${Gr("fields.day_type_custom")} + ${Er("fields.day_type_daily")} + ${Er("fields.day_type_weekdays")} + ${Er("fields.day_type_custom")}
- ${Gr("days_short.mon")} - ${Gr("days_short.tue")} - ${Gr("days_short.wed")} - ${Gr("days_short.thu")} - ${Gr("days_short.fri")} - ${Gr("days_short.sat")} - ${Gr("days_short.sun")} + ${Er("days_short.mon")} + ${Er("days_short.tue")} + ${Er("days_short.wed")} + ${Er("days_short.thu")} + ${Er("days_short.fri")} + ${Er("days_short.sat")} + ${Er("days_short.sun")}
-
${Gr("fields.time")}
+
${Er("fields.time")}
@@ -550,15 +550,15 @@ const Z=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?Object
-
${Gr("fields.options")}
+
${Er("fields.options")}
- ${this.selection.sun?V`automatically adjust time to sunrise/sunset`:V`automatically adjust time to sunrise/sunset`} + ${this.selection.sun?V`${Er("fields.shift_with_sun")}`:V`${Er("fields.shift_with_sun")}`}
- ${Gr("actions.cancel")} - ${void 0===this.selection.editItem?"":V`${Gr("actions.delete")}`} - ${Gr("actions.save")} + ${Er("actions.cancel")} + ${void 0===this.selection.editItem?"":V`${Er("actions.delete")}`} + ${Er("actions.save")}
- `}updateDays(t){var e=Array("daily","weekdays","custom");e.includes(t)?this.selection.daysType=t:(this.selection.days.includes(Number(t))?wr(this.selection.days,Number(t)):this.selection.days.push(Number(t)),this.selection.daysType="custom"),this.shadowRoot.querySelectorAll(".day-item").forEach(t=>{let i=String(t.getAttribute("index"));e.includes(i)?this.selection.daysType==i?t.classList.add("active"):t.classList.remove("active"):this.selection.days.includes(Number(i))?t.classList.add("active"):t.classList.remove("active")}),"custom"==this.selection.daysType?this.shadowRoot.querySelector("#day-list-custom").classList.remove("closed"):this.shadowRoot.querySelector("#day-list-custom").classList.add("closed")}updateTime(t){let e=Number(this.selection.timeHours),i=Number(this.selection.timeMinutes);"time-hours-up"==t?e++:"time-hours-down"==t?e--:"time-minutes-up"==t?i+=10:"time-minutes-down"==t&&(i-=10),e<0?e=23:e>23?e=0:i<0?i=50:i>50&&(i=0);let n=String(e).padStart(2,"0"),r=String(i).padStart(2,"0");this.shadowRoot.querySelector("#time-hours").innerHTML=n,this.shadowRoot.querySelector("#time-minutes").innerHTML=r,this.selection.timeHours=n,this.selection.timeMinutes=r}editItemSave(){var t=function(t,e){let i=e.GetEntity(t.entity),n=e.GetAction(t.entity,t.action),r=gr(n,["service","service_data"]);Object.assign(r,{entity:i.id}),Yr(r.service)||(r.service=Yr(r.entity)+"."+r.service);let s={actions:[0]};if(t.sun){if(e.next_sunrise&&e.next_sunset){let i,n=Number(t.timeHours)+Number(t.timeMinutes)/60,r=e.next_sunrise.getHours()+e.next_sunrise.getMinutes()/60,o=e.next_sunset.getHours()+e.next_sunset.getMinutes()/60;Math.abs(n-r)0?Math.abs(Math.floor(i)):Math.abs(Math.ceil(i)),c=i>0?Math.round(60*(i-a)):-Math.round(60*(i+a));Object.assign(s,{offset:`${i>0?"+":"-"}${String(a).padStart(2,"0")}:${String(c).padStart(2,"0")}`})}}else Object.assign(s,{time:t.timeHours+":"+t.timeMinutes});return"weekdays"==t.daysType?Object.assign(s,{days:[1,2,3,4,5]}):"custom"==t.daysType&&Object.assign(s,{days:t.days.sort().filter(t=>0!=t)}),{actions:[r],entries:[s]}}(this.selection,this.Config);this.selection.newItem?this._hass.callService("scheduler","add",t):this.selection.editItem&&this._hass.callService("scheduler","edit",Object.assign(t,{entity_id:this.selection.editItem})),this.selection=Object.assign({},qr),this.awaitUpdate()}editItemDelete(){let t=this.selection.editItem;this._hass.callService("scheduler","remove",{entity_id:t}),this.selection=Object.assign({},qr),this.awaitUpdate()}toggleSun(t){this.selection.sun=t}},e([K()],t.SchedulerCard.prototype,"Config",void 0),e([K({type:Number})],t.SchedulerCard.prototype,"count",void 0),e([K()],t.SchedulerCard.prototype,"_hass",void 0),t.SchedulerCard=e([(ds="scheduler-card",t=>"function"==typeof t?((t,e)=>(window.customElements.define(t,e),e))(ds,t):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){window.customElements.define(t,e)}}})(ds,t))],t.SchedulerCard)}({}); + `}updateDays(t){var e=Array("daily","weekdays","custom");e.includes(t)?this.selection.daysType=t:(this.selection.days.includes(Number(t))?ur(this.selection.days,Number(t)):this.selection.days.push(Number(t)),this.selection.daysType="custom"),this.shadowRoot.querySelectorAll(".day-item").forEach(t=>{let i=String(t.getAttribute("index"));e.includes(i)?this.selection.daysType==i?t.classList.add("active"):t.classList.remove("active"):this.selection.days.includes(Number(i))?t.classList.add("active"):t.classList.remove("active")}),"custom"==this.selection.daysType?this.shadowRoot.querySelector("#day-list-custom").classList.remove("closed"):this.shadowRoot.querySelector("#day-list-custom").classList.add("closed")}updateTime(t){let e=Number(this.selection.timeHours),i=Number(this.selection.timeMinutes);"time-hours-up"==t?e++:"time-hours-down"==t?e--:"time-minutes-up"==t?i+=10:"time-minutes-down"==t&&(i-=10),e<0?e=23:e>23?e=0:i<0?i=50:i>50&&(i=0);let n=String(e).padStart(2,"0"),r=String(i).padStart(2,"0");this.shadowRoot.querySelector("#time-hours").innerHTML=n,this.shadowRoot.querySelector("#time-minutes").innerHTML=r,this.selection.timeHours=n,this.selection.timeMinutes=r}editItemSave(){var t=function(t,e){let i=e.GetEntity(t.entity),n=e.GetAction(t.entity,t.action),r=or(n,["service","service_data"]);Object.assign(r,{entity:i.id}),Fr(r.service)||(r.service=Fr(r.entity)+"."+r.service);let s={actions:[0]};if(t.sun){if(e.next_sunrise&&e.next_sunset){let i,n=Number(t.timeHours)+Number(t.timeMinutes)/60,r=e.next_sunrise.getHours()+e.next_sunrise.getMinutes()/60,o=e.next_sunset.getHours()+e.next_sunset.getMinutes()/60;Math.abs(n-r)0?Math.abs(Math.floor(i)):Math.abs(Math.ceil(i)),c=i>0?Math.round(60*(i-a)):-Math.round(60*(i+a));Object.assign(s,{offset:`${i>0?"+":"-"}${String(a).padStart(2,"0")}:${String(c).padStart(2,"0")}`})}}else Object.assign(s,{time:t.timeHours+":"+t.timeMinutes});return"weekdays"==t.daysType?Object.assign(s,{days:[1,2,3,4,5]}):"custom"==t.daysType&&Object.assign(s,{days:t.days.sort().filter(t=>0!=t)}),{actions:[r],entries:[s]}}(this.selection,this.Config);this.selection.newItem?this._hass.callService("scheduler","add",t):this.selection.editItem&&this._hass.callService("scheduler","edit",Object.assign(t,{entity_id:this.selection.editItem})),this.selection=Object.assign({},Nr),this.awaitUpdate()}editItemDelete(){let t=this.selection.editItem;this._hass.callService("scheduler","remove",{entity_id:t}),this.selection=Object.assign({},Nr),this.awaitUpdate()}toggleSun(t){this.selection.sun=t}},e([K()],t.SchedulerCard.prototype,"Config",void 0),e([K({type:Number})],t.SchedulerCard.prototype,"count",void 0),e([K()],t.SchedulerCard.prototype,"_hass",void 0),t.SchedulerCard=e([(Xr="scheduler-card",t=>"function"==typeof t?((t,e)=>(window.customElements.define(t,e),e))(Xr,t):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){window.customElements.define(t,e)}}})(Xr,t))],t.SchedulerCard)}({}); diff --git a/src/config-parser.ts b/src/config-parser.ts index 5773b1a1..352bede5 100755 --- a/src/config-parser.ts +++ b/src/config-parser.ts @@ -1,5 +1,5 @@ -import { defaults, forEach, each, find, has, pick, omit, filter, flatten, map, mapValues, keyBy, pickBy } from "lodash-es"; +import { defaults, forEach, each, find, has, pick, omit, filter, flatten, map, mapValues, keyBy, pickBy, sortBy } from "lodash-es"; import { IDictionary, IEntityConfigEntry, IGroupConfigEntry, IButtonEntry, IActionConfigEntry, IConfig } from './types' import { defaultDomainConfig, getIconForDomain, getIconForAction, getNameForDomain, getNameForService } from './default-config' @@ -152,9 +152,12 @@ export class Config { } GetGroups(): IDictionary { - return mapValues(this.groups, el => { + let output = mapValues(this.groups, el => { return pick(el, ['name', 'icon']) as IButtonEntry }); + each(output, (item, key) => { Object.assign(item, { key: key }) }); + output = sortBy(output, 'name'); + return output; } GetEntities(group_id: string): IDictionary { @@ -170,9 +173,12 @@ export class Config { }); } - return mapValues(entities, el => { + let output = mapValues(entities, el => { return pick(el, ['name', 'icon']); }); + each(output, (item, key) => { Object.assign(item, { key: key }) }); + output = sortBy(output, 'name'); + return output; } GetEntity(entity_id: string): IEntityConfigEntry { @@ -183,9 +189,12 @@ export class Config { let entityCfg = this.entities[entity_id]; let actions = keyBy(entityCfg['actions'], 'id'); - return mapValues(actions, el => { + let output = mapValues(actions, el => { return pick(el, ['name', 'icon']) as IButtonEntry }); + each(output, (item, key) => { Object.assign(item, { key: key }) }); + output = sortBy(output, 'name'); + return output; } GetAction(entity_id: string, action_id: string): IActionConfigEntry | null { diff --git a/src/helpers.ts b/src/helpers.ts index ff4913a6..2670711c 100755 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -78,7 +78,6 @@ export function CreateSlug(input: IDictionary) { return slugify(JSON.stringify(values(obj)).replace(/\W/g, ' '), '_'); } - export function IsSchedulerEntity(entity_id: string) { return entity_id.match(/^switch.schedule_[0-9a-f]{6}$/); } diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 1a897f2c..e62223e7 100755 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -1,4 +1,5 @@ { + "scheduler": "Scheduler", "actions": { "add": "add item", "cancel": "cancel", @@ -23,7 +24,8 @@ "options": "Options", "day_type_daily": "every day", "day_type_weekdays": "weekdays", - "day_type_custom": "custom" + "day_type_custom": "custom", + "shift_with_sun": "automatically adjust time to sunrise/sunset" }, "days_short": { "mon": "mon", diff --git a/src/localize/languages/nl.json b/src/localize/languages/nl.json index a2c17737..046a1477 100755 --- a/src/localize/languages/nl.json +++ b/src/localize/languages/nl.json @@ -1,4 +1,5 @@ { + "scheduler": "Scheduler", "actions": { "add": "Nieuw item", "cancel": "annuleren", @@ -23,7 +24,8 @@ "options": "Opties", "day_type_daily": "Dagelijks", "day_type_weekdays": "Werkdagen", - "day_type_custom": "Anders" + "day_type_custom": "Anders", + "shift_with_sun": "Automatisch aanpassen aan zonsopgang/zonsondergang" }, "days_short": { "mon": "ma", diff --git a/src/scheduler-card.ts b/src/scheduler-card.ts index 5fcf2ae0..7f32f3d9 100755 --- a/src/scheduler-card.ts +++ b/src/scheduler-card.ts @@ -1,7 +1,7 @@ import { LitElement, html, customElement, property, CSSResult, TemplateResult } from 'lit-element'; import { HomeAssistant } from 'custom-card-helpers'; -import { find, filter, pick, extend, map, pull, size } from "lodash-es"; +import { find, filter, pick, extend, pull } from "lodash-es"; import { Config } from './config-parser'; @@ -78,7 +78,7 @@ export class SchedulerCard extends LitElement { if (!this.selection.newItem && !this.selection.editItem) { return html` -
Scheduler
+
${localize('scheduler')}
${this.getEntries()}
@@ -91,7 +91,7 @@ export class SchedulerCard extends LitElement { } else if (this.selection.newItem && !this.selection.actionConfirmed) { return html` -
Scheduler
+
${localize('scheduler')}
${localize('fields.group')}
@@ -116,7 +116,7 @@ export class SchedulerCard extends LitElement { else { return html` -
Scheduler
+
${localize('scheduler')}
${this.showEditor()}
`; @@ -209,10 +209,10 @@ export class SchedulerCard extends LitElement { getGroups(): TemplateResult[] { let groups = this.Config.GetGroups(); - if (!size(groups)) return [html`
${localize('instructions.no_groups_defined')}
`]; - return map(groups, (el: IButtonEntry, key: string) => { + if (!groups.length) return [html`
${localize('instructions.no_groups_defined')}
`]; + return groups.map((el: IButtonEntry) => { return html` - + ${el.icon ? html`` : ''} ${PrettyPrintName(el.name)} @@ -232,10 +232,10 @@ export class SchedulerCard extends LitElement { getEntities(): TemplateResult[] { if (!this.selection.group) return [html`
${localize('instructions.no_group_selected')}
`]; let entities = this.Config.GetEntities(this.selection.group); - if (!size(entities)) return [html`
${localize('instructions.no_entities_for_group')}
`]; - return map(entities, (el: IButtonEntry, key: string) => { + if (!entities.length) return [html`
${localize('instructions.no_entities_for_group')}
`]; + return entities.map((el: IButtonEntry) => { return html` - + ${el.icon ? html`` : ''} ${PrettyPrintName(el.name)} @@ -254,10 +254,10 @@ export class SchedulerCard extends LitElement { getActions(): TemplateResult[] { if (!this.selection.entity) return [html`
${localize('instructions.no_entity_selected')}
`]; let actions = this.Config.GetActions(this.selection.entity); - if (!size(actions)) return [html`
${localize('instructions.no_actions_for_entity')}
`]; - return map(actions, (el: IButtonEntry, key: string) => { + if (!actions.length) return [html`
${localize('instructions.no_actions_for_entity')}
`]; + return actions.map((el: IButtonEntry) => { return html` - + ${el.icon ? html`` : ''} ${PrettyPrintName(el.name)} @@ -361,7 +361,7 @@ export class SchedulerCard extends LitElement {
${localize('fields.options')}
- ${this.selection.sun ? html`automatically adjust time to sunrise/sunset` : html`automatically adjust time to sunrise/sunset`} + ${this.selection.sun ? html`${localize('fields.shift_with_sun')}` : html`${localize('fields.shift_with_sun')}`}
diff --git a/src/types.ts b/src/types.ts index 937bc34b..59cf37c1 100755 --- a/src/types.ts +++ b/src/types.ts @@ -6,6 +6,7 @@ export interface IDictionary { export interface IButtonEntry { icon?: string, name: string, + key: string, } export interface IActionConfigEntry {