This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
area-views.js
44 lines (44 loc) · 29.4 KB
/
area-views.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var t={en:{climate:"Climate",automations:"Automations & Scripts",sensors:"Sensors",scenes:"Scenes"},nl:{climate:"Klimaat",automations:"Automatiseringen & Scripts",sensors:"Sensors",scenes:"Scenes"}};function e(t,e){if("string"==typeof e&&"string"==typeof t&&(t.startsWith("/")&&t.endsWith("/")||-1!==t.indexOf("*"))){return t.startsWith("/")||(t=`/^${t=t.replace(/\./g,".").replace(/\*/g,".*")}$/`),new RegExp(t.slice(1,-1)).test(e)}}function s(t,s){if(null==t||0==t.length)return!1;if(null==s||0==s.length)return!1;for(const e of s)if(t.includes(e))return!0;for(const i of t)for(const t of s)if(e(i,t))return!0;return!1}function i(t,s){return(void 0===s.domain||t.domain==s.domain)&&((void 0===s.device_class||t.device_class==s.device_class)&&!(void 0!==s.entity_id&&!e(s.entity_id,t.entity_id)))}function n(t,e){if(Array.isArray(e)){for(const s of e)for(const e of t)if(i(e,s))return e}else for(const s of t)if(i(s,e))return s;return null}function o(t,e){const s=t.toLowerCase(),i=e.toLowerCase();return s.includes(i)?t.length==e.length?t:s.replace(`${i}: `,"").replace(`: ${i}`,"").replace(` - ${i}`,"").replace(`${i} - `,"").replace(`${i} `,"").replace(` ${i}`,"").replace(i,"").trim().toLowerCase().replace(/\b(\w)/g,(t=>t.toUpperCase())):t}const r={cameras:{index:1},topbuttons:{index:2,card:{type:"grid",columns:3}},alarm:{index:3},media:{index:4},climate:{index:5,title:"climate",card:{type:"entities",show_header_toggle:!1},footer:{type:"graph",hours_to_show:24,entity:[{domain:"sensor",device_class:"temperature"},{domain:"sensor",device_class:"humidity"}]}},scenes:{index:6,title:"scenes",card:{type:"entities",show_header_toggle:!1}},sensors:{index:7,title:"sensors",card:{type:"entities",show_header_toggle:!1},footer:{type:"graph",hours_to_show:24,entity:[{domain:"sensor",device_class:"illuminance"}]}},automations:{index:8,title:"automations",card:{type:"entities",show_header_toggle:!1}}},a={type:"button",show_state:!0,card_mod:{style:"span { padding-left: 5px; padding-right: 5px; font-size: 14px; font-weight: 400;}; .state {font-size: 10px; font-weight: 100; color: var(--secondary-text-color);}"}},c={},d={...c,secondary_info:"last-changed"},l={...c,secondary_info:"last-triggered"},h=[{domain:"climate",card:c,group:"climate"},{domain:"sensor",device_class:"temperature",card:d,group:"climate"},{domain:"sensor",device_class:"humidity",card:d,group:"climate"},{domain:"humidifier",card:c,group:"climate"},{domain:"dehumidifier",card:c,group:"climate"},{domain:"switch",entity_id:"*humidifier*",card:c,group:"climate"},{domain:"sensor",entity_id:"*humidifier*",card:d,group:"climate"},{domain:"light",card:a,group:"topbuttons"},{domain:"switch",card:a,group:"topbuttons"},{domain:"input_boolean",card:a,group:"topbuttons"},{domain:"button",card:a,group:"topbuttons"},{domain:"fan",card:a,group:"topbuttons"},{domain:"cover",card:a,group:"topbuttons"},{domain:"camera",card:{type:"picture-entity",show_state:!1,show_name:!1},group:"cameras"},{domain:"media_player",card:{type:"media-control"},group:"media"},{domain:"automation",card:l,group:"automations"},{domain:"script",card:l,group:"automations"},{domain:"scene",card:l,group:"scenes"},{domain:"alarm_control_panel",card:{type:"alarm-panel"},group:"alarm"},{domain:"binary_sensor",card:d,group:"sensors"},{domain:"sensor",card:d,group:"sensors"},{card:c,group:"sensors"}],p=["device_tracker"];function u(t,e){for(const s of e)if(i(t,s))return s;return null}const m="default_view";function f(t,e,s,i){if(void 0===i)throw`No defaultValue given for ${s}`;const n=t.strategy,o=g(t,e),r=n[s],a=o[s];let c=i;for(const t of[r,a])try{void 0!==t&&Array.isArray(t)?c=0===c.length?t:Array.from(new Set(c.concat(t))):void 0!==t&&"object"==typeof t?c={...c,...t}:void 0!==t&&(c=t)}catch{console.error("Error while processing configuration",s)}return c}function g(t,e){return t.views.find((t=>t.path==e))||{}}class _{static async generateDashboard(t){const[e,s]=await Promise.all([t.hass.callWS({type:"config/area_registry/list"}),t.hass.callWS({type:"config/entity_registry/list"})]),i=new Map;for(const t of s)i.set(t.entity_id,t);return{...t.config,views:[{...g(t.config,m),strategy:{type:"custom:area-views"},title:f(t.config,m,"title","Home"),icon:f(t.config,m,"icon","mdi:home-assistant"),path:m},...e.map((e=>({...g(t.config,e.area_id),strategy:{type:"custom:area-views",options:{area:e,entities:this.getAreaEntities(t.hass,e,i,f(t.config,e.area_id,"include",[]),f(t.config,e.area_id,"exclude",p))}},title:f(t.config,e.area_id,"title",e.name),icon:f(t.config,e.area_id,"icon","mdi:home-assistant"),path:e.area_id}))).sort(((t,e)=>t.title.localeCompare(e.title))),...t.config.views.filter((t=>!t.path===m&&!e.find((e=>e.area_id==t.path))))]}}static async getAreaEntities(t,i,n,r,a){const c=await t.callWS({type:"search/related",item_type:"area",item_id:i.area_id}),d=new Set;for(const t of["entity","automation","script","scene"])void 0!==c[t]&&c[t].forEach((t=>d.add(t)));for(const s of r)if(t.states.hasOwnProperty(s))d.add(s);else for(const i in t.states)e(s,i)&&d.add(i);const l=[];for(const e of d){if(!e in t.states)continue;const r=n.get(e);if(r){if(["diagnostic","config"].includes(r.entity_category))continue;if(r.disabled_by)continue;if(r.area_id&&r.area_id!=i.area_id)continue}const c=t.states[e];if(!c){console.warn("No state found for entity",e);continue}const d=e.split(".")[0],h=c.attributes.device_class;let p=c.attributes.friendly_name;if(!p){console.warn("Unable to resolve name for entity",e);continue}s(a,[d,h,p,e])||(p=o(p,i.name),l.push({entity_id:e,domain:d,name:p,device_class:h}))}return l}static async generateView(e){if(e.view.path===m)return await this.generateHomeView(e);const s=e.view.strategy.options.area,i=await e.view.strategy.options.entities,o=f(e.config,s.area_id,"cards",[]),a=f(e.config,s.area_id,"group_schema",r),c=[],d=[];d.push(await this.getHeaderCard(e.config,e.view));const l={};for(const t of i){const e=u(t,[...c,...h]);if(!e)throw`Unable to detect card definition for entity ${t.entity_id}`;const s={...e.card,name:t.name,entity:t.entity_id};e.group in l?l[e.group].push(s):l[e.group]=[s]}for(const s in l){const o=l[s].sort(((t,e)=>t.name.localeCompare(e.name))),r=a[s];if(!r)throw`Unable to detect group definition for group ${s}`;if(!r.card){for(const t of o)d.push({...t,index:r.index});continue}const c={...r.card};if("entities"===c.type?c.entities=o:c.cards=o,r.footer){const t=n(i,r.footer.entity);t&&(c.footer={...r.footer,entity:t.entity_id})}r.title&&(c.title=(p=r.title,!(g=e.hass.locale.language)in t&&(g="en"),p?p in t[g]?t[g][p]:p in t.en?t.en[p]:p:p)),d.push({...c,index:r.index,entities:o})}var p,g;return d.push(...o),{cards:d.sort(((t,e)=>t.index-e.index))}}static async generateHomeView(t){const e=f(t.config,m,"cards",[]),s=f(t.config,m,"compact",!1),i=f(t.config,m,"group_schema",r),n=[];if(n.push(await this.getHeaderCard(t.config,t.view)),s){const e=[];for(const s of t.config.views){if(s.path==m)continue;if(void 0===s.strategy)continue;const t=await s.strategy.options.entities;let i=s.strategy.options.motion_entity;if(!i){const e=t.filter((t=>"motion"==t.device_class));e.length>0&&(i=e[0].entity_id)}if(!i){const e=t.filter((t=>"door"==t.device_class||"window"==t.device_class));e.length>0&&(i=e[0].entity_id)}e.push({...a,entity:i,name:s.title,show_state:!1,icon:s.icon,tap_action:{action:"navigate",navigation_path:s.path}})}e.sort(((t,e)=>t.name.localeCompare(e.name)));const s=i.topbuttons;n.push({...s.card,cards:e})}else for(const e of t.config.views)e.path!=m&&n.push({type:"area",area:e.path,show_camera:!0,navigation_path:e.path});for(const t of e)n.splice(t.index||99,0,t);return{cards:n}}static async getHeaderCard(t,e){const s=[];for(const e of t.views)s.push({name:e.title,icon:e.icon,path:e.path});return{type:"custom:area-header",options:s,current:{name:e.title,icon:e.icon,path:e.path},disable_menu:f(t,e.path,"disable_menu",!1)}}}const y="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,w=(t,e,s=null)=>{for(;e!==s;){const s=e.nextSibling;t.removeChild(e),e=s}},v=`{{lit-${String(Math.random()).slice(2)}}}`,S=`\x3c!--${v}--\x3e`,b=new RegExp(`${v}|${S}`);class x{constructor(t,e){this.parts=[],this.element=e;const s=[],i=[],n=document.createTreeWalker(e.content,133,null,!1);let o=0,r=-1,a=0;const{strings:c,values:{length:d}}=t;for(;a<d;){const t=n.nextNode();if(null!==t){if(r++,1===t.nodeType){if(t.hasAttributes()){const e=t.attributes,{length:s}=e;let i=0;for(let t=0;t<s;t++)C(e[t].name,"$lit$")&&i++;for(;i-- >0;){const e=c[a],s=A.exec(e)[2],i=s.toLowerCase()+"$lit$",n=t.getAttribute(i);t.removeAttribute(i);const o=n.split(b);this.parts.push({type:"attribute",index:r,name:s,strings:o}),a+=o.length-1}}"TEMPLATE"===t.tagName&&(i.push(t),n.currentNode=t.content)}else if(3===t.nodeType){const e=t.data;if(e.indexOf(v)>=0){const i=t.parentNode,n=e.split(b),o=n.length-1;for(let e=0;e<o;e++){let s,o=n[e];if(""===o)s=N();else{const t=A.exec(o);null!==t&&C(t[2],"$lit$")&&(o=o.slice(0,t.index)+t[1]+t[2].slice(0,-"$lit$".length)+t[3]),s=document.createTextNode(o)}i.insertBefore(s,t),this.parts.push({type:"node",index:++r})}""===n[o]?(i.insertBefore(N(),t),s.push(t)):t.data=n[o],a+=o}}else if(8===t.nodeType)if(t.data===v){const e=t.parentNode;null!==t.previousSibling&&r!==o||(r++,e.insertBefore(N(),t)),o=r,this.parts.push({type:"node",index:r}),null===t.nextSibling?t.data="":(s.push(t),r--),a++}else{let e=-1;for(;-1!==(e=t.data.indexOf(v,e+1));)this.parts.push({type:"node",index:-1}),a++}}else n.currentNode=i.pop()}for(const t of s)t.parentNode.removeChild(t)}}const C=(t,e)=>{const s=t.length-e.length;return s>=0&&t.slice(s)===e},P=t=>-1!==t.index,N=()=>document.createComment(""),A=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function E(t,e){const{element:{content:s},parts:i}=t,n=document.createTreeWalker(s,133,null,!1);let o=V(i),r=i[o],a=-1,c=0;const d=[];let l=null;for(;n.nextNode();){a++;const t=n.currentNode;for(t.previousSibling===l&&(l=null),e.has(t)&&(d.push(t),null===l&&(l=t)),null!==l&&c++;void 0!==r&&r.index===a;)r.index=null!==l?-1:r.index-c,o=V(i,o),r=i[o]}d.forEach((t=>t.parentNode.removeChild(t)))}const T=t=>{let e=11===t.nodeType?0:1;const s=document.createTreeWalker(t,133,null,!1);for(;s.nextNode();)e++;return e},V=(t,e=-1)=>{for(let s=e+1;s<t.length;s++){const e=t[s];if(P(e))return s}return-1};const U=new WeakMap,$=t=>"function"==typeof t&&U.has(t),k={},O={};class R{constructor(t,e,s){this.__parts=[],this.template=t,this.processor=e,this.options=s}update(t){let e=0;for(const s of this.__parts)void 0!==s&&s.setValue(t[e]),e++;for(const t of this.__parts)void 0!==t&&t.commit()}_clone(){const t=y?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),e=[],s=this.template.parts,i=document.createTreeWalker(t,133,null,!1);let n,o=0,r=0,a=i.nextNode();for(;o<s.length;)if(n=s[o],P(n)){for(;r<n.index;)r++,"TEMPLATE"===a.nodeName&&(e.push(a),i.currentNode=a.content),null===(a=i.nextNode())&&(i.currentNode=e.pop(),a=i.nextNode());if("node"===n.type){const t=this.processor.handleTextExpression(this.options);t.insertAfterNode(a.previousSibling),this.__parts.push(t)}else this.__parts.push(...this.processor.handleAttributeExpressions(a,n.name,n.strings,this.options));o++}else this.__parts.push(void 0),o++;return y&&(document.adoptNode(t),customElements.upgrade(t)),t}}const M=window.trustedTypes&&trustedTypes.createPolicy("lit-html",{createHTML:t=>t}),H=` ${v} `;class q{constructor(t,e,s,i){this.strings=t,this.values=e,this.type=s,this.processor=i}getHTML(){const t=this.strings.length-1;let e="",s=!1;for(let i=0;i<t;i++){const t=this.strings[i],n=t.lastIndexOf("\x3c!--");s=(n>-1||s)&&-1===t.indexOf("--\x3e",n+1);const o=A.exec(t);e+=null===o?t+(s?H:S):t.substr(0,o.index)+o[1]+o[2]+"$lit$"+o[3]+v}return e+=this.strings[t],e}getTemplateElement(){const t=document.createElement("template");let e=this.getHTML();return void 0!==M&&(e=M.createHTML(e)),t.innerHTML=e,t}}const z=t=>null===t||!("object"==typeof t||"function"==typeof t),I=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class L{constructor(t,e,s){this.dirty=!0,this.element=t,this.name=e,this.strings=s,this.parts=[];for(let t=0;t<s.length-1;t++)this.parts[t]=this._createPart()}_createPart(){return new W(this)}_getValue(){const t=this.strings,e=t.length-1,s=this.parts;if(1===e&&""===t[0]&&""===t[1]){const t=s[0].value;if("symbol"==typeof t)return String(t);if("string"==typeof t||!I(t))return t}let i="";for(let n=0;n<e;n++){i+=t[n];const e=s[n];if(void 0!==e){const t=e.value;if(z(t)||!I(t))i+="string"==typeof t?t:String(t);else for(const e of t)i+="string"==typeof e?e:String(e)}}return i+=t[e],i}commit(){this.dirty&&(this.dirty=!1,this.element.setAttribute(this.name,this._getValue()))}}class W{constructor(t){this.value=void 0,this.committer=t}setValue(t){t===k||z(t)&&t===this.value||(this.value=t,$(t)||(this.committer.dirty=!0))}commit(){for(;$(this.value);){const t=this.value;this.value=k,t(this)}this.value!==k&&this.committer.commit()}}class j{constructor(t){this.value=void 0,this.__pendingValue=void 0,this.options=t}appendInto(t){this.startNode=t.appendChild(N()),this.endNode=t.appendChild(N())}insertAfterNode(t){this.startNode=t,this.endNode=t.nextSibling}appendIntoPart(t){t.__insert(this.startNode=N()),t.__insert(this.endNode=N())}insertAfterPart(t){t.__insert(this.startNode=N()),this.endNode=t.endNode,t.endNode=this.startNode}setValue(t){this.__pendingValue=t}commit(){if(null===this.startNode.parentNode)return;for(;$(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=k,t(this)}const t=this.__pendingValue;t!==k&&(z(t)?t!==this.value&&this.__commitText(t):t instanceof q?this.__commitTemplateResult(t):t instanceof Node?this.__commitNode(t):I(t)?this.__commitIterable(t):t===O?(this.value=O,this.clear()):this.__commitText(t))}__insert(t){this.endNode.parentNode.insertBefore(t,this.endNode)}__commitNode(t){this.value!==t&&(this.clear(),this.__insert(t),this.value=t)}__commitText(t){const e=this.startNode.nextSibling,s="string"==typeof(t=null==t?"":t)?t:String(t);e===this.endNode.previousSibling&&3===e.nodeType?e.data=s:this.__commitNode(document.createTextNode(s)),this.value=t}__commitTemplateResult(t){const e=this.options.templateFactory(t);if(this.value instanceof R&&this.value.template===e)this.value.update(t.values);else{const s=new R(e,t.processor,this.options),i=s._clone();s.update(t.values),this.__commitNode(i),this.value=s}}__commitIterable(t){Array.isArray(this.value)||(this.value=[],this.clear());const e=this.value;let s,i=0;for(const n of t)s=e[i],void 0===s&&(s=new j(this.options),e.push(s),0===i?s.appendIntoPart(this):s.insertAfterPart(e[i-1])),s.setValue(n),s.commit(),i++;i<e.length&&(e.length=i,this.clear(s&&s.endNode))}clear(t=this.startNode){w(this.startNode.parentNode,t.nextSibling,this.endNode)}}class F{constructor(t,e,s){if(this.value=void 0,this.__pendingValue=void 0,2!==s.length||""!==s[0]||""!==s[1])throw new Error("Boolean attributes can only contain a single expression");this.element=t,this.name=e,this.strings=s}setValue(t){this.__pendingValue=t}commit(){for(;$(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=k,t(this)}if(this.__pendingValue===k)return;const t=!!this.__pendingValue;this.value!==t&&(t?this.element.setAttribute(this.name,""):this.element.removeAttribute(this.name),this.value=t),this.__pendingValue=k}}class B extends L{constructor(t,e,s){super(t,e,s),this.single=2===s.length&&""===s[0]&&""===s[1]}_createPart(){return new D(this)}_getValue(){return this.single?this.parts[0].value:super._getValue()}commit(){this.dirty&&(this.dirty=!1,this.element[this.name]=this._getValue())}}class D extends W{}let J=!1;(()=>{try{const t={get capture(){return J=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})();class K{constructor(t,e,s){this.value=void 0,this.__pendingValue=void 0,this.element=t,this.eventName=e,this.eventContext=s,this.__boundHandleEvent=t=>this.handleEvent(t)}setValue(t){this.__pendingValue=t}commit(){for(;$(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=k,t(this)}if(this.__pendingValue===k)return;const t=this.__pendingValue,e=this.value,s=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),i=null!=t&&(null==e||s);s&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),i&&(this.__options=G(t),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=t,this.__pendingValue=k}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const G=t=>t&&(J?{capture:t.capture,passive:t.passive,once:t.once}:t.capture);function Q(t){let e=X.get(t.type);void 0===e&&(e={stringsArray:new WeakMap,keyString:new Map},X.set(t.type,e));let s=e.stringsArray.get(t.strings);if(void 0!==s)return s;const i=t.strings.join(v);return s=e.keyString.get(i),void 0===s&&(s=new x(t,t.getTemplateElement()),e.keyString.set(i,s)),e.stringsArray.set(t.strings,s),s}const X=new Map,Y=new WeakMap;const Z=new class{handleAttributeExpressions(t,e,s,i){const n=e[0];if("."===n){return new B(t,e.slice(1),s).parts}if("@"===n)return[new K(t,e.slice(1),i.eventContext)];if("?"===n)return[new F(t,e.slice(1),s)];return new L(t,e,s).parts}handleTextExpression(t){return new j(t)}};"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.4.1");const tt=(t,...e)=>new q(t,e,"html",Z),et=(t,e)=>`${t}--${e}`;let st=!0;void 0===window.ShadyCSS?st=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/[email protected] and @webcomponents/[email protected]."),st=!1);const it=t=>e=>{const s=et(e.type,t);let i=X.get(s);void 0===i&&(i={stringsArray:new WeakMap,keyString:new Map},X.set(s,i));let n=i.stringsArray.get(e.strings);if(void 0!==n)return n;const o=e.strings.join(v);if(n=i.keyString.get(o),void 0===n){const s=e.getTemplateElement();st&&window.ShadyCSS.prepareTemplateDom(s,t),n=new x(e,s),i.keyString.set(o,n)}return i.stringsArray.set(e.strings,n),n},nt=["html","svg"],ot=new Set,rt=(t,e,s)=>{ot.add(t);const i=s?s.element:document.createElement("template"),n=e.querySelectorAll("style"),{length:o}=n;if(0===o)return void window.ShadyCSS.prepareTemplateStyles(i,t);const r=document.createElement("style");for(let t=0;t<o;t++){const e=n[t];e.parentNode.removeChild(e),r.textContent+=e.textContent}(t=>{nt.forEach((e=>{const s=X.get(et(e,t));void 0!==s&&s.keyString.forEach((t=>{const{element:{content:e}}=t,s=new Set;Array.from(e.querySelectorAll("style")).forEach((t=>{s.add(t)})),E(t,s)}))}))})(t);const a=i.content;s?function(t,e,s=null){const{element:{content:i},parts:n}=t;if(null==s)return void i.appendChild(e);const o=document.createTreeWalker(i,133,null,!1);let r=V(n),a=0,c=-1;for(;o.nextNode();)for(c++,o.currentNode===s&&(a=T(e),s.parentNode.insertBefore(e,s));-1!==r&&n[r].index===c;){if(a>0){for(;-1!==r;)n[r].index+=a,r=V(n,r);return}r=V(n,r)}}(s,r,a.firstChild):a.insertBefore(r,a.firstChild),window.ShadyCSS.prepareTemplateStyles(i,t);const c=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==c)e.insertBefore(c.cloneNode(!0),e.firstChild);else if(s){a.insertBefore(r,a.firstChild);const t=new Set;t.add(r),E(s,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const at={toAttribute(t,e){switch(e){case Boolean:return t?"":null;case Object:case Array:return null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){switch(e){case Boolean:return null!==t;case Number:return null===t?null:Number(t);case Object:case Array:return JSON.parse(t)}return t}},ct=(t,e)=>e!==t&&(e==e||t==t),dt={attribute:!0,type:String,converter:at,reflect:!1,hasChanged:ct};class lt extends HTMLElement{constructor(){super(),this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach(((e,s)=>{const i=this._attributeNameForProperty(s,e);void 0!==i&&(this._attributeToPropertyMap.set(i,s),t.push(i))})),t}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const t=Object.getPrototypeOf(this)._classProperties;void 0!==t&&t.forEach(((t,e)=>this._classProperties.set(e,t)))}}static createProperty(t,e=dt){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const s="symbol"==typeof t?Symbol():`__${t}`,i=this.getPropertyDescriptor(t,s,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}static getPropertyDescriptor(t,e,s){return{get(){return this[e]},set(i){const n=this[t];this[e]=i,this.requestUpdateInternal(t,n,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this._classProperties&&this._classProperties.get(t)||dt}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty("finalized")||t.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const t=this.properties,e=[...Object.getOwnPropertyNames(t),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t):[]];for(const s of e)this.createProperty(s,t[s])}}static _attributeNameForProperty(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}static _valueHasChanged(t,e,s=ct){return s(t,e)}static _propertyValueFromAttribute(t,e){const s=e.type,i=e.converter||at,n="function"==typeof i?i:i.fromAttribute;return n?n(t,s):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const s=e.type,i=e.converter;return(i&&i.toAttribute||at.toAttribute)(t,s)}initialize(){this._updateState=0,this._updatePromise=new Promise((t=>this._enableUpdatingResolver=t)),this._changedProperties=new Map,this._saveInstanceProperties(),this.requestUpdateInternal()}_saveInstanceProperties(){this.constructor._classProperties.forEach(((t,e)=>{if(this.hasOwnProperty(e)){const t=this[e];delete this[e],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(e,t)}}))}_applyInstanceProperties(){this._instanceProperties.forEach(((t,e)=>this[e]=t)),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,s){e!==s&&this._attributeToProperty(t,s)}_propertyToAttribute(t,e,s=dt){const i=this.constructor,n=i._attributeNameForProperty(t,s);if(void 0!==n){const t=i._propertyValueToAttribute(e,s);if(void 0===t)return;this._updateState=8|this._updateState,null==t?this.removeAttribute(n):this.setAttribute(n,t),this._updateState=-9&this._updateState}}_attributeToProperty(t,e){if(8&this._updateState)return;const s=this.constructor,i=s._attributeToPropertyMap.get(t);if(void 0!==i){const t=s.getPropertyOptions(i);this._updateState=16|this._updateState,this[i]=s._propertyValueFromAttribute(e,t),this._updateState=-17&this._updateState}}requestUpdateInternal(t,e,s){let i=!0;if(void 0!==t){const n=this.constructor;s=s||n.getPropertyOptions(t),n._valueHasChanged(this[t],e,s.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==s.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,s))):i=!1}!this._hasRequestedUpdate&&i&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(t,e){return this.requestUpdateInternal(t,e),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(t){}const t=this.performUpdate();return null!=t&&await t,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){if(!this._hasRequestedUpdate)return;this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{t=this.shouldUpdate(e),t?this.update(e):this._markUpdated()}catch(e){throw t=!1,this._markUpdated(),e}t&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._updatePromise}shouldUpdate(t){return!0}update(t){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach(((t,e)=>this._propertyToAttribute(e,this[e],t))),this._reflectingProperties=void 0),this._markUpdated()}updated(t){}firstUpdated(t){}}lt.finalized=!0;const ht=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,pt=Symbol();class ut{constructor(t,e){if(e!==pt)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){return void 0===this._styleSheet&&(ht?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}(window.litElementVersions||(window.litElementVersions=[])).push("2.5.1");const mt={};class ft extends lt{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,s)=>t.reduceRight(((t,s)=>Array.isArray(s)?e(s,t):(t.add(s),t)),s),s=e(t,new Set),i=[];s.forEach((t=>i.unshift(t))),this._styles=i}else this._styles=void 0===t?[]:[t];this._styles=this._styles.map((t=>{if(t instanceof CSSStyleSheet&&!ht){const e=Array.prototype.slice.call(t.cssRules).reduce(((t,e)=>t+e.cssText),"");return new ut(String(e),pt)}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(this.constructor.shadowRootOptions)}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?ht?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!==mt&&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 mt}}ft.finalized=!0,ft.render=(t,e,s)=>{if(!s||"object"!=typeof s||!s.scopeName)throw new Error("The `scopeName` option is required.");const i=s.scopeName,n=Y.has(e),o=st&&11===e.nodeType&&!!e.host,r=o&&!ot.has(i),a=r?document.createDocumentFragment():e;if(((t,e,s)=>{let i=Y.get(e);void 0===i&&(w(e,e.firstChild),Y.set(e,i=new j(Object.assign({templateFactory:Q},s))),i.appendInto(e)),i.setValue(t),i.commit()})(t,a,Object.assign({templateFactory:it(i)},s)),r){const t=Y.get(a);Y.delete(a);const s=t.value instanceof R?t.value.template:void 0;rt(i,a,s),w(e,e.firstChild),e.appendChild(a),Y.set(e,t)}!n&&o&&window.ShadyCSS.styleElement(e.host)},ft.shadowRootOptions={mode:"open"};class gt extends ft{render(){return tt`
<style>
table.header {
cursor: pointer;
width: 100%;
font-weight: 400px;
font-size: var(--app-toolbar-font-size, 20px);
--mdc-icon-size: 32px;
}
div.itemslist {
background-color: var(--sidebar-background-color);
}
paper-item {
cursor: pointer;
}
</style>
<div>
<table
class="header"
style="width:100%"
@click="${this._headerClicked}"
>
<tr>
<td width="10%">
<ha-icon icon="${this.current.icon}"></ha-icon>
</td>
<td width="80%">
<div style="margin-left:10px">${this.current.name}</div>
</td>
<td width="10%">
<ha-icon icon="mdi:menu-open"></ha-icon>
</td>
</tr>
</table>
<div class="itemslist" id="areaSelect" ?hidden="${!this.showAreas}">
${this.options.filter((t=>t.path!=this.current.path)).map((t=>tt`
<paper-item @click="${()=>this._itemClicked(t.path)}">
<ha-icon icon="${t.icon}"></ha-icon>
<span style="margin-left: 20px">${t.name}</span>
</paper-item>
`))}
</div>
</div>
`}setConfig(t){this.options=t.options,this.current=t.current,this.disableMenu=t.disable_menu,this.showAreas=!1}async _itemClicked(t){this.showAreas=!1,this._navigate(t)}async _headerClicked(t){this.disableMenu?this._navigate(0):(this.showAreas=!this.showAreas,this.requestUpdate())}async _navigate(t){history.pushState(null,"",t);const e=new Event("location-changed",{bubbles:!0,cancelable:!1,composed:!0});e.detail={},window.dispatchEvent(e)}getCardSize(){return 1}}var _t="0.0.1";customElements.get("ll-strategy-area-views")||(customElements.define("ll-strategy-area-views",_),customElements.define("area-header",gt),console.info(`%c AREA-VIEWS \n%c Version ${_t} `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"));