forked from andrey-git/home-assistant-custom-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate-card-custom-ui-es5.html
1 lines (1 loc) · 26.3 KB
/
state-card-custom-ui-es5.html
1
<div hidden="" by-polymer-bundler=""><script>window.customUI=window.customUI||{VERSION:"20171129",SUPPORTED_SLIDER_MODES:["single-line","break-slider","break-slider-toggle","hide-slider","no-slider"],domHost:function(t){if(t===document)return null;var e=t.getRootNode();return e instanceof DocumentFragment?e.host:e},lightOrShadow:function(t,e){return t.shadowRoot?t.shadowRoot.querySelector(e):t.querySelector(e)},getElementHierarchy:function(t,e){if(null===t)return null;var o=e.shift();return o?window.customUI.getElementHierarchy(window.customUI.lightOrShadow(t,o),e):t},getContext:function(t){if(void 0===t._context){t._context=[];for(var e="HA-ENTITIES-CARD"===t.tagName?window.customUI.domHost(t):t;e;e=window.customUI.domHost(e))switch(e.tagName){case"HA-ENTITIES-CARD":e.groupEntity?t._context.push(e.groupEntity.entity_id):!1===e.groupEntity&&e.states&&e.states.length&&t._context.push("group."+window.hassUtil.computeDomain(e.states[0]));break;case"MORE-INFO-GROUP":e.stateObj&&t._context.push(e.stateObj.entity_id);break;case"HA-CARDS":t._context.push(e.getAttribute("data-view")||"default_view")}t._context.reverse()}return t._context},maybeChangeObjectByDevice:function(t){var e=window.customUI.getName();if(!e)return t;if(!t.attributes.device||!t.attributes.device[e])return t;var o=Object.assign({},t.attributes.device[e]);return Object.keys(o).length?window.customUI.applyAttributes(t,o):t},maybeChangeObjectByGroup:function(t,e){var o=window.customUI.getContext(t);if(!o)return e;if(!e.attributes.group)return e;var i={};return o.forEach(function(t){e.attributes.group[t]&&Object.assign(i,e.attributes.group[t])}),Object.keys(i).length?window.customUI.applyAttributes(e,i):e},maybeApplyTemplates:function(t,e){if(!e.attributes.templates)return e;var o={};if(Object.keys(e.attributes.templates).forEach(function(i){var n=e.attributes.templates[i],s=window.customUI.computeTemplate(n,t.hass,t.hass.states,e,e.attributes,e.attributes[i],e.state);o[i]=s}),!Object.keys(o).length)return e;var i=window.customUI.applyAttributes(e,o);return Object.prototype.hasOwnProperty.call(o,"state")&&(i.state=o.state),Object.prototype.hasOwnProperty.call(o,"_stateDisplay")&&(i._stateDisplay=o._stateDisplay),i},applyAttributes:function(t,e){return{entity_id:t.entity_id,state:t.state,attributes:Object.assign({},t.attributes,e),last_changed:t.last_changed}},maybeChangeObject:function(t,e,o,i){if(o)return e;var n=window.customUI.maybeChangeObjectByDevice(e);return n=window.customUI.maybeChangeObjectByGroup(t,n),(n=window.customUI.maybeApplyTemplates(t,n))!==e&&n.attributes.hidden&&i?null:n},fixGroupTitles:function(){var t=window.customUI.getElementHierarchy(document,["home-assistant","home-assistant-main"]);if(null!==t){var e=window.customUI.getElementHierarchy(t,["partial-cards","ha-cards[view-visible]"]);if(null!==e){window.customUI.lightOrShadow(e,".main").querySelectorAll("ha-entities-card").forEach(function(t){if(t.groupEntity){var e=window.customUI.maybeChangeObject(t,t.groupEntity,!1,!1);if(e!==t.groupEntity&&e.attributes.friendly_name){window.customUI.lightOrShadow(t,".name").textContent=e.attributes.friendly_name}}})}}else window.setTimeout(window.customUI.fixGroupTitles,1e3)},showVersion:function(){if("/dev-info"===window.location.pathname){var t=window.customUI.getElementHierarchy(document,["home-assistant","home-assistant-main","partial-panel-resolver","ha-panel-dev-info"]);if(null!==t){var e=window.customUI.lightOrShadow(t,".about"),o=e.querySelectorAll("p")[1],i=document.createElement("p");i.textContent="Custom UI "+window.customUI.VERSION,e.insertBefore(i,o)}else window.setTimeout(window.customUI.showVersion,1e3)}},useCustomizer:function(){var t=window.customUI.lightOrShadow(document,"home-assistant").hass.states["customizer.customizer"];t&&t.attributes.hide_attributes&&(window.hassUtil.LOGIC_STATE_ATTRIBUTES&&Array.prototype.push.apply(window.hassUtil.LOGIC_STATE_ATTRIBUTES,t.attributes.hide_attributes),window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES&&t.attributes.hide_attributes.forEach(function(t){Object.prototype.hasOwnProperty.call(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES,t)||(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[t]=void 0)}))},updateAttributes:function(){var t={group:void 0,device:void 0,templates:void 0,state_card_mode:{type:"array",options:{light:window.customUI.SUPPORTED_SLIDER_MODES.concat("badges"),cover:window.customUI.SUPPORTED_SLIDER_MODES.concat("badges"),"*":["badges"]}},state_card_custom_ui_secondary:{type:"string"},badges_list:{type:"json"},show_last_changed:{type:"boolean"},hide_control:{type:"boolean"},extra_data_template:{type:"string"},extra_badge:{type:"json"},stretch_slider:{type:"boolean"},slider_theme:{type:"json"},theme:{type:"string"},confirm_controls:{type:"boolean"},confirm_controls_show_lock:{type:"boolean"}};window.hassUtil.LOGIC_STATE_ATTRIBUTES&&Array.prototype.push.apply(window.hassUtil.LOGIC_STATE_ATTRIBUTES,Object.keys(t)),window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES&&Object.assign(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES,t)},updateConfigPanel:function(){if(window.location.pathname.startsWith("/config")){var t=window.customUI.getElementHierarchy(document,["home-assistant","home-assistant-main","partial-panel-resolver","ha-panel-config"]);if(t){var e=window.customUI.lightOrShadow(t,"iron-pages");if(e){var o=window.customUI.getElementHierarchy(t,["ha-config-dashboard","ha-config-navigation"]);if(o){if("HA-CONFIG-CUSTOM-UI"!==e.lastElementChild.tagName){var i=document.createElement("ha-config-custom-ui");i.isWide=window.customUI.domHost(e).isWide,i.setAttribute("page-name","customui"),e.appendChild(i),e.addEventListener("iron-items-changed",function(){window.location.pathname.startsWith("/config/customui")&&e.select("customui")})}o.pages.some(function(t){return"customui"===t.domain})||o.push("pages",{domain:"customui",caption:"Custom UI",description:"Set UI tweaks.",loaded:!0})}}}else window.setTimeout(window.customUI.updateConfigPanel,1e3)}},init:function(){if(!window.customUI.initDone){var t=window.customUI.lightOrShadow(document,"home-assistant");t.hass&&t.hass.states?(window.customUI.initDone=!0,window.customUI.runHooks(),window.customUI.useCustomizer(),window.addEventListener("location-changed",window.setTimeout.bind(null,window.customUI.runHooks,100)),console.log("Loaded CustomUI "+window.customUI.VERSION)):window.setTimeout(window.customUI.init,1e3)}},runHooks:function(){window.customUI.fixGroupTitles(),window.customUI.showVersion(),window.customUI.updateAttributes(),window.customUI.updateConfigPanel()},getName:function(){return window.localStorage.getItem("ha-device-name")||""},setName:function(t){window.localStorage.setItem("ha-device-name",t||"")},computeTemplate:function(t,e,o,i,n,s,a){var r=t.indexOf("return")>=0?t:"return `"+t+"`;";try{return new Function("hass","entities","entity","attributes","attribute","state",r)(e,o,i,n,s,a)}catch(t){if(t instanceof SyntaxError||t instanceof ReferenceError)return console.warn(t.name+": "+t.message+" in template "+r),null;throw t}}},window.customUI.init();</script><dom-module id="ha-config-custom-ui"><template><style include="ha-style"></style><app-header-layout has-scrolling-region=""><app-header slot="header" fixed=""><app-toolbar><paper-icon-button icon="mdi:arrow-left" on-tap="_backTapped"></paper-icon-button><div main-title="">Custom UI settings</div></app-toolbar></app-header><ha-config-section is-wide="[[isWide]]"><paper-card heading="Device name"><div class="card-content">Set device name so that you can reference it in per-device settings<paper-input label="Name" value="{{name}}"></paper-input></div></paper-card></ha-config-section></app-header-layout></template></dom-module><script>function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),_get=function e(t,n,o){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,n);if(void 0===r){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,n,o)}if("value"in r)return r.value;var a=r.get;if(void 0!==a)return a.call(o)},HaConfigCustomUi=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return _inherits(t,Polymer.Element),_createClass(t,[{key:"ready",value:function(){_get(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"ready",this).call(this),this.name=window.customUI.getName()}},{key:"nameChanged",value:function(e){window.customUI.setName(e)}},{key:"_backTapped",value:function(){window.history.back()}}],[{key:"is",get:function(){return"ha-config-custom-ui"}},{key:"properties",get:function(){return{isWide:Boolean,name:{type:String,observer:"nameChanged"}}}}]),t}();customElements.define(HaConfigCustomUi.is,HaConfigCustomUi);</script><dom-module id="ha-themed-slider"><template><style>.disable-off-when-min{--paper-slider-pin-start-color:var(--paper-slider-pin-color)}.disable-off-when-min.is-on{--paper-slider-knob-start-color:var(--paper-slider-knob-color);--paper-slider-knob-start-border-color:var(--paper-slider-knob-color)}paper-slider{margin:4px 0;max-width:100%;min-width:100px;width:var(--ha-paper-slider-width,200px)}</style><paper-slider min="[[_themedMin]]" max="[[_computeAttribute(theme, "max", max)]]" pin="[[_computeAttribute(theme, "pin", pin)]]" class$="[[computeClass(theme, isOn, _themedMin)]]" value="[[value]]" on-change="valueChanged"></paper-slider></template></dom-module><script>Polymer({is:"ha-themed-slider",ready:function(){this.value=this.value+1,this.value=this.value-1,this.disableOffWhenMin=!this._computeAttribute(this.theme,"off_when_min",!this.disableOffWhenMin),this.computeEnabledThemedReportWhenNotChanged(this.theme,this.disableReportWhenNotChanged)},properties:{min:{type:Number,value:0},max:{type:Number,value:100},pin:{type:Boolean,value:!1},isOn:{type:Boolean,value:!1},disableOffWhenMin:{type:Boolean,value:!1,notify:!0},disableReportWhenNotChanged:{type:Boolean,value:!1},theme:{type:Object},value:{type:Number,notify:!0},_themedMin:{type:Number,computed:'_computeAttribute(theme, "min", min)'}},observers:["computeEnabledThemedReportWhenNotChanged(theme, disableReportWhenNotChanged)"],computeEnabledThemedReportWhenNotChanged:function(e,t){this._enabledThemedReportWhenNotChanged=this._computeAttribute(e,"report_when_not_changed",!t)},_computeAttribute:function(e,t,n){return e&&t in e?e[t]:n},computeClass:function(e,t,n){var h="";return t&&(h+="is-on "),this._computeAttribute(e,"off_when_min",!this.disableOffWhenMin)||0===n?"":h+"disable-off-when-min"},valueChanged:function(e){this._enabledThemedReportWhenNotChanged||this.value!==e.target.value?this.value=e.target.value:e.stopPropagation()}});</script><script>Polymer({is:"dynamic-element",properties:{hass:{type:Object},stateObj:{type:Object},elementName:{type:String},inDialog:{type:Boolean,value:!1}},observers:["observerFunc(hass, stateObj, elementName, inDialog)"],observerFunc:function(e,t,s,a){window.hassUtil.dynamicContentUpdater(this,s?s.toUpperCase():"DIV",{hass:e,stateObj:t,inDialog:a})}});</script><dom-module id="dynamic-with-extra"><template><style is="custom-style" include="iron-flex iron-flex-alignment iron-flex-factors"></style><style>:host{display:inline-block}.control-wrapper{margin-left:16px;position:relative}ha-state-label-badge{margin-left:8px}dynamic-element{display:block}#overlay{position:absolute;left:0;right:0;top:0;bottom:0;text-align:center}#lock{margin-top:8px;opacity:.3}.extra{margin-bottom:-16px;--ha-label-badge-size:36px;--ha-label-badge-font-size:1.2em}.state{@apply(--paper-font-body1);color:var(--primary-text-color);margin-left:16px;text-align:right;line-height:40px}</style><div class$="[[extraClass(extraObjVisible)]] horizontal layout"><template is="dom-if" if="[[extraObjVisible]]"><ha-state-label-badge hass="[[hass]]" state="[[extraObj]]"></ha-state-label-badge></template><template is="dom-if" if="[[_showControl(inDialog, stateObj)]]"><template is="dom-if" if="[[controlElement]]"><div class="control-wrapper"><dynamic-element class="flex" state-obj="[[stateObj]]" hass="[[hass]]" element-name="[[controlElement]]"></dynamic-element><template is="dom-if" if="[[isConfirmControls(stateObj)]]"><div id="overlay" on-tap="tapHandler"><template is="dom-if" if="[[stateObj.attributes.confirm_controls_show_lock]]"><iron-icon id="lock" icon="mdi:lock-outline"></iron-icon></template></div></template></div></template><template is="dom-if" if="[[!controlElement]]"><div class="state">[[computeStateDisplay(stateObj)]]</div></template></template></div></template></dom-module><script>function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),_get=function t(e,n,r){null===e&&(e=Function.prototype);var i=Object.getOwnPropertyDescriptor(e,n);if(void 0===i){var o=Object.getPrototypeOf(e);return null===o?void 0:t(o,n,r)}if("value"in i)return i.value;var a=i.get;if(void 0!==a)return a.call(r)},DynamicWithExtra=function(t){function e(){return _classCallCheck(this,e),_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return _inherits(e,StateCardDisplay||Polymer.Element),_createClass(e,[{key:"_getObject",value:function(t,e){if(!e.attributes.extra_badge)return null;var n=e.attributes.extra_badge;return n.entity_id&&t.states[n.entity_id]?Object.assign({},t.states[n.entity_id]):n.attribute&&e.attributes[n.attribute]?{state:e.attributes[n.attribute],_domain:"none",entity_id:null,attributes:{unit_of_measurement:n.unit}}:null}},{key:"computeExtra",value:function(t,e){var n=this._getObject(t,e);return n?(n._entityDisplay="",n):{_entityDisplay:"",_domain:"none",attributes:{}}}},{key:"computeExtraVisible",value:function(t,e,n){if(n)return!1;var r=this._getObject(t,e);if(!r)return!1;var i=e.attributes.extra_badge.blacklist_states;return!i||(Array.isArray(i)||(i=[i]),!i.some(function(t){return RegExp(t).test(r.state.toString())}))}},{key:"extraClass",value:function(t){return t?"extra":""}},{key:"_showControl",value:function(t,e){return!!t||!e.attributes.hide_control}},{key:"computeStateDisplay",value:function(t){return window.hassUtil.computeStateState?window.hassUtil.computeStateState(t):_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"computeStateDisplay",this).call(this,this.haLocalize,t)}},{key:"isConfirmControls",value:function(t){return t.attributes.confirm_controls||t.attributes.confirm_controls_show_lock}},{key:"tapHandler",value:function(t){var e=this;this.$$("#overlay").style.pointerEvents="none";var n=this.$$("#lock");n&&(n.icon="mdi:lock-open-outline",n.style.opacity="0.1"),window.setTimeout(function(){e.$$("#overlay").style.pointerEvents="",n&&(n.icon="mdi:lock-outline",n.style.opacity="")},5e3),t.stopPropagation()}}],[{key:"is",get:function(){return"dynamic-with-extra"}},{key:"properties",get:function(){return{hass:Object,inDialog:{type:Boolean,value:!1},stateObj:Object,controlElement:String,extraObj:{type:Object,computed:"computeExtra(hass, stateObj, inDialog)"},extraObjVisible:{type:Boolean,computed:"computeExtraVisible(hass, stateObj, inDialog)"}}}}]),e}();customElements.define(DynamicWithExtra.is,DynamicWithExtra);</script><dom-module id="state-card-with-slider"><template><style is="custom-style" include="iron-flex iron-flex-alignment iron-flex-factors"></style><style>.second-line,.state-and-toggle,.state-info{max-width:100%}.nowrap .state-and-toggle{overflow:hidden;flex-grow:0}.nowrap .second-line{overflow:hidden}.second-line{padding-top:20px;padding-bottom:16px;margin-top:-20px;margin-bottom:-16px}.stretch .second-line,.stretch ha-themed-slider{width:100%;--ha-paper-slider-width:100%}.nowrap .state-info{min-width:initial}.top-wrapper,ha-themed-slider{min-width:100px;max-width:100%}.top-wrapper.stretch{display:block}.hidden{display:none}</style><div id="container" class$="horizontal layout flex top-wrapper [[_computeWrapClass(mode, stretchSlider, lineTooLong, inDialog)]]"><div class="horizontal layout justified flex-auto state-and-toggle"><state-info class="state-info" state-obj="[[stateObj]]" in-dialog="[[showLastChanged(stateObj, inDialog, extra)]]" secondary-line$="[[extra]]"><template is="dom-if" if="[[extra]]"><span>[[extra]]</span></template></state-info><template is="dom-if" if="[[breakSlider]]" class="hidden"><dynamic-with-extra hass="[[hass]]" state-obj="[[stateObj]]" control-element="[[controlElement]]" in-dialog="[[inDialog]]"></dynamic-with-extra></template></div><template is="dom-if" if="[[showSlider]]"><div class="horizontal layout flex-auto end-justified second-line"><ha-themed-slider id="slider" max="[[max]]" min="[[min]]" theme="[[stateObj.attributes.slider_theme]]" is-on="[[isOn(stateObj, nameOn)]]" value="{{sliderValue}}" disable-off-when-min="{{disableOffWhenMin}}" on-change="sliderChanged" on-tap="stopPropagation"></ha-themed-slider><template is="dom-if" if="[[!breakSlider]]"><dynamic-with-extra hass="[[hass]]" state-obj="[[stateObj]]" control-element="[[controlElement]]" in-dialog="[[inDialog]]"></dynamic-with-extra></template></div></template></div></template></dom-module><script>var DEFAULT_MODE="no-slider";Polymer({is:"state-card-with-slider",attached:function(){var e=this;this.async(function(){e.readyToCompute=!0,e._onIronResize()},1)},behaviors:[Polymer.IronResizableBehavior],properties:{hass:{type:Object},inDialog:{type:Boolean,value:!1},stateObj:{type:Object},controlElement:{type:String},domain:{type:String},serviceMin:{type:String},serviceMax:{type:String},valueName:{type:String,value:"___"},setValueName:{type:String},nameOn:{type:String,value:"on"},min:{type:Number,value:0},max:{type:Number,value:255},sliderValue:{type:Number,value:0},disableOffWhenMin:{type:Boolean},mode:{type:String},stretchSlider:{type:Boolean,value:!1},breakSlider:{type:Boolean,value:!1},hideSlider:{type:Boolean,value:!1},lineTooLong:{type:Boolean,value:!1},minLineBreak:{type:Number,value:0},maxLineBreak:{type:Number,value:999},showSlider:{type:Number,computed:"_showSlider(inDialog, stateObj, hideSlider)"},extra:{type:String,computed:"computeExtra(hass, stateObj)"}},observers:["stateObjChanged(stateObj, nameOn, valueName)"],listeners:{"iron-resize":"_onIronResize"},_onIronResize:function(){if(this.readyToCompute){if("no-slider"===this.mode)return this.hideSlider=!0,void(this.breakSlider=!0);var e=this.breakSlider;this.lineTooLong=!1,this.hideSlider=!1,this.breakSlider=!1;var t=this.$.container,i=t.clientWidth;if(i<=this.minLineBreak)this.lineTooLong=!0;else if(i>=this.maxLineBreak)this.lineTooLong=!1;else{var a=t.clientHeight,s=this.$$(".state-info").clientHeight;this.lineTooLong=a>1.5*s,this.lineTooLong?this.minLineBreak=i:e||(this.maxLineBreak=i)}this.hideSlider="hide-slider"===this.mode&&this.lineTooLong,this.breakSlider=("break-slider"===this.mode||"hide-slider"===this.mode)&&this.lineTooLong,this.showSlider||(this.breakSlider=!0)}},_computeWrapClass:function(e,t,i,a){return a?"":"single-line"===e?"nowrap":t&&i?"stretch wrap":"wrap"},_showSlider:function(e,t,i){return!e&&!i&&1&t.attributes.supported_features},sliderChanged:function(e){var t=parseInt(e.target.value,10),i={entity_id:this.stateObj.entity_id};if(!Number.isNaN(t)){var a=this.$$("#slider");e.target!==a?a=e.target:e.path?a=e.path[0]:e.composedPath&&(a=e.composedPath()[0]),0===t||t<=a.min&&!this.disableOffWhenMin?this.hass.callService(this.domain,this.serviceMin,i):(i[this.setValueName||this.valueName]=t,this.hass.callService(this.domain,this.serviceMax,i))}},stateObjChanged:function(e,t,i){this.isOn(e,t)?this.sliderValue=e.attributes[i]:this.sliderValue=0,e&&(-1!==window.customUI.SUPPORTED_SLIDER_MODES.indexOf(e.attributes.state_card_mode)?this.mode=e.attributes.state_card_mode:this.mode=DEFAULT_MODE,e.attributes.stretch_slider&&(this.stretchSlider=!0))},isOn:function(e,t){return e&&e.state===t},stopPropagation:function(e){e.stopPropagation()},computeExtra:function(e,t){return t.attributes.extra_data_template?window.customUI.computeTemplate(t.attributes.extra_data_template,e,e.states,t,t.attributes,void 0,t.state):null},showLastChanged:function(e,t,i){return!!t||!i&&!!e.attributes.show_last_changed}});</script><script>function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var _createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),_get=function t(e,n,i){null===e&&(e=Function.prototype);var a=Object.getOwnPropertyDescriptor(e,n);if(void 0===a){var s=Object.getPrototypeOf(e);return null===s?void 0:t(s,n,i)}if("value"in a)return a.value;var o=a.get;if(void 0!==o)return o.call(i)},SHOW_LAST_CHANGED_BLACKLISTED_CARDS=["configurator"],StateCardCustomUi=function(t){function e(){return _classCallCheck(this,e),_possibleConstructorReturn(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return _inherits(e,Polymer.Element),_createClass(e,[{key:"connectedCallback",value:function(){_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"connectedCallback",this).call(this);var t=this.parentNode.parentNode;"DIV"===t.tagName&&(t.classList.contains("state")||t.classList.contains("child-card"))&&(this._container=t,t.style.setProperty("background-color","var(--paper-card-background-color, inherit)"),t.updateStyles||(t.updateStyles=function(e){Object.keys(e).forEach(function(n){t.style.setProperty(n,e[n])})})),this._isAttached=!0,this.inputChanged(this.hass,this.inDialog,this.stateObj)}},{key:"disconnectedCallback",value:function(){this._isAttached=!1,this._container&&(this._container.updateStyles({display:"",margin:"",padding:""}),window.hassUtil.applyThemesOnElement(this._container,this.hass.themes||{default_theme:"default",themes:{}},"default"),this._container=null),_get(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"disconnectedCallback",this).call(this)}},{key:"badgeMode",value:function(t,e,n){var i=this,a=[];if("group"===n)e.attributes.entity_id.forEach(function(n){var s=t.states[n];s?(!e.attributes.badges_list||e.attributes.badges_list.indexOf(s.entity_id)>=0)&&a.push(window.customUI.maybeChangeObject(i,s,!1,!1)):console.warn("Unknown ID "+n+" in group "+e.entity_id)});else if(a.push(e),this._container){this._container.style.display="inline-block";var s={display:"inline-block"};this._container.classList.contains("state")&&(s.margin="0 -6px"),this.updateStyles(s)}window.hassUtil.dynamicContentUpdater(this,"HA-BADGES-CARD",{hass:t,states:a}),this.style.setProperty("--ha-state-label-badge-margin-bottom","0")}},{key:"cleanBadgeStyle",value:function(){this._container&&(this._container.style.display=""),this.updateStyles({display:"",margin:""})}},{key:"applyThemes",value:function(t,e){var n=this,i="default";this._container&&(n=this._container),e.attributes.theme&&(i=e.attributes.theme),window.hassUtil.applyThemesOnElement(n,t.themes||{default_theme:"default",themes:{}},i)}},{key:"maybeHideEntity",value:function(t){return t?(this._container&&this._container.updateStyles({margin:"",padding:""}),!1):(this.lastChild&&this.removeChild(this.lastChild),this._container&&this._container.updateStyles({margin:"0",padding:"0"}),!0)}},{key:"inputChanged",value:function(t,e,n){if(n&&t&&this._isAttached){var i=window.hassUtil.computeDomain(n),a=window.customUI.maybeChangeObject(this,n,e,!0);if(!this.maybeHideEntity(a))if(this.applyThemes(t,a),e||"badges"!==a.attributes.state_card_mode){this.cleanBadgeStyle();var s={hass:t,stateObj:a,inDialog:e},o=window.hassUtil.stateCardType(t,n),r=a.attributes.state_card_custom_ui_secondary;"light"===i?Object.assign(s,{controlElement:"ha-entity-toggle",serviceMin:"turn_off",serviceMax:"turn_on",valueName:"brightness"}):"cover"===i?Object.assign(s,{controlElement:"ha-cover-controls",max:100,serviceMin:"close_cover",serviceMax:"set_cover_position",setValueName:"position",valueName:"current_position",nameOn:"open"}):"toggle"===o?Object.assign(s,{controlElement:"ha-entity-toggle"}):"display"===o&&Object.assign(s,{controlElement:""}),r||"light"!==i&&"cover"!==i&&"toggle"!==o&&"display"!==o?a.attributes.show_last_changed&&-1===SHOW_LAST_CHANGED_BLACKLISTED_CARDS.indexOf(o)&&(s.inDialog=!0):(o="with-slider",Object.assign(s,{domain:i}),"unavailable"===n.state&&Object.assign(s,{controlElement:""})),window.hassUtil.dynamicContentUpdater(this,r||"STATE-CARD-"+o.toUpperCase(),s)}else this.badgeMode(t,a,i)}}}],[{key:"is",get:function(){return"state-card-custom-ui"}},{key:"properties",get:function(){return{hass:Object,inDialog:{type:Boolean,value:!1},stateObj:Object}}},{key:"observers",get:function(){return["inputChanged(hass, inDialog, stateObj)"]}}]),e}();customElements.define(StateCardCustomUi.is,StateCardCustomUi);</script></div>