|
1 | 1 | <div hidden="" by-polymer-bundler=""><script>
|
2 | 2 | window.customUI = window.customUI || {
|
3 |
| - VERSION: '20171227', |
| 3 | + VERSION: '20180112', |
4 | 4 |
|
5 | 5 | SUPPORTED_SLIDER_MODES: ['single-line', 'break-slider', 'break-slider-toggle', 'hide-slider', 'no-slider'],
|
6 | 6 |
|
|
33 | 33 | }
|
34 | 34 | break;
|
35 | 35 | case 'MORE-INFO-GROUP':
|
| 36 | + case 'STATE-CARD-CONTENT': |
36 | 37 | if (element.stateObj) {
|
37 | 38 | elem._context.push(element.stateObj.entity_id);
|
38 | 39 | }
|
|
216 | 217 | version.textContent = 'Custom UI ' + window.customUI.VERSION;
|
217 | 218 | about.insertBefore(version, secondP);
|
218 | 219 | },
|
| 220 | + controlColumns: function controlColumns(columns) { |
| 221 | + var partialCards = window.customUI.getElementHierarchy(document, ['home-assistant', 'home-assistant-main', 'partial-cards']); |
| 222 | + if (partialCards === null) { |
| 223 | + // DOM not ready. Wait 1 second. |
| 224 | + window.setTimeout(window.customUI.controlColumns.bind(null, columns), 1000); |
| 225 | + return; |
| 226 | + } |
| 227 | + partialCards.mqls.forEach(function (mql) { |
| 228 | + mql.removeListener(partialCards.handleWindowChange); |
| 229 | + }); |
| 230 | + partialCards.mqls = columns.map(function (width) { |
| 231 | + var mql = window.matchMedia('(min-width: ' + width + 'px)'); |
| 232 | + mql.addListener(partialCards.handleWindowChange); |
| 233 | + return mql; |
| 234 | + }); |
| 235 | + partialCards.handleWindowChange(); |
| 236 | + }, |
219 | 237 | useCustomizer: function useCustomizer() {
|
220 | 238 | var main = window.customUI.lightOrShadow(document, 'home-assistant');
|
221 | 239 | var customizer = main.hass.states['customizer.customizer'];
|
222 | 240 | if (!customizer) return;
|
| 241 | + if (customizer.attributes.columns) { |
| 242 | + window.customUI.controlColumns(customizer.attributes.columns); |
| 243 | + } |
223 | 244 |
|
224 | 245 | if (customizer.attributes.hide_attributes) {
|
225 | 246 | if (window.hassUtil.LOGIC_STATE_ATTRIBUTES) {
|
|
459 | 480 | <dom-module id="ha-themed-slider">
|
460 | 481 | <template>
|
461 | 482 | <style>
|
| 483 | + :host { |
| 484 | + margin: var(--ha-themed-slider-margin, initial); |
| 485 | + } |
462 | 486 | .disable-off-when-min {
|
463 | 487 | --paper-slider-pin-start-color: var(--paper-slider-pin-color);
|
464 | 488 | }
|
|
707 | 731 | </style>
|
708 | 732 | <div class$="[[extraClass(extraObjVisible)]] horizontal layout">
|
709 | 733 | <template is="dom-if" if="[[extraObjVisible]]">
|
710 |
| - <template is="dom-repeat" items="[[extraObj]]"> |
| 734 | + <template is="dom-repeat" items="[[extraObj]]" on-dom-change="extraDomChanged"> |
711 | 735 | <ha-state-label-badge hass="[[hass]]" state="[[item]]"></ha-state-label-badge>
|
712 | 736 | </template>
|
713 | 737 | </template>
|
|
752 | 776 | }
|
753 | 777 |
|
754 | 778 | _createClass(DynamicWithExtra, [{
|
| 779 | + key: 'connectedCallback', |
| 780 | + value: function connectedCallback() { |
| 781 | + _get(DynamicWithExtra.prototype.__proto__ || Object.getPrototypeOf(DynamicWithExtra.prototype), 'connectedCallback', this).call(this); |
| 782 | + this._attached = true; |
| 783 | + } |
| 784 | + }, { |
| 785 | + key: 'disconnectedCallback', |
| 786 | + value: function disconnectedCallback() { |
| 787 | + this._isAttached = false; |
| 788 | + _get(DynamicWithExtra.prototype.__proto__ || Object.getPrototypeOf(DynamicWithExtra.prototype), 'disconnectedCallback', this).call(this); |
| 789 | + } |
| 790 | + }, { |
755 | 791 | key: 'computeExtra',
|
756 |
| - value: function computeExtra(hass, stateObj) { |
757 |
| - if (!stateObj.attributes.extra_badge) return []; |
| 792 | + value: function computeExtra(hass, stateObj, attached) { |
| 793 | + var _this2 = this; |
| 794 | + |
| 795 | + if (!stateObj.attributes.extra_badge || !attached) return []; |
758 | 796 | var extraBadges = stateObj.attributes.extra_badge;
|
759 | 797 | if (!Array.isArray(extraBadges)) {
|
760 | 798 | extraBadges = [extraBadges];
|
761 | 799 | }
|
762 | 800 | return extraBadges.map(function (extraBadge) {
|
763 | 801 | var result = null;
|
764 | 802 | if (extraBadge.entity_id && hass.states[extraBadge.entity_id]) {
|
765 |
| - result = Object.assign({}, hass.states[extraBadge.entity_id]); |
766 |
| - } else if (extraBadge.attribute && stateObj.attributes[extraBadge.attribute]) { |
| 803 | + result = Object.assign({}, window.customUI.maybeChangeObject(_this2, hass.states[extraBadge.entity_id], _this2.inDialog, |
| 804 | + /* allowHidden= */false)); |
| 805 | + } else if (extraBadge.attribute && stateObj.attributes[extraBadge.attribute] !== undefined) { |
767 | 806 | result = {
|
768 |
| - state: stateObj.attributes[extraBadge.attribute], |
| 807 | + state: String(stateObj.attributes[extraBadge.attribute]), |
769 | 808 | _domain: 'none',
|
770 | 809 | entity_id: null,
|
771 | 810 | attributes: { unit_of_measurement: extraBadge.unit }
|
|
823 | 862 | }, {
|
824 | 863 | key: 'tapHandler',
|
825 | 864 | value: function tapHandler(e) {
|
826 |
| - var _this2 = this; |
| 865 | + var _this3 = this; |
827 | 866 |
|
828 | 867 | this.$$('#overlay').style.pointerEvents = 'none';
|
829 | 868 | var lock = this.$$('#lock');
|
|
832 | 871 | lock.style.opacity = '0.1';
|
833 | 872 | }
|
834 | 873 | window.setTimeout(function () {
|
835 |
| - _this2.$$('#overlay').style.pointerEvents = ''; |
| 874 | + _this3.$$('#overlay').style.pointerEvents = ''; |
836 | 875 | if (lock) {
|
837 | 876 | lock.icon = 'mdi:lock-outline';
|
838 | 877 | lock.style.opacity = '';
|
839 | 878 | }
|
840 | 879 | }, 5000);
|
841 | 880 | e.stopPropagation();
|
842 | 881 | }
|
| 882 | + }, { |
| 883 | + key: 'applyThemes', |
| 884 | + value: function applyThemes(hass, element, stateObj) { |
| 885 | + var themeName = stateObj.attributes.theme || 'default'; |
| 886 | + window.hassUtil.applyThemesOnElement(element, hass.themes || { default_theme: 'default', themes: {} }, themeName); |
| 887 | + } |
| 888 | + }, { |
| 889 | + key: 'extraDomChanged', |
| 890 | + value: function extraDomChanged() { |
| 891 | + var _this4 = this; |
| 892 | + |
| 893 | + this.root.querySelectorAll('ha-state-label-badge').forEach(function (elem) { |
| 894 | + _this4.applyThemes(_this4.hass, elem, elem.state); |
| 895 | + }); |
| 896 | + } |
843 | 897 | }], [{
|
844 | 898 | key: 'is',
|
845 | 899 | get: function get() {
|
|
858 | 912 | controlElement: String,
|
859 | 913 | extraObj: {
|
860 | 914 | type: Array,
|
861 |
| - computed: 'computeExtra(hass, stateObj)' |
| 915 | + computed: 'computeExtra(hass, stateObj, _attached)' |
862 | 916 | },
|
| 917 | + _attached: Boolean, |
863 | 918 | extraObjVisible: {
|
864 | 919 | type: Boolean,
|
865 | 920 | computed: 'computeExtraVisible(extraObj, inDialog)'
|
|
993 | 1048 | }, {
|
994 | 1049 | key: '_setMode',
|
995 | 1050 | value: function _setMode() {
|
996 |
| - this.hideSlider = this.mode === 'hide-slider' && this.lineTooLong; |
997 |
| - this.breakSlider = (this.mode === 'break-slider' || this.mode === 'hide-slider') && this.lineTooLong; |
| 1051 | + var obj = { |
| 1052 | + hideSlider: this.mode === 'hide-slider' && this.lineTooLong, |
| 1053 | + breakSlider: (this.mode === 'break-slider' || this.mode === 'hide-slider') && this.lineTooLong |
| 1054 | + }; |
998 | 1055 | if (!this.showSlider) {
|
999 |
| - this.breakSlider = true; |
| 1056 | + obj.breakSlider = true; |
1000 | 1057 | }
|
| 1058 | + this.setProperties(obj); |
1001 | 1059 | }
|
1002 | 1060 | }, {
|
1003 | 1061 | key: '_onIronResize',
|
|
1007 | 1065 | return;
|
1008 | 1066 | }
|
1009 | 1067 | if (this.mode === 'no-slider') {
|
1010 |
| - this.hideSlider = true; |
1011 |
| - this.breakSlider = true; |
| 1068 | + this.setProperties({ |
| 1069 | + hideSlider: true, |
| 1070 | + breakSlider: true |
| 1071 | + }); |
1012 | 1072 | return;
|
1013 | 1073 | }
|
1014 | 1074 | var prevBreakSlider = this.breakSlider;
|
1015 | 1075 | var prevHideSlider = this.hideSlider;
|
1016 |
| - this.lineTooLong = false; |
1017 |
| - this.hideSlider = false; |
1018 |
| - this.breakSlider = false; |
| 1076 | + this.setProperties({ |
| 1077 | + lineTooLong: false, |
| 1078 | + hideSlider: false, |
| 1079 | + breakSlider: false |
| 1080 | + }); |
1019 | 1081 | var container = this.$.container;
|
1020 | 1082 |
|
1021 | 1083 | var containerWidth = container.clientWidth;
|
|
1100 | 1162 | this.sliderValue = 0;
|
1101 | 1163 | }
|
1102 | 1164 | if (stateObj) {
|
1103 |
| - this.setProperties({ |
| 1165 | + var obj = { |
1104 | 1166 | minLineBreak: 0,
|
1105 | 1167 | maxLineBreak: 999,
|
1106 | 1168 | hideSlider: false,
|
1107 | 1169 | breakSlider: false,
|
1108 | 1170 | lineTooLong: false
|
1109 |
| - }); |
1110 |
| - if (window.customUI.SUPPORTED_SLIDER_MODES.indexOf(stateObj.attributes.state_card_mode) !== -1) { |
1111 |
| - this.mode = stateObj.attributes.state_card_mode; |
| 1171 | + }; |
| 1172 | + if (window.customUI.SUPPORTED_SLIDER_MODES.includes(stateObj.attributes.state_card_mode)) { |
| 1173 | + obj.mode = stateObj.attributes.state_card_mode; |
1112 | 1174 | } else {
|
1113 |
| - this.mode = DEFAULT_MODE; |
| 1175 | + obj.mode = DEFAULT_MODE; |
1114 | 1176 | }
|
1115 | 1177 | if (stateObj.attributes.stretch_slider) {
|
1116 |
| - this.stretchSlider = true; |
| 1178 | + obj.stretchSlider = true; |
1117 | 1179 | }
|
| 1180 | + this.setProperties(obj); |
1118 | 1181 | this._waitForLayout();
|
1119 | 1182 | }
|
1120 | 1183 | }
|
|
1308 | 1371 | this._container.style.display = 'inline-block';
|
1309 | 1372 | var params = { display: 'inline-block' };
|
1310 | 1373 | if (this._container.classList.contains('state')) {
|
1311 |
| - params.margin = '0 -6px'; |
| 1374 | + params.margin = 'var(--ha-badges-card-margin, 0 -6px)'; |
1312 | 1375 | }
|
1313 | 1376 | this.updateStyles(params);
|
1314 | 1377 | }
|
|
0 commit comments