Skip to content

Commit

Permalink
Release 20180330
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-git committed Mar 30, 2018
1 parent 5f74cb7 commit 1c79041
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/version.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<script>
window.customUI.VERSION = '20180216';
window.customUI.VERSION = '20180330';
</script>
103 changes: 75 additions & 28 deletions state-card-custom-ui-dbg-es5.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
if (template.match(/\b(entities|hass)\b/)) {
hasGlobal = true;
}
var value = window.customUI.computeTemplate(template, hass, states, stateObj, attributes, attributes[key], stateObj.state);
var value = window.customUI.computeTemplate(template, hass, states, stateObj, attributes, stateObj.untemplated_attributes && stateObj.untemplated_attributes[key] || attributes[key], stateObj.untemplated_state || stateObj.state);
// In case of null don't set the value.
if (value === null) return;
newAttributes[key] = value;
Expand All @@ -130,10 +130,12 @@
if (Object.prototype.hasOwnProperty.call(newAttributes, 'state')) {
if (newAttributes.state !== null) {
result.state = String(newAttributes.state);
result.untemplated_state = stateObj.state;
}
}
if (Object.prototype.hasOwnProperty.call(newAttributes, '_stateDisplay')) {
result._stateDisplay = newAttributes._stateDisplay;
result.untemplated_stateDisplay = stateObj._stateDisplay;
}
window.customUI._setKeep(result, !hasGlobal);
return result;
Expand Down Expand Up @@ -168,6 +170,7 @@
entity_id: stateObj.entity_id,
state: stateObj.state,
attributes: Object.assign({}, stateObj.attributes, attributes),
untemplated_attributes: stateObj.attributes,
last_changed: stateObj.last_changed
};
},
Expand Down Expand Up @@ -213,6 +216,10 @@
window.setTimeout(window.customUI.showVersion, 1000);
return;
}
if (devInfo.hass && devInfo.hass.config && devInfo.hass.config.core && devInfo.hass.config.core.version && devInfo.hass.config.core.version.split('.')[1] > 65) {
// 0.66 introduced proper display if customui versions.
return;
}
var about = window.customUI.lightOrShadow(devInfo, '.about');
var secondP = about.querySelectorAll('p')[1];
var version = document.createElement('p');
Expand Down Expand Up @@ -294,34 +301,65 @@
if (!window.location.pathname.startsWith('/config')) return;
var haPanelConfig = window.customUI.getElementHierarchy(document, ['home-assistant', 'home-assistant-main', 'partial-panel-resolver', 'ha-panel-config']);
if (!haPanelConfig) {
// DOM not ready. Wait 1 second.
window.setTimeout(window.customUI.updateConfigPanel, 1000);
// DOM not ready. Wait 100ms.
window.setTimeout(window.customUI.updateConfigPanel, 100);
return;
}
var ironPages = window.customUI.lightOrShadow(haPanelConfig, 'iron-pages');
if (!ironPages) return;
var haConfigNavigation = window.customUI.getElementHierarchy(haPanelConfig, ['ha-config-dashboard', 'ha-config-navigation']);
if (!haConfigNavigation) return;
if (ironPages.lastElementChild.tagName !== 'HA-CONFIG-CUSTOM-UI') {
if (haConfigNavigation) {
// HaConfigNavigation started using localize on 21.01.2018
if (haConfigNavigation.localize && !haConfigNavigation.cuiPatch) {
haConfigNavigation.cuiPatch = true;
haConfigNavigation._originalComputeLoaded = haConfigNavigation._computeLoaded;
haConfigNavigation._originalComputeCaption = haConfigNavigation._computeCaption;
haConfigNavigation._originalComputeDescription = haConfigNavigation._computeDescription;
haConfigNavigation._computeLoaded = function (hass, page) {
return page === 'customui' || haConfigNavigation._originalComputeLoaded(hass, page);
};
haConfigNavigation._computeCaption = function (page, localize) {
return page === 'customui' ? 'Custom UI' : haConfigNavigation._originalComputeCaption(page, localize);
};
haConfigNavigation._computeDescription = function (page, localize) {
return page === 'customui' ? 'SetUI tweaks' : haConfigNavigation._originalComputeDescription(page, localize);
};
}
if (!haConfigNavigation.pages.some(function (conf) {
return conf === 'customui' || conf.domain === 'customui';
})) {
haConfigNavigation.push('pages', haConfigNavigation.localize ? 'customui' : {
domain: 'customui',
caption: 'Custom UI',
description: 'Set UI tweaks.',
loaded: true
});
}
}
var getHaConfigCustomUi = function getHaConfigCustomUi() {
var haConfigCustomUi = document.createElement('ha-config-custom-ui');
haConfigCustomUi.isWide = window.customUI.domHost(ironPages).isWide;
haConfigCustomUi.isWide = haPanelConfig.isWide;
haConfigCustomUi.setAttribute('page-name', 'customui');
ironPages.appendChild(haConfigCustomUi);
ironPages.addEventListener('iron-items-changed', function () {
if (window.location.pathname.startsWith('/config/customui')) {
ironPages.select('customui');
}
});
}
if (!haConfigNavigation.pages.some(function (conf) {
return conf.domain === 'customui';
})) {
haConfigNavigation.push('pages', {
domain: 'customui',
caption: 'Custom UI',
description: 'Set UI tweaks.',
loaded: true
});
return haConfigCustomUi;
};

var ironPages = window.customUI.lightOrShadow(haPanelConfig, 'iron-pages');
if (ironPages) {
if (ironPages.lastElementChild.tagName !== 'HA-CONFIG-CUSTOM-UI') {
var haConfigCustomUi = getHaConfigCustomUi();
ironPages.appendChild(haConfigCustomUi);
ironPages.addEventListener('iron-items-changed', function () {
if (window.location.pathname.startsWith('/config/customui')) {
ironPages.select('customui');
}
});
}
} else {
var root = haPanelConfig.shadowRoot || haPanelConfig;
if (root.lastElementChild.tagName !== 'HA-CONFIG-CUSTOM-UI') {
var _haConfigCustomUi = getHaConfigCustomUi();
root.appendChild(_haConfigCustomUi);
}
var visible = window.location.pathname.startsWith('/config/customui');
root.lastElementChild.style.display = visible ? '' : 'none';
}
},
installStatesHook: function installStatesHook() {
Expand Down Expand Up @@ -424,6 +462,14 @@
/* eslint-disable no-console */
console.log('Loaded CustomUI ' + window.customUI.VERSION);
/* eslint-enable no-console */
if (!window.CUSTOM_UI_LIST) {
window.CUSTOM_UI_LIST = [];
}
window.CUSTOM_UI_LIST.push({
name: 'CustomUI',
version: window.customUI.VERSION,
url: 'https://github.com/andrey-git/home-assistant-custom-ui'
});
},
runHooks: function runHooks() {
window.customUI.fixGroupTitles();
Expand Down Expand Up @@ -456,7 +502,7 @@
}
};</script>
<script>
window.customUI.VERSION = '20180216';</script>
window.customUI.VERSION = '20180330';</script>
<script>
window.customUI.init();</script>
<dom-module id="ha-config-custom-ui">
Expand Down Expand Up @@ -492,8 +538,8 @@

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var HaConfigCustomUi = function (_Polymer$Element) {
_inherits(HaConfigCustomUi, _Polymer$Element);
var HaConfigCustomUi = function (_window$hassMixins$Ev) {
_inherits(HaConfigCustomUi, _window$hassMixins$Ev);

function HaConfigCustomUi() {
_classCallCheck(this, HaConfigCustomUi);
Expand All @@ -516,6 +562,7 @@
key: '_backTapped',
value: function _backTapped() {
window.history.back();
this.fire('location-changed');
}
}], [{
key: 'is',
Expand All @@ -537,7 +584,7 @@
}]);

return HaConfigCustomUi;
}(Polymer.Element);
}(window.hassMixins.EventsMixin(Polymer.Element));

customElements.define(HaConfigCustomUi.is, HaConfigCustomUi);</script>
<script>var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
Expand Down
Binary file modified state-card-custom-ui-dbg-es5.html.gz
Binary file not shown.
96 changes: 72 additions & 24 deletions state-card-custom-ui-dbg.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
}
const value = window.customUI.computeTemplate(
template, hass, states, stateObj, attributes,
attributes[key], stateObj.state);
(stateObj.untemplated_attributes && stateObj.untemplated_attributes[key]) ||
attributes[key],
stateObj.untemplated_state || stateObj.state);
// In case of null don't set the value.
if (value === null) return;
newAttributes[key] = value;
Expand All @@ -142,10 +144,12 @@
if (Object.prototype.hasOwnProperty.call(newAttributes, 'state')) {
if (newAttributes.state !== null) {
result.state = String(newAttributes.state);
result.untemplated_state = stateObj.state;
}
}
if (Object.prototype.hasOwnProperty.call(newAttributes, '_stateDisplay')) {
result._stateDisplay = newAttributes._stateDisplay;
result.untemplated_stateDisplay = stateObj._stateDisplay;
}
window.customUI._setKeep(result, !hasGlobal);
return result;
Expand Down Expand Up @@ -184,6 +188,7 @@
entity_id: stateObj.entity_id,
state: stateObj.state,
attributes: Object.assign({}, stateObj.attributes, attributes),
untemplated_attributes: stateObj.attributes,
last_changed: stateObj.last_changed,
};
},
Expand Down Expand Up @@ -244,6 +249,12 @@
window.setTimeout(window.customUI.showVersion, 1000);
return;
}
if (devInfo.hass && devInfo.hass.config && devInfo.hass.config.core &&
devInfo.hass.config.core.version &&
devInfo.hass.config.core.version.split('.')[1] > 65) {
// 0.66 introduced proper display if customui versions.
return;
}
const about = window.customUI.lightOrShadow(devInfo, '.about');
const secondP = about.querySelectorAll('p')[1];
const version = document.createElement('p');
Expand Down Expand Up @@ -341,34 +352,62 @@
'partial-panel-resolver',
'ha-panel-config']);
if (!haPanelConfig) {
// DOM not ready. Wait 1 second.
window.setTimeout(window.customUI.updateConfigPanel, 1000);
// DOM not ready. Wait 100ms.
window.setTimeout(window.customUI.updateConfigPanel, 100);
return;
}
const ironPages = window.customUI.lightOrShadow(haPanelConfig, 'iron-pages');
if (!ironPages) return;
const haConfigNavigation = window.customUI.getElementHierarchy(haPanelConfig, [
'ha-config-dashboard',
'ha-config-navigation']);
if (!haConfigNavigation) return;
if (ironPages.lastElementChild.tagName !== 'HA-CONFIG-CUSTOM-UI') {
if (haConfigNavigation) {
// HaConfigNavigation started using localize on 21.01.2018
if (haConfigNavigation.localize && !haConfigNavigation.cuiPatch) {
haConfigNavigation.cuiPatch = true;
haConfigNavigation._originalComputeLoaded = haConfigNavigation._computeLoaded;
haConfigNavigation._originalComputeCaption = haConfigNavigation._computeCaption;
haConfigNavigation._originalComputeDescription = haConfigNavigation._computeDescription;
haConfigNavigation._computeLoaded = (hass, page) =>
page === 'customui' || haConfigNavigation._originalComputeLoaded(hass, page);
haConfigNavigation._computeCaption = (page, localize) =>
(page === 'customui' ? 'Custom UI' : haConfigNavigation._originalComputeCaption(page, localize));
haConfigNavigation._computeDescription = (page, localize) =>
(page === 'customui' ? 'SetUI tweaks' : haConfigNavigation._originalComputeDescription(page, localize));
}
if (!haConfigNavigation.pages.some(conf => conf === 'customui' || conf.domain === 'customui')) {
haConfigNavigation.push('pages', haConfigNavigation.localize ? 'customui' : {
domain: 'customui',
caption: 'Custom UI',
description: 'Set UI tweaks.',
loaded: true,
});
}
}
const getHaConfigCustomUi = () => {
const haConfigCustomUi = document.createElement('ha-config-custom-ui');
haConfigCustomUi.isWide = window.customUI.domHost(ironPages).isWide;
haConfigCustomUi.isWide = haPanelConfig.isWide;
haConfigCustomUi.setAttribute('page-name', 'customui');
ironPages.appendChild(haConfigCustomUi);
ironPages.addEventListener('iron-items-changed', () => {
if (window.location.pathname.startsWith('/config/customui')) {
ironPages.select('customui');
}
});
}
if (!haConfigNavigation.pages.some(conf => conf.domain === 'customui')) {
haConfigNavigation.push('pages', {
domain: 'customui',
caption: 'Custom UI',
description: 'Set UI tweaks.',
loaded: true,
});
return haConfigCustomUi;
};

const ironPages = window.customUI.lightOrShadow(haPanelConfig, 'iron-pages');
if (ironPages) {
if (ironPages.lastElementChild.tagName !== 'HA-CONFIG-CUSTOM-UI') {
const haConfigCustomUi = getHaConfigCustomUi();
ironPages.appendChild(haConfigCustomUi);
ironPages.addEventListener('iron-items-changed', () => {
if (window.location.pathname.startsWith('/config/customui')) {
ironPages.select('customui');
}
});
}
} else {
const root = haPanelConfig.shadowRoot || haPanelConfig;
if (root.lastElementChild.tagName !== 'HA-CONFIG-CUSTOM-UI') {
const haConfigCustomUi = getHaConfigCustomUi();
root.appendChild(haConfigCustomUi);
}
const visible = window.location.pathname.startsWith('/config/customui');
root.lastElementChild.style.display = visible ? '' : 'none';
}
},

Expand Down Expand Up @@ -477,6 +516,14 @@
/* eslint-disable no-console */
console.log(`Loaded CustomUI ${window.customUI.VERSION}`);
/* eslint-enable no-console */
if (!window.CUSTOM_UI_LIST) {
window.CUSTOM_UI_LIST = [];
}
window.CUSTOM_UI_LIST.push({
name: 'CustomUI',
version: window.customUI.VERSION,
url: 'https://github.com/andrey-git/home-assistant-custom-ui',
});
},

runHooks() {
Expand Down Expand Up @@ -515,7 +562,7 @@
};
</script>
<script>
window.customUI.VERSION = '20180216';
window.customUI.VERSION = '20180330';
</script>
<script>
window.customUI.init();
Expand Down Expand Up @@ -544,7 +591,7 @@
</dom-module>

<script>
class HaConfigCustomUi extends Polymer.Element {
class HaConfigCustomUi extends window.hassMixins.EventsMixin(Polymer.Element) {
static get is() { return 'ha-config-custom-ui'; }

static get properties() {
Expand All @@ -569,6 +616,7 @@

_backTapped() {
window.history.back();
this.fire('location-changed');
}
}
customElements.define(HaConfigCustomUi.is, HaConfigCustomUi);
Expand Down
Binary file modified state-card-custom-ui-dbg.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion state-card-custom-ui-es5.html

Large diffs are not rendered by default.

Binary file modified state-card-custom-ui-es5.html.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion state-card-custom-ui.html

Large diffs are not rendered by default.

Binary file modified state-card-custom-ui.html.gz
Binary file not shown.

0 comments on commit 1c79041

Please sign in to comment.