From 6d88fdde1151f71426aa37d2604160ffcfbebdbf Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 1 Aug 2017 12:49:34 +0200 Subject: [PATCH 1/9] Allow custom cards Kept config the same as the state-card for simplicity for the user. Only the height is still [fixed for the domain](https://github.com/home-assistant/home-assistant-polymer/blob/6a864106e0a07452abe148617fa3a0f067b0c526/src/components/ha-cards.html#L84), might need to make that customizable too? --- src/cards/ha-card-chooser.html | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 782402ee02f4..74af785d0378 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -18,11 +18,29 @@ }, }, + _ensureCustomUILoaded: function (stateType) { + this.importHref( + '/local/custom_ui/state-card-' + stateType + '.html', + function () {}, + /* eslint-disable no-console */ + function () { console.error('Error loading %s from /local/custom_ui/state-card-%s.html', stateType, stateType); }, + /* eslint-enable no-console */ + true); + }, + cardDataChanged: function (newData) { if (!newData) return; - window.hassUtil.dynamicContentUpdater(this, 'HA-' + newData.cardType.toUpperCase() + '-CARD', - newData); + var cardType = ''; + + if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_state_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.custom_ui_state_card; + this._ensureCustomUILoaded(cardType); + cardType = 'STATE-CARD-' + cardType.toUpperCase(); + } else { + cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; + } + window.hassUtil.dynamicContentUpdater(this, cardType, newData); }, }); From 2a2b2942d0343e616d26c562270a2b492e1743f5 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 1 Aug 2017 20:07:34 +0200 Subject: [PATCH 2/9] tab > spaces Stupid notepad++ --- src/cards/ha-card-chooser.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 74af785d0378..5a72bb6be56d 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -31,7 +31,7 @@ cardDataChanged: function (newData) { if (!newData) return; - var cardType = ''; + var cardType = ''; if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_state_card' in newData.stateObj.attributes) { cardType = newData.stateObj.attributes.custom_ui_state_card; From f61d392181a2366ecf75aedaaeba8740564ea628 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 5 Aug 2017 20:25:10 +0200 Subject: [PATCH 3/9] Made separate attribute custom_ui_card --- src/cards/ha-card-chooser.html | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 5a72bb6be56d..ee30def7dd6c 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -20,27 +20,25 @@ _ensureCustomUILoaded: function (stateType) { this.importHref( - '/local/custom_ui/state-card-' + stateType + '.html', + '/local/custom_ui/card-' + stateType + '.html', function () {}, /* eslint-disable no-console */ - function () { console.error('Error loading %s from /local/custom_ui/state-card-%s.html', stateType, stateType); }, + function () { console.error('Error loading %s from /local/custom_ui/card-%s.html', stateType, stateType); }, /* eslint-enable no-console */ true); }, - + cardDataChanged: function (newData) { if (!newData) return; - - var cardType = ''; - - if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_state_card' in newData.stateObj.attributes) { - cardType = newData.stateObj.attributes.custom_ui_state_card; + + if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.custom_ui_card; this._ensureCustomUILoaded(cardType); - cardType = 'STATE-CARD-' + cardType.toUpperCase(); + cardType = 'CARD-' + cardType.toUpperCase(); } else { cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; } window.hassUtil.dynamicContentUpdater(this, cardType, newData); }, }); - + \ No newline at end of file From 7fd4ee156e305ad6cde15dbc631a48d95b131a97 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 5 Aug 2017 20:49:36 +0200 Subject: [PATCH 4/9] tox and card/state-card prefix gone --- src/cards/ha-card-chooser.html | 14 ++++++++------ src/state-summary/state-card-content.html | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index ee30def7dd6c..42bf66906241 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -20,25 +20,27 @@ _ensureCustomUILoaded: function (stateType) { this.importHref( - '/local/custom_ui/card-' + stateType + '.html', + '/local/custom_ui/' + stateType + '.html', function () {}, /* eslint-disable no-console */ - function () { console.error('Error loading %s from /local/custom_ui/card-%s.html', stateType, stateType); }, + function () { console.error('Error loading %s from /local/custom_ui/%s.html', stateType, stateType); }, /* eslint-enable no-console */ true); }, - + cardDataChanged: function (newData) { if (!newData) return; - + + var cardType = ''; + if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_card' in newData.stateObj.attributes) { cardType = newData.stateObj.attributes.custom_ui_card; this._ensureCustomUILoaded(cardType); - cardType = 'CARD-' + cardType.toUpperCase(); + cardType = cardType.toUpperCase(); } else { cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; } window.hassUtil.dynamicContentUpdater(this, cardType, newData); }, }); - \ No newline at end of file + diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index dd3c86e26c74..3f9a8d59b3d9 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -37,10 +37,10 @@ _ensureCustomUILoaded: function (stateType) { this.importHref( - '/local/custom_ui/state-card-' + stateType + '.html', + '/local/custom_ui/' + stateType + '.html', function () {}, /* eslint-disable no-console */ - function () { console.error('Error loading %s from /local/custom_ui/state-card-%s.html', stateType, stateType); }, + function () { console.error('Error loading %s from /local/custom_ui/%s.html', stateType, stateType); }, /* eslint-enable no-console */ true); }, @@ -56,7 +56,7 @@ } window.hassUtil.dynamicContentUpdater( this, - ('STATE-CARD-' + stateCardType.toUpperCase()), + (stateCardType.toUpperCase()), { hass: hass, stateObj: stateObj, From e39af2713ff73bc3ca69447382b28fcb84bcb0cf Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 5 Aug 2017 21:25:16 +0200 Subject: [PATCH 5/9] Moved loading custom ui to util customizable more-info --- src/cards/ha-card-chooser.html | 14 ++--------- src/state-summary/state-card-content.html | 14 ++--------- src/util/hass-util.html | 29 ++++++++++++++++------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 42bf66906241..2c9680081da8 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -18,24 +18,14 @@ }, }, - _ensureCustomUILoaded: function (stateType) { - this.importHref( - '/local/custom_ui/' + stateType + '.html', - function () {}, - /* eslint-disable no-console */ - function () { console.error('Error loading %s from /local/custom_ui/%s.html', stateType, stateType); }, - /* eslint-enable no-console */ - true); - }, - cardDataChanged: function (newData) { if (!newData) return; - var cardType = ''; + var cardType; if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_card' in newData.stateObj.attributes) { cardType = newData.stateObj.attributes.custom_ui_card; - this._ensureCustomUILoaded(cardType); + window.hassUtil.ensureCustomUILoaded(cardType); cardType = cardType.toUpperCase(); } else { cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index 3f9a8d59b3d9..443f45f92304 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -35,24 +35,14 @@ 'inputChanged(hass, inDialog, stateObj)', ], - _ensureCustomUILoaded: function (stateType) { - this.importHref( - '/local/custom_ui/' + stateType + '.html', - function () {}, - /* eslint-disable no-console */ - function () { console.error('Error loading %s from /local/custom_ui/%s.html', stateType, stateType); }, - /* eslint-enable no-console */ - true); - }, - inputChanged: function (hass, inDialog, stateObj) { var stateCardType; if (!stateObj || !hass) return; if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { stateCardType = stateObj.attributes.custom_ui_state_card; - this._ensureCustomUILoaded(stateCardType); + window.hassUtil.ensureCustomUILoaded(stateCardType); } else { - stateCardType = window.hassUtil.stateCardType(hass, stateObj); + stateCardType = 'STATE-CARD-' + window.hassUtil.stateCardType(hass, stateObj); } window.hassUtil.dynamicContentUpdater( this, diff --git a/src/util/hass-util.html b/src/util/hass-util.html index e145f7834a15..e57f2996da45 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -25,7 +25,7 @@ window.hassUtil.DOMAINS_WITH_MORE_INFO = [ 'alarm_control_panel', 'automation', 'camera', 'climate', 'configurator', 'cover', 'fan', 'group', 'light', 'lock', 'media_player', 'script', - 'sun', 'updater', 'vacuum', + 'sun', 'updater', ]; window.hassUtil.DOMAINS_WITH_NO_HISTORY = ['camera', 'configurator', 'scene']; @@ -225,7 +225,22 @@ return 'display'; }; +window.hassUtil.ensureCustomUILoaded = function (customUI) { + Polymer.Base.importHref( + '/local/custom_ui/' + customUI + '.html', + function () {}, + /* eslint-disable no-console */ + function () { console.error('Error loading %s from /local/custom_ui/%s.html', customUI, customUI); }, + /* eslint-enable no-console */ + true); +}, + window.hassUtil.stateMoreInfoType = function (stateObj) { + if (stateObj.attributes && 'custom_ui_more_info' in stateObj.attributes) { + var customUI = stateObj.attributes.custom_ui_card; + window.hassUtil.ensureCustomUILoaded(customUI); + return customUI; + } var domain = window.hassUtil.computeDomain(stateObj); if (window.hassUtil.DOMAINS_WITH_MORE_INFO.indexOf(domain) !== -1) { @@ -399,7 +414,7 @@ var domain = window.hassUtil.computeDomain(state); if (unit && domain === 'sensor') { - if (unit === '°C' || unit === '°F') { + if (unit === '°C' || unit === '°F') { return 'mdi:thermometer'; } else if (unit === 'Mice') { return 'mdi:mouse-variant'; @@ -492,19 +507,15 @@ return hass && hass.config.core.location_name; }; -window.hassUtil.applyThemesOnElement = function (element, themes, localTheme) { +window.hassUtil.applyThemesOnElement = function (element, themes) { if (!element._themes) { element._themes = {}; } - var themeName = themes.default_theme; - if (localTheme === 'default' || (localTheme && themes.themes[localTheme])) { - themeName = localTheme; - } - if (themeName === 'default') { + if (themes.default_theme === 'default') { element.updateStyles(element._themes); return; } - var theme = themes.themes[themeName]; + var theme = themes.themes[themes.default_theme]; var styles = Object.assign({}, element._themes); Object.keys(theme).forEach(function (key) { var prefixedKey = '--' + key; From 2d4fd6a99bf9d6a18f25e9a98c17003eb843c74e Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 5 Aug 2017 21:31:39 +0200 Subject: [PATCH 6/9] Fix --- src/util/hass-util.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/hass-util.html b/src/util/hass-util.html index e57f2996da45..9eff1c0c1a56 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -38,7 +38,7 @@ 'entity_picture', 'friendly_name', 'icon', 'unit_of_measurement', 'emulated_hue', 'emulated_hue_name', 'haaska_hidden', 'haaska_name', 'homebridge_hidden', 'homebridge_name', 'supported_features', 'attribution', - 'custom_ui_state_card', 'device_class', + 'custom_ui_state_card', 'custom_ui_card', 'custom_ui_more_info', 'device_class', ]; window.hassUtil.LANGUAGE = navigator.languages ? @@ -237,7 +237,7 @@ window.hassUtil.stateMoreInfoType = function (stateObj) { if (stateObj.attributes && 'custom_ui_more_info' in stateObj.attributes) { - var customUI = stateObj.attributes.custom_ui_card; + var customUI = stateObj.attributes.custom_ui_more_info; window.hassUtil.ensureCustomUILoaded(customUI); return customUI; } From fdfa1315007254233ab30b0b17bd6a275b5af265 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sat, 5 Aug 2017 22:23:23 +0200 Subject: [PATCH 7/9] No more-info prefix in custom ui --- src/more-infos/more-info-content.html | 2 +- src/util/hass-util.html | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/more-infos/more-info-content.html b/src/more-infos/more-info-content.html index 23b3f76c6e70..c6a84391f985 100644 --- a/src/more-infos/more-info-content.html +++ b/src/more-infos/more-info-content.html @@ -46,7 +46,7 @@ } } else { window.hassUtil.dynamicContentUpdater( - this, 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(), + this, window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(), { hass: this.hass, stateObj: stateObj, isVisible: true }); } }, diff --git a/src/util/hass-util.html b/src/util/hass-util.html index 9eff1c0c1a56..73719f7f4ff6 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -244,12 +244,12 @@ var domain = window.hassUtil.computeDomain(stateObj); if (window.hassUtil.DOMAINS_WITH_MORE_INFO.indexOf(domain) !== -1) { - return domain; + return 'MORE-INFO-' + domain; } if (window.hassUtil.HIDE_MORE_INFO.indexOf(domain) !== -1) { - return 'hidden'; + return 'MORE-INFO-HIDDEN'; } - return 'default'; + return 'MORE-INFO-DEFAULT'; }; window.hassUtil.domainIcon = function (domain, state) { From 88e08592ea36e826341a81611ea0e47680855301 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sun, 6 Aug 2017 10:27:02 +0200 Subject: [PATCH 8/9] Fix --- src/util/hass-util.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/hass-util.html b/src/util/hass-util.html index b3c752153fe7..17b0432e1f24 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -25,7 +25,7 @@ window.hassUtil.DOMAINS_WITH_MORE_INFO = [ 'alarm_control_panel', 'automation', 'camera', 'climate', 'configurator', 'cover', 'fan', 'group', 'light', 'lock', 'media_player', 'script', - 'sun', 'updater', + 'sun', 'updater', 'vacuum', ]; window.hassUtil.DOMAINS_WITH_NO_HISTORY = ['camera', 'configurator', 'scene']; @@ -420,7 +420,7 @@ var domain = window.hassUtil.computeDomain(state); if (unit && domain === 'sensor') { - if (unit === '°C' || unit === '°F') { + if (unit === '°C' || unit === '°F') { return 'mdi:thermometer'; } else if (unit === 'Mice') { return 'mdi:mouse-variant'; From d7b3e06124145a516b3494b31080ca0142373c1f Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Sun, 6 Aug 2017 10:30:35 +0200 Subject: [PATCH 9/9] Fix --- src/util/hass-util.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/hass-util.html b/src/util/hass-util.html index 17b0432e1f24..5311038cfa96 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -239,7 +239,7 @@ function () { console.error('Error loading %s from /local/custom_ui/%s.html', customUI, customUI); }, /* eslint-enable no-console */ true); -}, +}; window.hassUtil.stateMoreInfoType = function (stateObj) { if (stateObj.attributes && 'custom_ui_more_info' in stateObj.attributes) {