core/homeassistant/components/frontend/www_static/frontend.html

725 lines
558 KiB
HTML
Raw Normal View History

<html><head><meta charset="UTF-8"></head><body><div hidden="" by-vulcanize=""><script>!function(){function e(){document.body.removeAttribute("unresolved")}window.WebComponents?addEventListener("WebComponentsReady",e):"interactive"===document.readyState||"complete"===document.readyState?e():addEventListener("DOMContentLoaded",e)}(),window.Polymer={Settings:function(){var e=window.Polymer||{};if(!e.noUrlSettings)for(var t,r=location.search.slice(1).split("&"),i=0;i<r.length&&(t=r[i]);i++)t=t.split("="),t[0]&&(e[t[0]]=t[1]||!0);return e.wantShadow="shadow"===e.dom,e.hasShadow=Boolean(Element.prototype.createShadowRoot),e.nativeShadow=e.hasShadow&&!window.ShadowDOMPolyfill,e.useShadow=e.wantShadow&&e.hasShadow,e.hasNativeImports=Boolean("import"in document.createElement("link")),e.useNativeImports=e.hasNativeImports,e.useNativeCustomElements=!window.CustomElements||window.CustomElements.useNative,e.useNativeShadow=e.useShadow&&e.nativeShadow,e.usePolyfillProto=!e.useNativeCustomElements&&!Object.__proto__,e.hasNativeCSSProperties=!navigator.userAgent.match("AppleWebKit/601")&&window.CSS&&CSS.supports&&CSS.supports("box-shadow","0 0 0 var(--foo)"),e.useNativeCSSProperties=e.hasNativeCSSProperties&&e.lazyRegister&&e.useNativeCSSProperties,e.isIE=navigator.userAgent.match("Trident"),e}()},function(){var e=window.Polymer;window.Polymer=function(e){"function"==typeof e&&(e=e.prototype),e||(e={}),e=t(e);var r=e===e.constructor.prototype?e.constructor:null,i={prototype:e};e.extends&&(i.extends=e.extends),Polymer.telemetry._registrate(e);var o=document.registerElement(e.is,i);return r||o};var t=function(e){var t=Polymer.Base;return e.extends&&(t=Polymer.Base._getExtendedPrototype(e.extends)),e=Polymer.Base.chainObject(e,t),e.registerCallback(),e};if(e)for(var r in e)Polymer[r]=e[r];Polymer.Class=function(e){return e.factoryImpl||(e.factoryImpl=function(){}),t(e).constructor}}(),Polymer.telemetry={registrations:[],_regLog:function(e){console.log("["+e.is+"]: registered")},_registrate:function(e){this.registrations.push(e),Polymer.log&&this._regLog(e)},dumpRegistrations:function(){this.registrations.forEach(this._regLog)}},Object.defineProperty(window,"currentImport",{enumerable:!0,configurable:!0,get:function(){return(document._currentScript||document.currentScript||{}).ownerDocument}}),Polymer.RenderStatus={_ready:!1,_callbacks:[],whenReady:function(e){this._ready?e():this._callbacks.push(e)},_makeReady:function(){this._ready=!0;for(var e=0;e<this._callbacks.length;e++)this._callbacks[e]();this._callbacks=[]},_catchFirstRender:function(){requestAnimationFrame(function(){Polymer.RenderStatus._makeReady()})},_afterNextRenderQueue:[],_waitingNextRender:!1,afterNextRender:function(e,t,r){this._watchNextRender(),this._afterNextRenderQueue.push([e,t,r])},hasRendered:function(){return this._ready},_watchNextRender:function(){if(!this._waitingNextRender){this._waitingNextRender=!0;var e=function(){Polymer.RenderStatus._flushNextRender()};this._ready?requestAnimationFrame(e):this.whenReady(e)}},_flushNextRender:function(){var e=this;setTimeout(function(){e._flushRenderCallbacks(e._afterNextRenderQueue),e._afterNextRenderQueue=[],e._waitingNextRender=!1})},_flushRenderCallbacks:function(e){for(var t,r=0;r<e.length;r++)t=e[r],t[1].apply(t[0],t[2]||Polymer.nar)}},window.HTMLImports?HTMLImports.whenReady(function(){Polymer.RenderStatus._catchFirstRender()}):Polymer.RenderStatus._catchFirstRender(),Polymer.ImportStatus=Polymer.RenderStatus,Polymer.ImportStatus.whenLoaded=Polymer.ImportStatus.whenReady,function(){"use strict";var e=Polymer.Settings;Polymer.Base={__isPolymerInstance__:!0,_addFeature:function(e){this.mixin(this,e)},registerCallback:function(){if("max"===e.lazyRegister)this.beforeRegister&&this.beforeRegister();else{this._desugarBehaviors();for(var t,r=0;r<this.behaviors.length;r++)t=this.behaviors[r],t.beforeRegister&&t.beforeRegister.call(this);this.beforeRegister&&this.beforeRegister()}this._registerFeatures(),e.lazyRegister||this.ensureRegisterFinished()},createdCallback:function(){if(e.disableUpgradeEnabled){if(this.hasAttribut
for(var e,t=this.shadyRoot._dirtyRoots,o=0,i=t.length;o<i&&(e=t[o]);o++)e._distributeContent();this.shadyRoot._dirtyRoots=[]},_finishDistribute:function(){if(this._useContent){if(this.shadyRoot._distributionClean=!0,h.hasInsertionPoint(this.shadyRoot))this._composeTree(),d(this.shadyRoot);else if(this.shadyRoot._hasDistributed){var e=this._composeNode(this);this._updateChildNodes(this,e)}else u.Composed.clearChildNodes(this),this.appendChild(this.shadyRoot);this.shadyRoot._hasDistributed||a(this),this.shadyRoot._hasDistributed=!0}},elementMatches:function(e,t){return t=t||this,h.matchesSelector.call(t,e)},_resetDistribution:function(){for(var e=u.Logical.getChildNodes(this),o=0;o<e.length;o++){var i=e[o];i._destinationInsertionPoints&&(i._destinationInsertionPoints=void 0),n(i)&&t(i)}for(var s=this.shadyRoot,r=s._insertionPoints,d=0;d<r.length;d++)r[d]._distributedNodes=[]},_collectPool:function(){for(var e=[],t=u.Logical.getChildNodes(this),o=0;o<t.length;o++){var i=t[o];n(i)?e.push.apply(e,i._distributedNodes):e.push(i)}return e},_distributePool:function(e,t){for(var i,n=e._insertionPoints,s=0,r=n.length;s<r&&(i=n[s]);s++)this._distributeInsertionPoint(i,t),o(i,this)},_distributeInsertionPoint:function(t,o){for(var i,n=!1,s=0,r=o.length;s<r;s++)(i=o[s])&&this._matchesContentSelect(i,t)&&(e(i,t),o[s]=void 0,n=!0);if(!n)for(var d=u.Logical.getChildNodes(t),a=0;a<d.length;a++)e(d[a],t)},_composeTree:function(){this._updateChildNodes(this,this._composeNode(this));for(var e,t,o=this.shadyRoot._insertionPoints,i=0,n=o.length;i<n&&(e=o[i]);i++)t=u.Logical.getParentNode(e),t._useContent||t===this||t===this.shadyRoot||this._updateChildNodes(t,this._composeNode(t))},_composeNode:function(e){for(var t=[],o=u.Logical.getChildNodes(e.shadyRoot||e),s=0;s<o.length;s++){var r=o[s];if(n(r))for(var d=r._distributedNodes,a=0;a<d.length;a++){var l=d[a];i(r,l)&&t.push(l)}else t.push(r)}return t},_updateChildNodes:function(e,t){for(var o,i=u.Composed.getChildNodes(e),n=Polymer.ArraySplice.calculateSplices(t,i),s=0,r=0;s<n.length&&(o=n[s]);s++){for(var d,a=0;a<o.removed.length&&(d=o.removed[a]);a++)u.Composed.getParentNode(d)===e&&u.Composed.removeChild(e,d),i.splice(o.index+r,1);r-=o.addedCount}for(var o,l,s=0;s<n.length&&(o=n[s]);s++)for(l=i[o.index],a=o.index,d;a<o.index+o.addedCount;a++)d=t[a],u.Composed.insertBefore(e,d,l),i.splice(a,0,d)},_matchesContentSelect:function(e,t){var o=t.getAttribute("select");return!o||(!(o=o.trim())||e instanceof Element&&(!!/^(:not\()?[*.#[a-zA-Z_|]/.test(o)&&this.elementMatches(o,e)))},_elementAdd:function(){},_elementRemove:function(){}});var c={get:function(){var e=Polymer.dom(this).getOwnerRoot();return e&&e.host},configurable:!0};Object.defineProperty(Polymer.Base,"domHost",c),Polymer.BaseDescriptors.domHost=c;var _=window.CustomElements&&!CustomElements.useNative}(),Polymer.Settings.useShadow&&Polymer.Base._addFeature({_poolContent:function(){},_beginDistribute:function(){},distributeContent:function(){},_distributeContent:function(){},_finishDistribute:function(){},_createLocalRoot:function(){this.createShadowRoot(),this.shadowRoot.appendChild(this.root),this.root=this.shadowRoot}}),Polymer.Async={_currVal:0,_lastVal:0,_callbacks:[],_twiddleContent:0,_twiddle:document.createTextNode(""),run:function(e,t){return t>0?~setTimeout(e,t):(this._twiddle.textContent=this._twiddleContent++,this._callbacks.push(e),this._currVal++)},cancel:function(e){if(e<0)clearTimeout(~e);else{var t=e-this._lastVal;if(t>=0){if(!this._callbacks[t])throw"invalid async handle: "+e;this._callbacks[t]=null}}},_atEndOfMicrotask:function(){for(var e=this._callbacks.length,t=0;t<e;t++){var o=this._callbacks[t];if(o)try{o()}catch(e){throw t++,this._callbacks.splice(0,t),this._lastVal+=t,this._twiddle.textContent=this._twiddleContent++,e}}this._callbacks.splice(0,e),this._lastVal+=e}},new window.MutationObserver(function(){Polymer.Async._atEndOfMicrotask()}).observe(Polymer.Async._twiddle,{characterData:!0}),Polymer.Debounce=function(){function e(e,t,i){return e?e.stop():e=new o(this),e.go(t,i),e}var t=Polymer.Async,o=function(e){t
},_configure:function(){this._configureAnnotationReferences(),this._configureInstanceProperties(),this._aboveConfig=this.mixin({},this._config);for(var e={},n=0;n<this.behaviors.length;n++)this._configureProperties(this.behaviors[n].properties,e);this._configureProperties(t?this.__proto__.properties:this.properties,e),this.mixin(e,this._aboveConfig),this._config=e,this._clients&&this._clients.length&&this._distributeConfig(this._config)},_configureInstanceProperties:function(){for(var t in this._propertyEffects)!e&&this.hasOwnProperty(t)&&(this._configValue(t,this[t]),delete this[t])},_configureProperties:function(e,t){for(var n in e){var r=e[n];if(void 0!==r.value){var s=r.value;"function"==typeof s&&(s=s.call(this,this._config)),t[n]=s}}},_distributeConfig:function(e){var t=this._propertyEffects;if(t)for(var n in e){var r=t[n];if(r)for(var s,i=0,o=r.length;i<o&&(s=r[i]);i++)if("annotation"===s.kind){var a=this._nodes[s.effect.index],l=s.effect.propertyName,c="attribute"==s.effect.kind,h=a._propertyEffects&&a._propertyEffects[l];if(a._configValue&&(h||!c)){var u=n===s.effect.value?e[n]:this._get(s.effect.value,e);u=this._computeFinalAnnotationValue(a,l,u,s.effect),c&&(u=a.deserialize(this.serialize(u),a._propertyInfo[l].type)),a._configValue(l,u)}}}},_afterClientsReady:function(){this._executeStaticEffects(),this._applyConfig(this._config,this._aboveConfig),this._flushHandlers()},_applyConfig:function(e,t){for(var n in e)void 0===this[n]&&this.__setProperty(n,e[n],n in t)},_notifyListener:function(e,t){if(!Polymer.Bind._isEventBogus(t,t.target)){var n,r;if(t.detail&&(n=t.detail.value,r=t.detail.path),this._clientsReadied)return e.call(this,t.target,n,r);this._queueHandler([e,t.target,n,r])}},_queueHandler:function(e){this._handlers.push(e)},_flushHandlers:function(){for(var e,t=this._handlers,n=0,r=t.length;n<r&&(e=t[n]);n++)e[0].call(this,e[1],e[2],e[3]);this._handlers=[]}})}(),function(){"use strict";var e=Polymer.Path;Polymer.Base._addFeature({notifyPath:function(e,t,n){var r={},s=this._get(e,this,r);1===arguments.length&&(t=s),r.path&&this._notifyPath(r.path,t,n)},_notifyPath:function(e,t,n){var r=this._propertySetter(e,t);if(r!==t&&(r===r||t===t))return this._pathEffector(e,t),n||this._notifyPathUp(e,t),!0},_getPathParts:function(e){if(Array.isArray(e)){for(var t=[],n=0;n<e.length;n++)for(var r=e[n].toString().split("."),s=0;s<r.length;s++)t.push(r[s]);return t}return e.toString().split(".")},set:function(e,t,n){var r,s=n||this,i=this._getPathParts(e),o=i[i.length-1];if(i.length>1){for(var a=0;a<i.length-1;a++){var l=i[a];if(r&&"#"==l[0]?s=Polymer.Collection.get(r).getItem(l):(s=s[l],r&&parseInt(l,10)==l&&(i[a]=Polymer.Collection.get(r).getKey(s))),!s)return;r=Array.isArray(s)?s:null}if(r){var c,h,u=Polymer.Collection.get(r);"#"==o[0]?(h=o,c=u.getItem(h),o=r.indexOf(c),u.setItem(h,t)):parseInt(o,10)==o&&(c=s[o],h=u.getKey(c),i[a]=h,u.setItem(h,t))}s[o]=t,n||this._notifyPath(i.join("."),t)}else s[e]=t},get:function(e,t){return this._get(e,t)},_get:function(e,t,n){for(var r,s=t||this,i=this._getPathParts(e),o=0;o<i.length;o++){if(!s)return;var a=i[o];r&&"#"==a[0]?s=Polymer.Collection.get(r).getItem(a):(s=s[a],n&&r&&parseInt(a,10)==a&&(i[o]=Polymer.Collection.get(r).getKey(s))),r=Array.isArray(s)?s:null}return n&&(n.path=i.join(".")),s},_pathEffector:function(t,n){var r=e.root(t),s=this._propertyEffects&&this._propertyEffects[r];if(s)for(var i,o=0;o<s.length&&(i=s[o]);o++){var a=i.pathFn;a&&a.call(this,t,n,i.effect)}this._boundPaths&&this._notifyBoundPaths(t,n)},_annotationPathEffect:function(t,n,r){if(e.matches(r.value,!1,t))Polymer.Bind._annotationEffect.call(this,t,n,r);else if(!r.negate&&e.isDescendant(r.value,t)){var s=this._nodes[r.index];if(s&&s._notifyPath){var i=e.translate(r.value,r.name,t);s._notifyPath(i,n,!0)}}},_complexObserverPathEffect:function(t,n,r){e.matches(r.trigger.name,r.trigger.wildcard,t)&&Polymer.Bind._complexObserverEffect.call(this,t,n,r)},_computePathEffect:function(t,n,r){e.matches(r.trigger.name,r.trigger.wildcard,t)&&Polymer.Bind._computeEffect.call(this,t,n,r)},_annotatedComputationPa
_styles:[],_properties:null,customStyle:{},_styleCache:new t,_element:Polymer.DomApi.wrap(document.documentElement),addStyle:function(e){this._styles.push(e),this._properties=null},get _styleProperties(){return this._properties||(e.decorateStyles(this._styles,this),this._styles._scopeStyleProperties=null,this._properties=e.hostAndRootPropertiesForScope(this).rootProps,e.mixinCustomStyle(this._properties,this.customStyle),e.reify(this._properties)),this._properties},hasStyleProperties:function(){return Boolean(this._properties)},_needsStyleProperties:function(){},_computeStyleProperties:function(){return this._styleProperties},updateStyles:function(t){this._properties=null,t&&Polymer.Base.mixin(this.customStyle,t),this._styleCache.clear();for(var r,s=0;s<this._styles.length;s++)r=this._styles[s],r=r.__importElement||r,r._apply();n&&e.updateNativeStyleProperties(document.documentElement,this.customStyle)}}}(),function(){"use strict";var e=Polymer.Base.serializeValueToAttribute,t=Polymer.StyleProperties,n=Polymer.StyleTransformer,r=Polymer.StyleDefaults,s=Polymer.Settings.useNativeShadow,i=Polymer.Settings.useNativeCSSProperties;Polymer.Base._addFeature({_prepStyleProperties:function(){i||(this._ownStylePropertyNames=this._styles&&this._styles.length?t.decorateStyles(this._styles,this):null)},customStyle:null,getComputedStyleValue:function(e){return i||this._styleProperties||this._computeStyleProperties(),!i&&this._styleProperties&&this._styleProperties[e]||getComputedStyle(this).getPropertyValue(e)},_setupStyleProperties:function(){this.customStyle={},this._styleCache=null,this._styleProperties=null,this._scopeSelector=null,this._ownStyleProperties=null,this._customStyle=null},_needsStyleProperties:function(){return Boolean(!i&&this._ownStylePropertyNames&&this._ownStylePropertyNames.length)},_validateApplyShim:function(){if(this.__applyShimInvalid){Polymer.ApplyShim.transform(this._styles,this.__proto__);var e=n.elementStyles(this);if(s){var t=this._template.content.querySelector("style");t&&(t.textContent=e)}else{var r=this._scopeStyle&&this._scopeStyle.nextSibling;r&&(r.textContent=e)}}},_beforeAttached:function(){this._scopeSelector&&!this.__stylePropertiesInvalid||!this._needsStyleProperties()||(this.__stylePropertiesInvalid=!1,this._updateStyleProperties())},_findStyleHost:function(){for(var e,t=this;e=Polymer.dom(t).getOwnerRoot();){if(Polymer.isInstance(e.host))return e.host;t=e.host}return r},_updateStyleProperties:function(){var e,n=this._findStyleHost();n._styleProperties||n._computeStyleProperties(),n._styleCache||(n._styleCache=new Polymer.StyleCache);var r=t.propertyDataFromStyles(n._styles,this),i=!this.__notStyleScopeCacheable;i&&(r.key.customStyle=this.customStyle,e=n._styleCache.retrieve(this.is,r.key,this._styles));var a=Boolean(e);a?this._styleProperties=e._styleProperties:this._computeStyleProperties(r.properties),this._computeOwnStyleProperties(),a||(e=o.retrieve(this.is,this._ownStyleProperties,this._styles));var l=Boolean(e)&&!a,c=this._applyStyleProperties(e);a||(c=c&&s?c.cloneNode(!0):c,e={style:c,_scopeSelector:this._scopeSelector,_styleProperties:this._styleProperties},i&&(r.key.customStyle={},this.mixin(r.key.customStyle,this.customStyle),n._styleCache.store(this.is,e,r.key,this._styles)),l||o.store(this.is,Object.create(e),this._ownStyleProperties,this._styles))},_computeStyleProperties:function(e){var n=this._findStyleHost();n._styleProperties||n._computeStyleProperties();var r=Object.create(n._styleProperties),s=t.hostAndRootPropertiesForScope(this);this.mixin(r,s.hostProps),e=e||t.propertyDataFromStyles(n._styles,this).properties,this.mixin(r,e),this.mixin(r,s.rootProps),t.mixinCustomStyle(r,this.customStyle),t.reify(r),this._styleProperties=r},_computeOwnStyleProperties:function(){for(var e,t={},n=0;n<this._ownStylePropertyNames.length;n++)e=this._ownStylePropertyNames[n],t[e]=this._styleProperties[e];this._ownStyleProperties=t},_scopeCount:0,_applyStyleProperties:function(e){var n=this._scopeSelector;this._scopeSelector=e?e._scopeSelector:this.is+"-"+this.__proto__._scopeCount++;var r=t.
2017-01-30 02:43:39 +00:00
window.hassUtil.DEFAULT_ICON = 'mdi:bookmark';
window.hassUtil.OFF_STATES = ['off', 'closed', 'unlocked'];
window.hassUtil.DOMAINS_WITH_CARD = [
'climate',
'cover',
'configurator',
'input_select',
'input_slider',
'media_player',
'scene',
'script',
'weblink',
];
window.hassUtil.DOMAINS_WITH_MORE_INFO = [
'alarm_control_panel', 'automation', 'camera', 'climate', 'configurator',
'cover', 'fan', 'group', 'light', 'lock', 'media_player', 'script',
'sun', 'updater',
];
window.hassUtil.DOMAINS_WITH_NO_HISTORY = ['camera', 'configurator', 'scene'];
window.hassUtil.HIDE_MORE_INFO = [
'input_select', 'scene', 'script', 'input_slider',
];
window.hassUtil.LANGUAGE = navigator.languages ?
navigator.languages[0] : navigator.language || navigator.userLanguage;
window.hassUtil.attributeClassNames = function (stateObj, attributes) {
if (!stateObj) return '';
return attributes.map(
function (attribute) {
return attribute in stateObj.attributes ? 'has-' + attribute : '';
}
).join(' ');
};
window.hassUtil.canToggleState = function (hass, stateObj) {
var domain = window.hassUtil.computeDomain(stateObj);
if (domain === 'group') {
return stateObj.state === 'on' || stateObj.state === 'off';
}
return window.hassUtil.canToggleDomain(hass, domain);
};
window.hassUtil.canToggleDomain = function (hass, domain) {
var turnOnService;
var services = hass.config.services[domain];
if (domain === 'lock') {
turnOnService = 'lock';
} else if (domain === 'cover') {
turnOnService = 'open_cover';
} else {
turnOnService = 'turn_on';
}
return services && turnOnService in services;
};
// Update root's child element to be newElementTag replacing another existing child if any.
// Copy attributes into the child element.
window.hassUtil.dynamicContentUpdater = function (root, newElementTag, attributes) {
var rootEl = Polymer.dom(root);
var customEl;
2017-02-25 23:03:14 +00:00
if (rootEl.lastChild && rootEl.lastChild.tagName === newElementTag) {
2017-01-30 02:43:39 +00:00
customEl = rootEl.lastChild;
} else {
if (rootEl.lastChild) {
rootEl.removeChild(rootEl.lastChild);
}
customEl = document.createElement(newElementTag);
}
Object.keys(attributes).forEach(function (key) {
customEl[key] = attributes[key];
});
if (customEl.parentNode === null) {
rootEl.appendChild(customEl);
}
};
// Check for support of native locale string options
function toLocaleStringSupportsOptions() {
try {
new Date().toLocaleString('i');
} catch (e) {
return e.name === 'RangeError';
}
return false;
}
function toLocaleDateStringSupportsOptions() {
try {
new Date().toLocaleDateString('i');
} catch (e) {
return e.name === 'RangeError';
}
return false;
}
function toLocaleTimeStringSupportsOptions() {
try {
new Date().toLocaleTimeString('i');
} catch (e) {
return e.name === 'RangeError';
}
return false;
}
window.fecha.masks.haDateTime = (window.fecha.masks.shortTime + ' ' +
window.fecha.masks.mediumDate);
if (toLocaleStringSupportsOptions()) {
window.hassUtil.formatDateTime = function (dateObj) {
return dateObj.toLocaleString(window.hassUtil.LANGUAGE, {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
});
};
} else {
window.hassUtil.formatDateTime = function (dateObj) {
return window.fecha.format(dateObj, 'haDateTime');
};
}
if (toLocaleDateStringSupportsOptions()) {
window.hassUtil.formatDate = function (dateObj) {
return dateObj.toLocaleDateString(window.hassUtil.LANGUAGE,
{ year: 'numeric', month: 'long', day: 'numeric' });
};
} else {
window.hassUtil.formatDate = function (dateObj) {
return window.fecha.format(dateObj, 'mediumDate');
};
}
if (toLocaleTimeStringSupportsOptions()) {
window.hassUtil.formatTime = function (dateObj) {
return dateObj.toLocaleTimeString(window.hassUtil.LANGUAGE,
{ hour: 'numeric', minute: '2-digit' });
};
} else {
window.hassUtil.formatTime = function (dateObj) {
return window.fecha.format(dateObj, 'shortTime');
};
}
window.hassUtil.relativeTime = function (dateObj) {
var delta = Math.abs(new Date() - dateObj) / 1000;
var format = new Date() > dateObj ? '%s ago' : 'in %s';
var tests = window.hassUtil.relativeTime.tests;
var i;
for (i = 0; i < tests.length; i += 2) {
if (delta < tests[i]) {
delta = Math.floor(delta);
return format.replace('%s',
delta === 1 ? '1 ' + tests[i + 1] : delta + ' ' + tests[i + 1] + 's');
}
delta /= tests[i];
}
delta = Math.floor(delta);
return format.replace('%s', delta === 1 ? '1 week' : delta + ' weeks');
};
window.hassUtil.relativeTime.tests = [
60, 'second',
60, 'minute',
24, 'hour',
7, 'day',
];
window.hassUtil.stateCardType = function (hass, stateObj) {
if (stateObj.state === 'unavailable') {
return 'display';
}
var domain = window.hassUtil.computeDomain(stateObj);
if (window.hassUtil.DOMAINS_WITH_CARD.indexOf(domain) !== -1) {
return domain;
} else if (window.hassUtil.canToggleState(hass, stateObj) &&
stateObj.attributes.control !== 'hidden') {
return 'toggle';
}
return 'display';
};
window.hassUtil.stateMoreInfoType = function (stateObj) {
var domain = window.hassUtil.computeDomain(stateObj);
if (window.hassUtil.DOMAINS_WITH_MORE_INFO.indexOf(domain) !== -1) {
return domain;
}
if (window.hassUtil.HIDE_MORE_INFO.indexOf(domain) !== -1) {
return 'hidden';
}
return 'default';
};
window.hassUtil.domainIcon = function (domain, state) {
switch (domain) {
case 'alarm_control_panel':
return state && state === 'disarmed' ? 'mdi:bell-outline' : 'mdi:bell';
case 'automation':
return 'mdi:playlist-play';
case 'binary_sensor':
return state && state === 'off' ? 'mdi:radiobox-blank' : 'mdi:checkbox-marked-circle';
2017-01-31 15:39:01 +00:00
case 'calendar':
return 'mdi:calendar';
2017-01-30 02:43:39 +00:00
case 'camera':
return 'mdi:video';
case 'climate':
return 'mdi:nest-thermostat';
case 'configurator':
return 'mdi:settings';
case 'conversation':
return 'mdi:text-to-speech';
case 'cover':
return state && state === 'open' ? 'mdi:window-open' : 'mdi:window-closed';
case 'device_tracker':
return 'mdi:account';
case 'fan':
return 'mdi:fan';
case 'group':
return 'mdi:google-circles-communities';
case 'homeassistant':
return 'mdi:home';
2017-01-31 15:39:01 +00:00
case 'image_processing':
return 'mdi:image-filter-frames';
2017-01-30 02:43:39 +00:00
case 'input_boolean':
return 'mdi:drawing';
case 'input_select':
return 'mdi:format-list-bulleted';
case 'input_slider':
return 'mdi:ray-vertex';
case 'light':
return 'mdi:lightbulb';
case 'lock':
return state && state === 'unlocked' ? 'mdi:lock-open' : 'mdi:lock';
case 'media_player':
return state && state !== 'off' && state !== 'idle' ?
'mdi:cast-connected' : 'mdi:cast';
case 'notify':
return 'mdi:comment-alert';
case 'proximity':
return 'mdi:apple-safari';
case 'remote':
return 'mdi:remote';
case 'scene':
return 'mdi:google-pages';
case 'script':
return 'mdi:file-document';
case 'sensor':
return 'mdi:eye';
case 'simple_alarm':
return 'mdi:bell';
case 'sun':
return 'mdi:white-balance-sunny';
case 'switch':
return 'mdi:flash';
case 'updater':
return 'mdi:cloud-upload';
case 'weblink':
return 'mdi:open-in-new';
default:
/* eslint-disable no-console */
console.warn(
'Unable to find icon for domain ' + domain + ' (' + state + ')');
/* eslint-enable no-console */
return window.hassUtil.DEFAULT_ICON;
}
};
window.hassUtil.binarySensorIcon = function (state) {
var activated = state.state && state.state === 'off';
2017-02-11 05:06:42 +00:00
switch (state.attributes.device_class) {
2017-01-30 02:43:39 +00:00
case 'connectivity':
return activated ? 'mdi:server-network-off' : 'mdi:server-network';
case 'light':
return activated ? 'mdi:brightness-5' : 'mdi:brightness-7';
case 'moisture':
return activated ? 'mdi:water-off' : 'mdi:water';
case 'motion':
return activated ? 'mdi:walk' : 'mdi:run';
case 'occupancy':
return activated ? 'mdi:home' : 'mdi:home-outline';
case 'opening':
return activated ? 'mdi:crop-square' : 'mdi:exit-to-app';
case 'sound':
return activated ? 'mdi:music-note-off' : 'mdi:music-note';
case 'vibration':
return activated ? 'mdi:crop-portrait' : 'mdi:vibrate';
case 'gas':
case 'power':
case 'safety':
case 'smoke':
return activated ? 'mdi:verified' : 'mdi:alert';
default:
return activated ? 'mdi:radiobox-blank' : 'mdi:checkbox-marked-circle';
}
};
2017-02-12 19:35:36 +00:00
window.hassUtil.coverIcon = function (state) {
var open = state.state && state.state === 'open';
switch (state.attributes.device_class) {
case 'garage':
return open ? 'mdi:garage-open' : 'mdi:garage';
default:
return open ? 'mdi:window-open' : 'mdi:window-closed';
}
};
2017-01-30 02:43:39 +00:00
window.hassUtil.stateIcon = function (state) {
if (!state) {
return window.hassUtil.DEFAULT_ICON;
} else if (state.attributes.icon) {
return state.attributes.icon;
}
var unit = state.attributes.unit_of_measurement;
var domain = window.hassUtil.computeDomain(state);
if (unit && domain === 'sensor') {
if (unit === '°C' || unit === '°F') {
return 'mdi:thermometer';
} else if (unit === 'Mice') {
return 'mdi:mouse-variant';
}
} else if (domain === 'binary_sensor') {
return window.hassUtil.binarySensorIcon(state);
2017-02-12 19:35:36 +00:00
} else if (domain === 'cover') {
return window.hassUtil.coverIcon(state);
2017-01-30 02:43:39 +00:00
}
return window.hassUtil.domainIcon(domain, state.state);
};
window.hassUtil.computeDomain = function (stateObj) {
if (!stateObj._domain) {
stateObj._domain = window.HAWS.extractDomain(stateObj.entity_id);
}
return stateObj._domain;
};
window.hassUtil.computeStateName = function (stateObj) {
2017-04-04 06:02:04 +00:00
if (stateObj._entityDisplay === undefined) {
2017-01-30 02:43:39 +00:00
stateObj._entityDisplay = (
stateObj.attributes.friendly_name ||
window.HAWS.extractObjectId(stateObj.entity_id)
.replace(/_/g, ' '));
}
return stateObj._entityDisplay;
};
window.hassUtil.computeStateState = function (stateObj) {
if (!stateObj._stateDisplay) {
stateObj._stateDisplay = stateObj.state.replace(/_/g, ' ');
if (stateObj.attributes.unit_of_measurement) {
stateObj._stateDisplay += ` ${stateObj.attributes.unit_of_measurement}`;
}
}
return stateObj._stateDisplay;
};
window.hassUtil.isComponentLoaded = function (hass, component) {
return hass.config.core.components.indexOf(component) !== -1;
};
window.hassUtil.computeLocationName = function (hass) {
return hass.config.core.location_name;
};</script><script>!function(){var t=["dockedSidebar"];Polymer({is:"ha-pref-storage",properties:{hass:{type:Object},storage:{type:Object,value:window.localStorage||{}}},storeState:function(){if(this.hass)try{for(var e=0;e<t.length;e++){var r=t[e];this.storage[r]=JSON.stringify(this.hass[r])}}catch(t){}},getStoredState:function(){for(var e={},r=0;r<t.length;r++){var a=t[r];a in this.storage&&(e[a]=JSON.parse(this.storage[a]))}return e}})}()</script><script>window.hassCallApi=function(e,t,s,o,a){var r=e+"/api/"+o;if(window.HASS_DEMO){var n,i=o.split("/",1)[0];switch(i){case"bootstrap":n=window.hassDemoData.bootstrap;break;case"logbook":n=window.hassDemoData.logbook;break;case"history":n=window.hassDemoData.stateHistory;break;default:n=!1}return new Promise(function(e,t){n?e(n):t("Request not allowed in demo mode.")})}return new Promise(function(e,o){var n=new XMLHttpRequest;n.open(s,r,!0),t.authToken&&n.setRequestHeader("X-HA-access",t.authToken),n.onload=function(){var t=n.responseText;if("application/json"===n.getResponseHeader("content-type"))try{t=JSON.parse(n.responseText)}catch(e){return void o({error:"Unable to parse JSON response",status_code:n.status,body:t})}n.status>199&&n.status<300?e(t):o({error:"Response error: "+n.status,status_code:n.status,body:t})},n.onerror=function(){o({error:"Request error",status_code:n.status,body:n.responseText})},a?(n.setRequestHeader("Content-Type","application/json;charset=UTF-8"),n.send(JSON.stringify(a))):n.send()})}</script><style is="custom-style">:root{--primary-text-color:var(--light-theme-text-color);--primary-background-color:var(--light-theme-background-color);--secondary-text-color:var(--light-theme-secondary-color);--disabled-text-color:var(--light-theme-disabled-color);--divider-color:var(--light-theme-divider-color);--error-color:var(--paper-deep-orange-a700);--primary-color:var(--paper-indigo-500);--light-primary-color:var(--paper-indigo-100);--dark-primary-color:var(--paper-indigo-700);--accent-color:var(--paper-pink-a200);--light-accent-color:var(--paper-pink-a100);--dark-accent-color:var(--paper-pink-a400);--light-theme-background-color:#ffffff;--light-theme-base-color:#000000;--light-theme-text-color:var(--paper-grey-900);--light-theme-secondary-color:#737373;--light-theme-disabled-color:#9b9b9b;--light-theme-divider-color:#dbdbdb;--dark-theme-background-color:var(--paper-grey-900);--dark-theme-base-color:#ffffff;--dark-theme-text-color:#ffffff;--dark-theme-secondary-color:#bcbcbc;--dark-theme-disabled-color:#646464;--dark-theme-divider-color:#3c3c3c;--text-primary-color:var(--dark-theme-text-color);--default-primary-color:var(--primary-color)}</style><script>!function(){var e={},t={},i=null;Polymer.IronMeta=Polymer({is:"iron-meta",properties:{type:{type:String,value:"default",observer:"_typeChanged"},key:{type:String,observer:"_keyChanged"},value:{type:Object,notify:!0,observer:"_valueChanged"},self:{type:Boolean,observer:"_selfChanged"},list:{type:Array,notify:!0}},hostAttributes:{hidden:!0},factoryImpl:function(e){if(e)for(var t in e)switch(t){case"type":case"key":case"value":this[t]=e[t]}},created:function(){this._metaDatas=e,this._metaArrays=t},_keyChanged:function(e,t){this._resetRegistration(t)},_valueChanged:function(e){this._resetRegistration(this.key)},_selfChanged:function(e){e&&(this.value=this)},_typeChanged:function(i){this._unregisterKey(this.key),e[i]||(e[i]={}),this._metaData=e[i],t[i]||(t[i]=[]),this.list=t[i],this._registerKeyValue(this.key,this.value)},byKey:function(e){return this._metaData&&this._metaData[e]},_resetRegistration:function(e){this._unregisterKey(e),this._registerKeyValue(this.key,this.value)},_unregisterKey:function(e){this._unregister(e,this._metaData,this.list)},_registerKeyValue:function(e,t){this._register(e,t,this._metaData,this.list)},_register:function(e,t,i,a){e&&i&&void 0!==t&&(i[e]=t,a.push(t))},_unregister:function(e,t,i){if(e&&t&&e in t){var a=t[e];delete t[e],this.arrayDelete(i,a)}}}),Polymer.IronMeta.getIronMeta=function(){return null===i&&(i=new Polymer.IronMeta),i},Polymer.IronMetaQuery=Polymer({is:"iron-meta-
2017-02-21 05:56:38 +00:00
window.CoverEntity = function (hass, stateObj) {
this.hass = hass;
this.stateObj = stateObj;
};
function addGetter(name, getter) {
Object.defineProperty(window.CoverEntity.prototype, name,
{ get: getter });
}
addGetter('isFullyOpen', function () {
if (this.stateObj.attributes.current_position !== undefined) {
return this.stateObj.attributes.current_position === 100;
}
return this.stateObj.state === 'open';
});
addGetter('isFullyClosed', function () {
if (this.stateObj.attributes.current_position !== undefined) {
return this.stateObj.attributes.current_position === 0;
}
return this.stateObj.state === 'closed';
});
addGetter('isFullyOpenTilt', function () {
return this.stateObj.attributes.current_tilt_position === 100;
});
addGetter('isFullyClosedTilt', function () {
return this.stateObj.attributes.current_tilt_position === 0;
});
/* eslint-disable no-bitwise */
addGetter('supportsOpen', function () {
return (this.stateObj.attributes.supported_features & 1) !== 0;
});
addGetter('supportsClose', function () {
return (this.stateObj.attributes.supported_features & 2) !== 0;
});
addGetter('supportsSetPosition', function () {
return (this.stateObj.attributes.supported_features & 4) !== 0;
});
addGetter('supportsStop', function () {
return (this.stateObj.attributes.supported_features & 8) !== 0;
});
addGetter('supportsOpenTilt', function () {
return (this.stateObj.attributes.supported_features & 16) !== 0;
});
addGetter('supportsCloseTilt', function () {
return (this.stateObj.attributes.supported_features & 32) !== 0;
});
addGetter('supportsStopTilt', function () {
return (this.stateObj.attributes.supported_features & 64) !== 0;
});
addGetter('supportsSetTiltPosition', function () {
return (this.stateObj.attributes.supported_features & 128) !== 0;
});
/* eslint-enable no-bitwise */
Object.assign(window.CoverEntity.prototype, {
openCover() {
this.callService('open_cover');
},
closeCover() {
this.callService('close_cover');
},
stopCover() {
this.callService('stop_cover');
},
openCoverTilt() {
this.callService('open_cover_tilt');
},
closeCoverTilt() {
this.callService('close_cover_tilt');
},
stopCoverTilt() {
this.callService('stop_cover_tilt');
},
setCoverPosition(position) {
this.callService('set_cover_position', { position: position });
},
setCoverTiltPosition(tiltPosition) {
this.callService('set_cover_tilt_position', { tilt_position: tiltPosition });
},
// helper method
callService(service, data) {
var serviceData = data || {};
serviceData.entity_id = this.stateObj.entity_id;
this.hass.callService('cover', service, serviceData);
},
});
}());</script><dom-module id="ha-cover-controls" assetpath="components/"><template><style>.state{white-space:nowrap}[invisible]{visibility:hidden!important}</style><div class="state"><paper-icon-button icon="mdi:arrow-up" on-tap="onOpenTap" invisible$="[[!entityObj.supportsOpen]]" disabled="[[entityObj.isFullyOpen]]"></paper-icon-button><paper-icon-button icon="mdi:stop" on-tap="onStopTap" invisible$="[[!entityObj.supportsStop]]"></paper-icon-button><paper-icon-button icon="mdi:arrow-down" on-tap="onCloseTap" invisible$="[[!entityObj.supportsClose]]" disabled="[[entityObj.isFullyClosed]]"></paper-icon-button></div></template></dom-module><script>Polymer({is:"ha-cover-controls",properties:{hass:{type:Object},stateObj:{type:Object},entityObj:{type:Object,computed:"computeEntityObj(hass, stateObj)"}},computeEntityObj:function(t,o){return new window.CoverEntity(t,o)},onOpenTap:function(t){t.stopPropagation(),this.entityObj.openCover()},onCloseTap:function(t){t.stopPropagation(),this.entityObj.closeCover()},onStopTap:function(t){t.stopPropagation(),this.entityObj.stopCover()}})</script><dom-module id="state-card-cover" assetpath="state-summary/"><template><style is="custom-style" include="iron-flex iron-flex-alignment"></style><style>:host{line-height:1.5}</style><div class="horizontal justified layout"><state-info state-obj="[[stateObj]]" in-dialog="[[inDialog]]"></state-info><ha-cover-controls hass="[[hass]]" state-obj="[[stateObj]]"></ha-cover-controls></div></template></dom-module><script>Polymer({is:"state-card-cover",properties:{hass:{type:Object},inDialog:{type:Boolean,value:!1},stateObj:{type:Object}}})</script><dom-module id="state-card-display" assetpath="state-summary/"><template><style is="custom-style" include="iron-flex iron-flex-alignment"></style><style>.state{@apply(--paper-font-body1);color:var(--primary-text-color);margin-left:16px;text-align:right;line-height:40px}</style><div class="horizontal justified layout"><state-info state-obj="[[stateObj]]" in-dialog="[[inDialog]]"></state-info><div class="state">[[computeStateDisplay(stateObj)]]</div></div></template></dom-module><script>Polymer({is:"state-card-display",properties:{inDialog:{type:Boolean,value:!1},stateObj:{type:Object}},computeStateDisplay:function(t){return window.hassUtil.computeStateState(t)}})</script><script>Polymer.PaperInputHelper={},Polymer.PaperInputHelper.NextLabelID=1,Polymer.PaperInputHelper.NextAddonID=1,Polymer.PaperInputBehaviorImpl={properties:{label:{type:String},value:{notify:!0,type:String},disabled:{type:Boolean,value:!1},invalid:{type:Boolean,value:!1,notify:!0},preventInvalidInput:{type:Boolean},allowedPattern:{type:String},type:{type:String},list:{type:String},pattern:{type:String},required:{type:Boolean,value:!1},errorMessage:{type:String},charCounter:{type:Boolean,value:!1},noLabelFloat:{type:Boolean,value:!1},alwaysFloatLabel:{type:Boolean,value:!1},autoValidate:{type:Boolean,value:!1},validator:{type:String},autocomplete:{type:String,value:"off"},autofocus:{type:Boolean,observer:"_autofocusChanged"},inputmode:{type:String},minlength:{type:Number},maxlength:{type:Number},min:{type:String},max:{type:String},step:{type:String},name:{type:String},placeholder:{type:String,value:""},readonly:{type:Boolean,value:!1},size:{type:Number},autocapitalize:{type:String,value:"none"},autocorrect:{type:String,value:"off"},autosave:{type:String},results:{type:Number},accept:{type:String},multiple:{type:Boolean},_ariaDescribedBy:{type:String,value:""},_ariaLabelledBy:{type:String,value:""}},listeners:{"addon-attached":"_onAddonAttached"},keyBindings:{"shift+tab:keydown":"_onShiftTabDown"},hostAttributes:{tabindex:0},get inputElement(){return this.$.input},get _focusableElement(){return this.inputElement},registered:function(){this._typesThatHaveText=["date","datetime","datetime-local","month","time","week","file"]},attached:function(){this._updateAriaLabelledBy(),this.inputElement&&this._typesThatHaveText.indexOf(this.inputElement.type)!==-1&&(this.alwaysFloatLabel=!0)},_appendStringWithSpace:function(e,t){return e=e?e+" "+t:t},_onAddon
return performance.now()};else var t=function(){return Date.now()};var e=function(t,e,i){this.target=t,this.currentTime=e,this.timelineTime=i,this.type="cancel",this.bubbles=!1,this.cancelable=!1,this.currentTarget=t,this.defaultPrevented=!1,this.eventPhase=Event.AT_TARGET,this.timeStamp=Date.now()},i=window.Element.prototype.animate;window.Element.prototype.animate=function(n,r){var o=i.call(this,n,r);o._cancelHandlers=[],o.oncancel=null;var a=o.cancel;o.cancel=function(){a.call(this);var i=new e(this,null,t()),n=this._cancelHandlers.concat(this.oncancel?[this.oncancel]:[]);setTimeout(function(){n.forEach(function(t){t.call(i.target,i)})},0)};var s=o.addEventListener;o.addEventListener=function(t,e){"function"==typeof e&&"cancel"==t?this._cancelHandlers.push(e):s.call(this,t,e)};var u=o.removeEventListener;return o.removeEventListener=function(t,e){if("cancel"==t){var i=this._cancelHandlers.indexOf(e);i>=0&&this._cancelHandlers.splice(i,1)}else u.call(this,t,e)},o}}}(),function(t){var e=document.documentElement,i=null,n=!1;try{var r=getComputedStyle(e).getPropertyValue("opacity"),o="0"==r?"1":"0";i=e.animate({opacity:[o,o]},{duration:1}),i.currentTime=0,n=getComputedStyle(e).getPropertyValue("opacity")==o}catch(t){}finally{i&&i.cancel()}if(!n){var a=window.Element.prototype.animate;window.Element.prototype.animate=function(e,i){return window.Symbol&&Symbol.iterator&&Array.prototype.from&&e[Symbol.iterator]&&(e=Array.from(e)),Array.isArray(e)||null===e||(e=t.convertToArrayForm(e)),a.call(this,e,i)}}}(c),function(t,e,i){function n(t){var i=e.timeline;i.currentTime=t,i._discardAnimations(),0==i._animations.length?o=!1:requestAnimationFrame(n)}var r=window.requestAnimationFrame;window.requestAnimationFrame=function(t){return r(function(i){e.timeline._updateAnimationsPromises(),t(i),e.timeline._updateAnimationsPromises()})},e.AnimationTimeline=function(){this._animations=[],this.currentTime=void 0},e.AnimationTimeline.prototype={getAnimations:function(){return this._discardAnimations(),this._animations.slice()},_updateAnimationsPromises:function(){e.animationsWithPromises=e.animationsWithPromises.filter(function(t){return t._updatePromises()})},_discardAnimations:function(){this._updateAnimationsPromises(),this._animations=this._animations.filter(function(t){return"finished"!=t.playState&&"idle"!=t.playState})},_play:function(t){var i=new e.Animation(t,this);return this._animations.push(i),e.restartWebAnimationsNextTick(),i._updatePromises(),i._animation.play(),i._updatePromises(),i},play:function(t){return t&&t.remove(),this._play(t)}};var o=!1;e.restartWebAnimationsNextTick=function(){o||(o=!0,requestAnimationFrame(n))};var a=new e.AnimationTimeline;e.timeline=a;try{Object.defineProperty(window.document,"timeline",{configurable:!0,get:function(){return a}})}catch(t){}try{window.document.timeline=a}catch(t){}}(0,e),function(t,e,i){e.animationsWithPromises=[],e.Animation=function(e,i){if(this.id="",e&&e._id&&(this.id=e._id),this.effect=e,e&&(e._animation=this),!i)throw new Error("Animation with null timeline is not supported");this._timeline=i,this._sequenceNumber=t.sequenceNumber++,this._holdTime=0,this._paused=!1,this._isGroup=!1,this._animation=null,this._childAnimations=[],this._callback=null,this._oldPlayState="idle",this._rebuildUnderlyingAnimation(),this._animation.cancel(),this._updatePromises()},e.Animation.prototype={_updatePromises:function(){var t=this._oldPlayState,e=this.playState;return this._readyPromise&&e!==t&&("idle"==e?(this._rejectReadyPromise(),this._readyPromise=void 0):"pending"==t?this._resolveReadyPromise():"pending"==e&&(this._readyPromise=void 0)),this._finishedPromise&&e!==t&&("idle"==e?(this._rejectFinishedPromise(),this._finishedPromise=void 0):"finished"==e?this._resolveFinishedPromise():"finished"==t&&(this._finishedPromise=void 0)),this._oldPlayState=this.playState,this._readyPromise||this._finishedPromise},_rebuildUnderlyingAnimation:function(){this._updatePromises();var t,i,n,r,o=!!this._animation;o&&(t=this.playbackRate,i=this._paused,n=this.startTime,r=this.currentTime,this._animation.c
2017-01-30 02:43:39 +00:00
window.MediaPlayerEntity = function (hass, stateObj) {
this.hass = hass;
this.stateObj = stateObj;
};
function addGetter(name, getter) {
Object.defineProperty(window.MediaPlayerEntity.prototype, name,
{ get: getter });
}
addGetter('isOff', function () {
return this.stateObj.state === 'off';
});
addGetter('isIdle', function () {
return this.stateObj.state === 'idle';
});
addGetter('isMuted', function () {
return this.stateObj.attributes.is_volume_muted;
});
addGetter('isPaused', function () {
return this.stateObj.state === 'paused';
});
addGetter('isPlaying', function () {
return this.stateObj.state === 'playing';
});
addGetter('isMusic', function () {
return this.stateObj.attributes.media_content_type === 'music';
});
addGetter('isTVShow', function () {
return this.stateObj.attributes.media_content_type === 'tvshow';
});
addGetter('hasMediaControl', function () {
return ['playing', 'paused', 'unknown'].indexOf(
this.stateObj.state) !== -1;
});
addGetter('volumeSliderValue', function () {
return this.stateObj.attributes.volume_level * 100;
});
addGetter('showProgress', function () {
return (
(this.isPlaying || this.isPaused) &&
'media_position' in this.stateObj.attributes &&
'media_position_updated_at' in this.stateObj.attributes);
});
addGetter('currentProgress', function () {
return (
this.stateObj.attributes.media_position +
((Date.now() -
new Date(this.stateObj.attributes.media_position_updated_at)) / 1000));
});
/* eslint-disable no-bitwise */
addGetter('supportsPause', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 1) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsVolumeSet', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 4) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsVolumeMute', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 8) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsPreviousTrack', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 16) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsNextTrack', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 32) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsTurnOn', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 128) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsTurnOff', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 256) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsPlayMedia', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 512) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsVolumeButtons', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 1024) !== 0;
2017-01-30 02:43:39 +00:00
});
addGetter('supportsPlay', function () {
2017-02-08 05:30:24 +00:00
return (this.stateObj.attributes.supported_features & 16384) !== 0;
2017-01-30 02:43:39 +00:00
});
/* eslint-enable no-bitwise */
addGetter('primaryText', function () {
return this.stateObj.attributes.media_title ||
window.hassUtil.computeStateState(this.stateObj);
});
addGetter('secondaryText', function () {
if (this.isMusic) {
return this.stateObj.attributes.media_artist;
} else if (this.isTVShow) {
var text = this.stateObj.attributes.media_series_title;
if (this.stateObj.attributes.media_season) {
text += ' S' + this.stateObj.attributes.media_season;
if (this.stateObj.attributes.media_episode) {
text += 'E' + this.stateObj.attributes.media_episode;
}
}
return text;
} else if (this.stateObj.attributes.app_name) {
return this.stateObj.attributes.app_name;
}
return '';
});
Object.assign(window.MediaPlayerEntity.prototype, {
mediaPlayPause() {
this.callService('media_play_pause');
},
nextTrack() {
this.callService('media_next_track');
},
playbackControl() {
this.callService('media_play_pause');
},
previousTrack() {
this.callService('media_previous_track');
},
setVolume(volume) {
this.callService('volume_set', { volume_level: volume });
},
togglePower() {
if (this.isOff) {
this.turnOn();
} else {
this.turnOff();
}
},
turnOff() {
this.callService('turn_off');
},
turnOn() {
this.callService('turn_on');
},
volumeDown() {
this.callService('volume_down');
},
volumeMute(mute) {
if (!this.supportsVolumeMute) {
throw new Error('Muting volume not supported');
}
this.callService('volume_mute', { is_volume_muted: mute });
},
volumeUp() {
2017-02-21 05:56:38 +00:00
this.callService('volume_up');
2017-01-30 02:43:39 +00:00
},
// helper method
callService(service, data) {
var serviceData = data || {};
serviceData.entity_id = this.stateObj.entity_id;
this.hass.callService('media_player', service, serviceData);
},
});
}());</script><dom-module id="ha-media_player-card" assetpath="cards/"><template><style include="paper-material iron-flex iron-flex-alignment iron-positioning">:host{display:block;position:relative;font-size:0;border-radius:2px;overflow:hidden}.banner{position:relative;background-color:#fff;border-top-left-radius:2px;border-top-right-radius:2px}.banner:before{display:block;content:"";width:100%;padding-top:56%;transition:padding-top .8s}.banner.no-cover{background-position:center center;background-image:url(/static/images/card_media_player_bg.png);background-repeat:no-repeat;background-color:var(--primary-color)}.banner.content-type-music:before{padding-top:100%}.banner.no-cover:before{padding-top:88px}.banner>.cover{position:absolute;top:0;left:0;right:0;bottom:0;border-top-left-radius:2px;border-top-right-radius:2px;background-position:center center;background-size:cover;transition:opacity .8s;opacity:1}.banner.is-off>.cover{opacity:0}.banner>.caption{@apply(--paper-font-caption);position:absolute;left:0;right:0;bottom:0;background-color:rgba(0,0,0,var(--dark-secondary-opacity));padding:8px 16px;font-size:14px;font-weight:500;color:#fff;transition:background-color .5s}.banner.is-off>.caption{background-color:initial}.banner>.caption .title{@apply(--paper-font-common-nowrap);font-size:1.2em;margin:8px 0 4px}.progress{width:100%;--paper-progress-active-color:var(--accent-color);--paper-progress-container-color:#FFF}.controls{position:relative;@apply(--paper-font-body1);padding:8px;border-bottom-left-radius:2px;border-bottom-right-radius:2px;background-color:#fff}.controls paper-icon-button{width:44px;height:44px}paper-icon-button{opacity:var(--dark-primary-opacity)}paper-icon-button[disabled]{opacity:var(--dark-disabled-opacity)}paper-icon-button.primary{width:56px!important;height:56px!important;background-color:var(--primary-color);color:#fff;border-radius:50%;padding:8px;transition:background-color .5s}paper-icon-button.primary[disabled]{background-color:rgba(0,0,0,var(--dark-disabled-opacity))}[invisible]{visibility:hidden!important}</style><div class$="[[computeBannerClasses(playerObj)]]"><div class="cover" id="cover"></div><div class="caption">[[computeStateName(stateObj)]]<div class="title">[[playerObj.primaryText]]</div>[[playerObj.secondaryText]]<br></div></div><paper-progress max="[[stateObj.attributes.media_duration]]" value="[[playbackPosition]]" hidden$="[[computeHideProgress(playerObj)]]" class="progress"></paper-progress><div class="controls layout horizontal justified"><paper-icon-button icon="mdi:power" on-tap="handleTogglePower" invisible$="[[computeHidePowerButton(playerObj)]]" class="self-center secondary"></paper-icon-button><div><paper-icon-button icon="mdi:skip-previous" invisible$="[[!playerObj.supportsPreviousTrack]]" disabled="[[playerObj.isOff]]" on-tap="handlePrevious"></paper-icon-button><paper-icon-button class="primary" icon="[[computePlaybackControlIcon(playerObj)]]" invisible$="[[!computePlaybackControlIcon(playerObj)]]" disabled="[[playerObj.isOff]]" on-tap="handlePlaybackControl"></paper-icon-button><paper-icon-button icon="mdi:skip-next" invisible$="[[!playerObj.supportsNextTrack]]" disabled="[[playerObj.isOff]]" on-tap="handleNext"></paper-icon-button></div><paper-icon-button icon="mdi:dots-vertical" on-tap="handleOpenMoreInfo" class="self-center secondary"></paper-icon-button></div></template></dom-module><script>Polymer({is:"ha-media_player-card",properties:{hass:{type:Object},stateObj:{type:Object},playerObj:{type:Object,computed:"computePlayerObj(hass, stateObj)",observer:"playerObjChanged"},playbackControlIcon:{type:String,computed:"computePlaybackControlIcon(playerObj)"},playbackPosition:{type:Number},elevation:{type:Number,value:1,reflectToAttribute:!0}},created:function(){this.updatePlaybackPosition=this.updatePlaybackPosition.bind(this)},playerObjChanged:function(t){var e,o=t.stateObj.attributes.entity_picture;o?(e=document.createElement("IMG"),e.onload=function(){this.$.cover.style.backgroundImage="url("+o+")",e.onerror=e.onload=null,e.src="",e=null}.bind(this),e.onerror=fu