From f8b5e4c096933ec8e681a3f8a38db8234ee5bcdb Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Thu, 17 Oct 2019 19:06:38 -0500 Subject: [PATCH] add duration option --- README.md | 12 +++++++----- dist/restriction-card.js | 32 +++++++++++++------------------- src/restriction-card.ts | 22 ++++++++-------------- src/types.ts | 1 + 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 869fc89..53be5f6 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,10 @@ Hey dude! Help me out for a couple of :beers: or a :coffee:! This card is available in the [HACS (Home Assistant Community Store)](https://hacs.netlify.com) In your `resources` section add + ```yaml - - url: /community_plugin/restriction-card/restriction-card.js - type: module +- url: /community_plugin/restriction-card/restriction-card.js + type: module ``` ## Options @@ -41,6 +42,7 @@ In your `resources` section add | exemptions | list | **Optional** | List of exemption objects. See [Exemption Options](#exemption-options). | | condition | map | **Optional** | Conditional object to make lock active. See [Condition Options](#condition-options). | | row | boolean | **Optional** | Set to true to give a default `margin:left: 24px` | +| duration | number | **Optional** | Duration of unlock in seconds. Default is `5` | ## Restrictions Options @@ -156,14 +158,14 @@ Row example ![row](row.png) ```yaml -type: 'custom:hui-entities-card' +type: "custom:hui-entities-card" entities: - card: entity: cover.garage_door - type: 'custom:hui-cover-entity-row' + type: "custom:hui-cover-entity-row" restrictions: block: true - type: 'custom:restriction-card' + type: "custom:restriction-card" row: true - entity: light.kitchen ``` diff --git a/dist/restriction-card.js b/dist/restriction-card.js index 1671646..82f1e5d 100644 --- a/dist/restriction-card.js +++ b/dist/restriction-card.js @@ -91,7 +91,7 @@ class g{constructor(t,e,s){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 - */function A(t){let e=D.get(t.type);void 0===e&&(e={stringsArray:new WeakMap,keyString:new Map},D.set(t.type,e));let s=e.stringsArray.get(t.strings);if(void 0!==s)return s;const n=t.strings.join(a);return void 0===(s=e.keyString.get(n))&&(s=new h(t,t.getTemplateElement()),e.keyString.set(n,s)),e.stringsArray.set(t.strings,s),s}const D=new Map,O=new WeakMap; + */function A(t){let e=D.get(t.type);void 0===e&&(e={stringsArray:new WeakMap,keyString:new Map},D.set(t.type,e));let s=e.stringsArray.get(t.strings);if(void 0!==s)return s;const n=t.strings.join(a);return void 0===(s=e.keyString.get(n))&&(s=new h(t,t.getTemplateElement()),e.keyString.set(n,s)),e.stringsArray.set(t.strings,s),s}const D=new Map,V=new WeakMap; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -118,7 +118,7 @@ class g{constructor(t,e,s){this.__parts=[],this.template=t,this.processor=e,this * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.1.2");const V=(t,...e)=>new y(t,e,"html",T),R=133; +(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.1.2");const R=(t,...e)=>new y(t,e,"html",T),O=133; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -131,7 +131,7 @@ class g{constructor(t,e,s){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 - */function Y(t,e){const{element:{content:s},parts:n}=t,i=document.createTreeWalker(s,R,null,!1);let r=U(n),o=n[r],a=-1,c=0;const l=[];let d=null;for(;i.nextNode();){a++;const t=i.currentNode;for(t.previousSibling===d&&(d=null),e.has(t)&&(l.push(t),null===d&&(d=t)),null!==d&&c++;void 0!==o&&o.index===a;)o.index=null!==d?-1:o.index-c,o=n[r=U(n,r)]}l.forEach(t=>t.parentNode.removeChild(t))}const H=t=>{let e=11===t.nodeType?0:1;const s=document.createTreeWalker(t,R,null,!1);for(;s.nextNode();)e++;return e},U=(t,e=-1)=>{for(let s=e+1;st.parentNode.removeChild(t))}const H=t=>{let e=11===t.nodeType?0:1;const s=document.createTreeWalker(t,O,null,!1);for(;s.nextNode();)e++;return e},U=(t,e=-1)=>{for(let s=e+1;s`${t}--${e}`;let j=!0;void 0===window.ShadyCSS?j=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),j=!1);const z=t=>e=>{const s=L(e.type,t);let n=D.get(s);void 0===n&&(n={stringsArray:new WeakMap,keyString:new Map},D.set(s,n));let i=n.stringsArray.get(e.strings);if(void 0!==i)return i;const r=e.strings.join(a);if(void 0===(i=n.keyString.get(r))){const s=e.getTemplateElement();j&&window.ShadyCSS.prepareTemplateDom(s,t),i=new h(e,s),n.keyString.set(r,i)}return n.stringsArray.set(e.strings,i),i},F=["html","svg"],$=new Set,q=(t,e,s)=>{$.add(t);const n=s?s.element:document.createElement("template"),i=e.querySelectorAll("style"),{length:r}=i;if(0===r)return void window.ShadyCSS.prepareTemplateStyles(n,t);const o=document.createElement("style");for(let t=0;t{F.forEach(e=>{const s=D.get(L(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)}),Y(t,s)})})})(t);const a=n.content;s?function(t,e,s=null){const{element:{content:n},parts:i}=t;if(null==s)return void n.appendChild(e);const r=document.createTreeWalker(n,R,null,!1);let o=U(i),a=0,c=-1;for(;r.nextNode();){for(c++,r.currentNode===s&&(a=H(e),s.parentNode.insertBefore(e,s));-1!==o&&i[o].index===c;){if(a>0){for(;-1!==o;)i[o].index+=a,o=U(i,o);return}o=U(i,o)}}}(s,o,a.firstChild):a.insertBefore(o,a.firstChild),window.ShadyCSS.prepareTemplateStyles(n,t);const c=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==c)e.insertBefore(c.cloneNode(!0),e.firstChild);else if(s){a.insertBefore(o,a.firstChild);const t=new Set;t.add(o),Y(s,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const I={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}},B=(t,e)=>e!==t&&(e==e||t==t),W={attribute:!0,type:String,converter:I,reflect:!1,hasChanged:B},J=Promise.resolve(!0),Z=1,G=4,K=8,Q=16,X=32,tt="finalized";class et extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=J,this._hasConnectedResolver=void 0,this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach((e,s)=>{const n=this._attributeNameForProperty(s,e);void 0!==n&&(this._attributeToPropertyMap.set(n,s),t.push(n))}),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=W){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const s="symbol"==typeof t?Symbol():`__${t}`;Object.defineProperty(this.prototype,t,{get(){return this[s]},set(e){const n=this[t];this[s]=e,this._requestUpdate(t,n)},configurable:!0,enumerable:!0})}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty(tt)||t.finalize(),this[tt]=!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=B){return s(t,e)}static _propertyValueFromAttribute(t,e){const s=e.type,n=e.converter||I,i="function"==typeof n?n:n.fromAttribute;return i?i(t,s):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const s=e.type,n=e.converter;return(n&&n.toAttribute||I.toAttribute)(t,s)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_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._updateState=this._updateState|X,this._hasConnectedResolver&&(this._hasConnectedResolver(),this._hasConnectedResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,s){e!==s&&this._attributeToProperty(t,s)}_propertyToAttribute(t,e,s=W){const n=this.constructor,i=n._attributeNameForProperty(t,s);if(void 0!==i){const t=n._propertyValueToAttribute(e,s);if(void 0===t)return;this._updateState=this._updateState|K,null==t?this.removeAttribute(i):this.setAttribute(i,t),this._updateState=this._updateState&~K}}_attributeToProperty(t,e){if(this._updateState&K)return;const s=this.constructor,n=s._attributeToPropertyMap.get(t);if(void 0!==n){const t=s._classProperties.get(n)||W;this._updateState=this._updateState|Q,this[n]=s._propertyValueFromAttribute(e,t),this._updateState=this._updateState&~Q}}_requestUpdate(t,e){let s=!0;if(void 0!==t){const n=this.constructor,i=n._classProperties.get(t)||W;n._valueHasChanged(this[t],e,i.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==i.reflect||this._updateState&Q||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,i))):s=!1}!this._hasRequestedUpdate&&s&&this._enqueueUpdate()}requestUpdate(t,e){return this._requestUpdate(t,e),this.updateComplete}async _enqueueUpdate(){let t,e;this._updateState=this._updateState|G;const s=this._updatePromise;this._updatePromise=new Promise((s,n)=>{t=s,e=n});try{await s}catch(t){}this._hasConnected||await new Promise(t=>this._hasConnectedResolver=t);try{const t=this.performUpdate();null!=t&&await t}catch(t){e(t)}t(!this._hasRequestedUpdate)}get _hasConnected(){return this._updateState&X}get _hasRequestedUpdate(){return this._updateState&G}get hasUpdated(){return this._updateState&Z}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{(t=this.shouldUpdate(e))&&this.update(e)}catch(e){throw t=!1,e}finally{this._markUpdated()}t&&(this._updateState&Z||(this._updateState=this._updateState|Z,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=this._updateState&~G}get updateComplete(){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)}updated(t){}firstUpdated(t){}}et[tt]=!0; +const j=(t,e)=>`${t}--${e}`;let L=!0;void 0===window.ShadyCSS?L=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),L=!1);const z=t=>e=>{const s=j(e.type,t);let n=D.get(s);void 0===n&&(n={stringsArray:new WeakMap,keyString:new Map},D.set(s,n));let i=n.stringsArray.get(e.strings);if(void 0!==i)return i;const r=e.strings.join(a);if(void 0===(i=n.keyString.get(r))){const s=e.getTemplateElement();L&&window.ShadyCSS.prepareTemplateDom(s,t),i=new h(e,s),n.keyString.set(r,i)}return n.stringsArray.set(e.strings,i),i},F=["html","svg"],$=new Set,q=(t,e,s)=>{$.add(t);const n=s?s.element:document.createElement("template"),i=e.querySelectorAll("style"),{length:r}=i;if(0===r)return void window.ShadyCSS.prepareTemplateStyles(n,t);const o=document.createElement("style");for(let t=0;t{F.forEach(e=>{const s=D.get(j(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)}),Y(t,s)})})})(t);const a=n.content;s?function(t,e,s=null){const{element:{content:n},parts:i}=t;if(null==s)return void n.appendChild(e);const r=document.createTreeWalker(n,O,null,!1);let o=U(i),a=0,c=-1;for(;r.nextNode();){for(c++,r.currentNode===s&&(a=H(e),s.parentNode.insertBefore(e,s));-1!==o&&i[o].index===c;){if(a>0){for(;-1!==o;)i[o].index+=a,o=U(i,o);return}o=U(i,o)}}}(s,o,a.firstChild):a.insertBefore(o,a.firstChild),window.ShadyCSS.prepareTemplateStyles(n,t);const c=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==c)e.insertBefore(c.cloneNode(!0),e.firstChild);else if(s){a.insertBefore(o,a.firstChild);const t=new Set;t.add(o),Y(s,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const I={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}},B=(t,e)=>e!==t&&(e==e||t==t),W={attribute:!0,type:String,converter:I,reflect:!1,hasChanged:B},J=Promise.resolve(!0),Z=1,G=4,K=8,Q=16,X=32,tt="finalized";class et extends HTMLElement{constructor(){super(),this._updateState=0,this._instanceProperties=void 0,this._updatePromise=J,this._hasConnectedResolver=void 0,this._changedProperties=new Map,this._reflectingProperties=void 0,this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach((e,s)=>{const n=this._attributeNameForProperty(s,e);void 0!==n&&(this._attributeToPropertyMap.set(n,s),t.push(n))}),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=W){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const s="symbol"==typeof t?Symbol():`__${t}`;Object.defineProperty(this.prototype,t,{get(){return this[s]},set(e){const n=this[t];this[s]=e,this._requestUpdate(t,n)},configurable:!0,enumerable:!0})}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty(tt)||t.finalize(),this[tt]=!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=B){return s(t,e)}static _propertyValueFromAttribute(t,e){const s=e.type,n=e.converter||I,i="function"==typeof n?n:n.fromAttribute;return i?i(t,s):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const s=e.type,n=e.converter;return(n&&n.toAttribute||I.toAttribute)(t,s)}initialize(){this._saveInstanceProperties(),this._requestUpdate()}_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._updateState=this._updateState|X,this._hasConnectedResolver&&(this._hasConnectedResolver(),this._hasConnectedResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,s){e!==s&&this._attributeToProperty(t,s)}_propertyToAttribute(t,e,s=W){const n=this.constructor,i=n._attributeNameForProperty(t,s);if(void 0!==i){const t=n._propertyValueToAttribute(e,s);if(void 0===t)return;this._updateState=this._updateState|K,null==t?this.removeAttribute(i):this.setAttribute(i,t),this._updateState=this._updateState&~K}}_attributeToProperty(t,e){if(this._updateState&K)return;const s=this.constructor,n=s._attributeToPropertyMap.get(t);if(void 0!==n){const t=s._classProperties.get(n)||W;this._updateState=this._updateState|Q,this[n]=s._propertyValueFromAttribute(e,t),this._updateState=this._updateState&~Q}}_requestUpdate(t,e){let s=!0;if(void 0!==t){const n=this.constructor,i=n._classProperties.get(t)||W;n._valueHasChanged(this[t],e,i.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==i.reflect||this._updateState&Q||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,i))):s=!1}!this._hasRequestedUpdate&&s&&this._enqueueUpdate()}requestUpdate(t,e){return this._requestUpdate(t,e),this.updateComplete}async _enqueueUpdate(){let t,e;this._updateState=this._updateState|G;const s=this._updatePromise;this._updatePromise=new Promise((s,n)=>{t=s,e=n});try{await s}catch(t){}this._hasConnected||await new Promise(t=>this._hasConnectedResolver=t);try{const t=this.performUpdate();null!=t&&await t}catch(t){e(t)}t(!this._hasRequestedUpdate)}get _hasConnected(){return this._updateState&X}get _hasRequestedUpdate(){return this._updateState&G}get hasUpdated(){return this._updateState&Z}performUpdate(){this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{(t=this.shouldUpdate(e))&&this.update(e)}catch(e){throw t=!1,e}finally{this._markUpdated()}t&&(this._updateState&Z||(this._updateState=this._updateState|Z,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=this._updateState&~G}get updateComplete(){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)}updated(t){}firstUpdated(t){}}et[tt]=!0; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -183,7 +183,7 @@ found at http://polymer.github.io/PATENTS.txt * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -(window.litElementVersions||(window.litElementVersions=[])).push("2.2.1");const lt=t=>t.flat?t.flat(1/0):function t(e,s=[]){for(let n=0,i=e.length;n(t.add(e),t),new Set).forEach(t=>e.unshift(t))}else t&&e.push(t);return e}initialize(){super.initialize(),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?rt?this.renderRoot.adoptedStyleSheets=t.map(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){super.update(t);const e=this.render();e instanceof y&&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(){}}dt.finalized=!0,dt.render=(t,e,s)=>{if(!s||"object"!=typeof s||!s.scopeName)throw new Error("The `scopeName` option is required.");const n=s.scopeName,r=O.has(e),o=j&&11===e.nodeType&&!!e.host,a=o&&!$.has(n),c=a?document.createDocumentFragment():e;if(((t,e,s)=>{let n=O.get(e);void 0===n&&(i(e,e.firstChild),O.set(e,n=new x(Object.assign({templateFactory:A},s))),n.appendInto(e)),n.setValue(t),n.commit()})(t,c,Object.assign({templateFactory:z(n)},s)),a){const t=O.get(c);O.delete(c);const s=t.value instanceof g?t.value.template:void 0;q(n,c,s),i(e,e.firstChild),e.appendChild(c),O.set(e,t)}!r&&o&&window.ShadyCSS.styleElement(e.host)}; +(window.litElementVersions||(window.litElementVersions=[])).push("2.2.1");const lt=t=>t.flat?t.flat(1/0):function t(e,s=[]){for(let n=0,i=e.length;n(t.add(e),t),new Set).forEach(t=>e.unshift(t))}else t&&e.push(t);return e}initialize(){super.initialize(),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?rt?this.renderRoot.adoptedStyleSheets=t.map(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){super.update(t);const e=this.render();e instanceof y&&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(){}}dt.finalized=!0,dt.render=(t,e,s)=>{if(!s||"object"!=typeof s||!s.scopeName)throw new Error("The `scopeName` option is required.");const n=s.scopeName,r=V.has(e),o=L&&11===e.nodeType&&!!e.host,a=o&&!$.has(n),c=a?document.createDocumentFragment():e;if(((t,e,s)=>{let n=V.get(e);void 0===n&&(i(e,e.firstChild),V.set(e,n=new x(Object.assign({templateFactory:A},s))),n.appendInto(e)),n.setValue(t),n.commit()})(t,c,Object.assign({templateFactory:z(n)},s)),a){const t=V.get(c);V.delete(c);const s=t.value instanceof g?t.value.template:void 0;q(n,c,s),i(e,e.firstChild),e.appendChild(c),V.set(e,t)}!r&&o&&window.ShadyCSS.styleElement(e.host)}; /** * @license * Copyright (c) 2018 The Polymer Project Authors. All rights reserved. @@ -197,9 +197,9 @@ found at http://polymer.github.io/PATENTS.txt * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -const ht=new WeakMap,ut=(t=>(...s)=>{const n=t(...s);return e.set(n,!0),n})(t=>e=>{if(!(e instanceof b)||e instanceof N||"class"!==e.committer.name||e.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:s}=e,{element:n}=s;ht.has(e)||(n.className=s.strings.join(" "));const{classList:i}=n,r=ht.get(e);for(const e in r)e in t||i.remove(e);for(const e in t){const s=t[e];if(!r||s!==r[e]){i[s?"add":"remove"](e)}}ht.set(e,t)});var pt={},mt=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,ft="[^\\s]+",gt=/\[([^]*?)\]/gm,_t=function(){};function yt(t,e){for(var s=[],n=0,i=t.length;n3?0:(t-t%10!=10)*t%10]}};var Ct={D:function(t){return t.getDate()},DD:function(t){return St(t.getDate())},Do:function(t,e){return e.DoFn(t.getDate())},d:function(t){return t.getDay()},dd:function(t){return St(t.getDay())},ddd:function(t,e){return e.dayNamesShort[t.getDay()]},dddd:function(t,e){return e.dayNames[t.getDay()]},M:function(t){return t.getMonth()+1},MM:function(t){return St(t.getMonth()+1)},MMM:function(t,e){return e.monthNamesShort[t.getMonth()]},MMMM:function(t,e){return e.monthNames[t.getMonth()]},YY:function(t){return St(String(t.getFullYear()),4).substr(2)},YYYY:function(t){return St(t.getFullYear(),4)},h:function(t){return t.getHours()%12||12},hh:function(t){return St(t.getHours()%12||12)},H:function(t){return t.getHours()},HH:function(t){return St(t.getHours())},m:function(t){return t.getMinutes()},mm:function(t){return St(t.getMinutes())},s:function(t){return t.getSeconds()},ss:function(t){return St(t.getSeconds())},S:function(t){return Math.round(t.getMilliseconds()/100)},SS:function(t){return St(Math.round(t.getMilliseconds()/10),2)},SSS:function(t){return St(t.getMilliseconds(),3)},a:function(t,e){return t.getHours()<12?e.amPm[0]:e.amPm[1]},A:function(t,e){return t.getHours()<12?e.amPm[0].toUpperCase():e.amPm[1].toUpperCase()},ZZ:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+St(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)}},Nt={D:["\\d\\d?",function(t,e){t.day=e}],Do:["\\d\\d?"+ft,function(t,e){t.day=parseInt(e,10)}],M:["\\d\\d?",function(t,e){t.month=e-1}],YY:["\\d\\d?",function(t,e){var s=+(""+(new Date).getFullYear()).substr(0,2);t.year=""+(e>68?s-1:s)+e}],h:["\\d\\d?",function(t,e){t.hour=e}],m:["\\d\\d?",function(t,e){t.minute=e}],s:["\\d\\d?",function(t,e){t.second=e}],YYYY:["\\d{4}",function(t,e){t.year=e}],S:["\\d",function(t,e){t.millisecond=100*e}],SS:["\\d{2}",function(t,e){t.millisecond=10*e}],SSS:["\\d{3}",function(t,e){t.millisecond=e}],d:["\\d\\d?",_t],ddd:[ft,_t],MMM:[ft,vt("monthNamesShort")],MMMM:[ft,vt("monthNames")],a:[ft,function(t,e,s){var n=e.toLowerCase();n===s.amPm[0]?t.isPm=!1:n===s.amPm[1]&&(t.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(t,e){var s,n=(e+"").match(/([+-]|\d\d)/gi);n&&(s=60*n[1]+parseInt(n[2],10),t.timezoneOffset="+"===n[0]?s:-s)}]};Nt.dd=Nt.d,Nt.dddd=Nt.ddd,Nt.DD=Nt.D,Nt.mm=Nt.m,Nt.hh=Nt.H=Nt.HH=Nt.h,Nt.MM=Nt.M,Nt.ss=Nt.s,Nt.A=Nt.a,pt.masks={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},pt.format=function(t,e,s){var n=s||pt.i18n;if("number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date in fecha.format");e=pt.masks[e]||e||pt.masks.default;var i=[];return(e=(e=e.replace(gt,(function(t,e){return i.push(e),"@@@"}))).replace(mt,(function(e){return e in Ct?Ct[e](t,n):e.slice(1,e.length-1)}))).replace(/@@@/g,(function(){return i.shift()}))},pt.parse=function(t,e,s){var n=s||pt.i18n;if("string"!=typeof e)throw new Error("Invalid format in fecha.parse");if(e=pt.masks[e]||e,t.length>1e3)return null;var i={},r=[],o=[];e=e.replace(gt,(function(t,e){return o.push(e),"@@@"}));var a,c=(a=e,a.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(mt,(function(t){if(Nt[t]){var e=Nt[t];return r.push(e[1]),"("+e[0]+")"}return t}));c=c.replace(/@@@/g,(function(){return o.shift()}));var l=t.match(new RegExp(c,"i"));if(!l)return null;for(var d=1;d=":return n>=s;case">":return n>s;case"!=":return n!==s;case"regex":return n.match(s);default:return!1}};let Et=class extends dt{set hass(t){this._hass=t;const e=this.shadowRoot.querySelector("#card > *");e&&(e.hass=t)}getCardSize(){const t=this.shadowRoot.querySelector("#card > *");return t&&"function"==typeof(e=t).getCardSize?e.getCardSize():1;var e}setConfig(t){if(!t.card)throw new Error("Error in card configuration.");if(t.restrictions&&t.restrictions.pin&&!t.restrictions.pin.code)throw new Error("A pin code is required for pin restrictions");this._config=t}shouldUpdate(t){const e=t.get("hass");return!(!t.has("config")&&e)||!!(this._config&&this._config.condition&&this._config.condition.entity)&&e.states[this._config.condition.entity]!==this._hass.states[this._config.condition.entity]}render(){return this._config&&this._hass?this._config.restrictions&&this._matchRestriction(this._config.restrictions.hide)?V``:V` +const ht=new WeakMap,ut=(t=>(...s)=>{const n=t(...s);return e.set(n,!0),n})(t=>e=>{if(!(e instanceof b)||e instanceof N||"class"!==e.committer.name||e.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:s}=e,{element:n}=s;ht.has(e)||(n.className=s.strings.join(" "));const{classList:i}=n,r=ht.get(e);for(const e in r)e in t||i.remove(e);for(const e in t){const s=t[e];if(!r||s!==r[e]){i[s?"add":"remove"](e)}}ht.set(e,t)});var pt={},mt=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,ft="[^\\s]+",gt=/\[([^]*?)\]/gm,_t=function(){};function yt(t,e){for(var s=[],n=0,i=t.length;n3?0:(t-t%10!=10)*t%10]}};var Ct={D:function(t){return t.getDate()},DD:function(t){return St(t.getDate())},Do:function(t,e){return e.DoFn(t.getDate())},d:function(t){return t.getDay()},dd:function(t){return St(t.getDay())},ddd:function(t,e){return e.dayNamesShort[t.getDay()]},dddd:function(t,e){return e.dayNames[t.getDay()]},M:function(t){return t.getMonth()+1},MM:function(t){return St(t.getMonth()+1)},MMM:function(t,e){return e.monthNamesShort[t.getMonth()]},MMMM:function(t,e){return e.monthNames[t.getMonth()]},YY:function(t){return St(String(t.getFullYear()),4).substr(2)},YYYY:function(t){return St(t.getFullYear(),4)},h:function(t){return t.getHours()%12||12},hh:function(t){return St(t.getHours()%12||12)},H:function(t){return t.getHours()},HH:function(t){return St(t.getHours())},m:function(t){return t.getMinutes()},mm:function(t){return St(t.getMinutes())},s:function(t){return t.getSeconds()},ss:function(t){return St(t.getSeconds())},S:function(t){return Math.round(t.getMilliseconds()/100)},SS:function(t){return St(Math.round(t.getMilliseconds()/10),2)},SSS:function(t){return St(t.getMilliseconds(),3)},a:function(t,e){return t.getHours()<12?e.amPm[0]:e.amPm[1]},A:function(t,e){return t.getHours()<12?e.amPm[0].toUpperCase():e.amPm[1].toUpperCase()},ZZ:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+St(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)}},Nt={D:["\\d\\d?",function(t,e){t.day=e}],Do:["\\d\\d?"+ft,function(t,e){t.day=parseInt(e,10)}],M:["\\d\\d?",function(t,e){t.month=e-1}],YY:["\\d\\d?",function(t,e){var s=+(""+(new Date).getFullYear()).substr(0,2);t.year=""+(e>68?s-1:s)+e}],h:["\\d\\d?",function(t,e){t.hour=e}],m:["\\d\\d?",function(t,e){t.minute=e}],s:["\\d\\d?",function(t,e){t.second=e}],YYYY:["\\d{4}",function(t,e){t.year=e}],S:["\\d",function(t,e){t.millisecond=100*e}],SS:["\\d{2}",function(t,e){t.millisecond=10*e}],SSS:["\\d{3}",function(t,e){t.millisecond=e}],d:["\\d\\d?",_t],ddd:[ft,_t],MMM:[ft,vt("monthNamesShort")],MMMM:[ft,vt("monthNames")],a:[ft,function(t,e,s){var n=e.toLowerCase();n===s.amPm[0]?t.isPm=!1:n===s.amPm[1]&&(t.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(t,e){var s,n=(e+"").match(/([+-]|\d\d)/gi);n&&(s=60*n[1]+parseInt(n[2],10),t.timezoneOffset="+"===n[0]?s:-s)}]};Nt.dd=Nt.d,Nt.dddd=Nt.ddd,Nt.DD=Nt.D,Nt.mm=Nt.m,Nt.hh=Nt.H=Nt.HH=Nt.h,Nt.MM=Nt.M,Nt.ss=Nt.s,Nt.A=Nt.a,pt.masks={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},pt.format=function(t,e,s){var n=s||pt.i18n;if("number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date in fecha.format");e=pt.masks[e]||e||pt.masks.default;var i=[];return(e=(e=e.replace(gt,(function(t,e){return i.push(e),"@@@"}))).replace(mt,(function(e){return e in Ct?Ct[e](t,n):e.slice(1,e.length-1)}))).replace(/@@@/g,(function(){return i.shift()}))},pt.parse=function(t,e,s){var n=s||pt.i18n;if("string"!=typeof e)throw new Error("Invalid format in fecha.parse");if(e=pt.masks[e]||e,t.length>1e3)return null;var i={},r=[],o=[];e=e.replace(gt,(function(t,e){return o.push(e),"@@@"}));var a,c=(a=e,a.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(mt,(function(t){if(Nt[t]){var e=Nt[t];return r.push(e[1]),"("+e[0]+")"}return t}));c=c.replace(/@@@/g,(function(){return o.shift()}));var l=t.match(new RegExp(c,"i"));if(!l)return null;for(var d=1;d=":return n>=s;case">":return n>s;case"!=":return n!==s;case"regex":return n.match(s);default:return!1}};let Et=class extends dt{set hass(t){this._hass=t;const e=this.shadowRoot.querySelector("#card > *");e&&(e.hass=t)}getCardSize(){const t=this.shadowRoot.querySelector("#card > *");return t&&"function"==typeof(e=t).getCardSize?e.getCardSize():1;var e}setConfig(t){if(!t.card)throw new Error("Error in card configuration.");if(t.restrictions&&t.restrictions.pin&&!t.restrictions.pin.code)throw new Error("A pin code is required for pin restrictions");this._config=Object.assign({duration:5},t)}shouldUpdate(t){const e=t.get("hass");return!(!t.has("config")&&e)||!!(this._config&&this._config.condition&&this._config.condition.entity)&&e.states[this._config.condition.entity]!==this._hass.states[this._config.condition.entity]}render(){return this._config&&this._hass?this._config.restrictions&&this._matchRestriction(this._config.restrictions.hide)?R``:R`
- ${this._config.exemptions&&this._config.exemptions.some(t=>t.user===this._hass.user.id)||this._config.condition&&!kt(this._hass.states[this._config.condition.entity],this._config.condition)?"":V` + ${this._config.exemptions&&this._config.exemptions.some(t=>t.user===this._hass.user.id)||this._config.condition&&!kt(this._hass.states[this._config.condition.entity],this._config.condition)?"":R`
(...s)=>{const n=t(...s);return e.set(n,!0),n})(t=>e `} ${this.renderCard(this._config.card)}
- `:V``}renderCard(t){const e=Mt(t);return this._hass&&(e.hass=this._hass),V` + `:R``}renderCard(t){const e=Mt(t);return this._hass&&(e.hass=this._hass),R`
${e}
- `}_matchRestriction(t){return t&&(!t.exemptions||!t.exemptions.some(t=>t.user===this._hass.user.id))&&(!t.condition||kt(this._hass.states[t.condition.entity],t.condition))}_handleClick(){const t=this.shadowRoot.getElementById("lock");if(this._config.restrictions){if(this._matchRestriction(this._config.restrictions.block))return this._config.restrictions.block.text&&alert(this._config.restrictions.block.text),t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3);if(this._matchRestriction(this._config.restrictions.pin)){if(prompt(this._config.restrictions.pin.text||"Input pin code")!=this._config.restrictions.pin.code)return t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3)}if(this._matchRestriction(this._config.restrictions.confirm)&&!confirm(this._config.restrictions.confirm.text||"Are you sure you want to unlock?"))return}const e=this.shadowRoot.getElementById("overlay");e.style.setProperty("pointer-events","none"),t.classList.add("fadeOut"),window.setTimeout(()=>{e.style.setProperty("pointer-events",""),t&&t.classList.remove("fadeOut")},5e3)}static get styles(){return ct` + `}_matchRestriction(t){return t&&(!t.exemptions||!t.exemptions.some(t=>t.user===this._hass.user.id))&&(!t.condition||kt(this._hass.states[t.condition.entity],t.condition))}_handleClick(){const t=this.shadowRoot.getElementById("lock");if(this._config.restrictions){if(this._matchRestriction(this._config.restrictions.block))return this._config.restrictions.block.text&&alert(this._config.restrictions.block.text),t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3);if(this._matchRestriction(this._config.restrictions.pin)){if(prompt(this._config.restrictions.pin.text||"Input pin code")!=this._config.restrictions.pin.code)return t.classList.add("invalid"),void window.setTimeout(()=>{t&&t.classList.remove("invalid")},3e3)}if(this._matchRestriction(this._config.restrictions.confirm)&&!confirm(this._config.restrictions.confirm.text||"Are you sure you want to unlock?"))return}const e=this.shadowRoot.getElementById("overlay");e.style.setProperty("pointer-events","none"),t.classList.add("hidden"),window.setTimeout(()=>{e.style.setProperty("pointer-events",""),t&&t.classList.remove("hidden")},1e3*this._config.duration)}static get styles(){return ct` :host { display: block; position: relative; @@ -262,16 +262,10 @@ const ht=new WeakMap,ut=(t=>(...s)=>{const n=t(...s);return e.set(n,!0),n})(t=>e .row { margin-left: 24px !important; } - @keyframes fadeOut { - 20% { - opacity: 0; - } - 80% { - opacity: 0; - } - } - .fadeOut { - animation: fadeOut 5s linear; + .hidden { + visibility: hidden; + opacity: 0; + transition: visibility 0s 2s, opacity 2s linear; color: var(--success-lock-color); } @keyframes blinker { diff --git a/src/restriction-card.ts b/src/restriction-card.ts index dd5daf8..6a80ce4 100644 --- a/src/restriction-card.ts +++ b/src/restriction-card.ts @@ -56,7 +56,7 @@ class RestrictionCard extends LitElement implements LovelaceCard { throw new Error("A pin code is required for pin restrictions"); } - this._config = config; + this._config = { duration: 5, ...config }; } protected shouldUpdate(changedProps: PropertyValues): boolean { @@ -201,13 +201,13 @@ class RestrictionCard extends LitElement implements LovelaceCard { const overlay = this.shadowRoot!.getElementById("overlay") as LitElement; overlay.style.setProperty("pointer-events", "none"); - lock.classList.add("fadeOut"); + lock.classList.add("hidden"); window.setTimeout(() => { overlay.style.setProperty("pointer-events", ""); if (lock) { - lock.classList.remove("fadeOut"); + lock.classList.remove("hidden"); } - }, 5000); + }, this._config!.duration! * 1000); } static get styles(): CSSResult { @@ -255,16 +255,10 @@ class RestrictionCard extends LitElement implements LovelaceCard { .row { margin-left: 24px !important; } - @keyframes fadeOut { - 20% { - opacity: 0; - } - 80% { - opacity: 0; - } - } - .fadeOut { - animation: fadeOut 5s linear; + .hidden { + visibility: hidden; + opacity: 0; + transition: visibility 0s 2s, opacity 2s linear; color: var(--success-lock-color); } @keyframes blinker { diff --git a/src/types.ts b/src/types.ts index 56655df..8eb515c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,6 +6,7 @@ export interface RestrictionCardConfig extends LovelaceCardConfig { condition?: ConditionConfig; card?: LovelaceCardConfig; row?: boolean; + delay?: number; } export interface RestrictionsConfig {