From 9060a7fde63d82802a4b1fd07dfae9b1421c1d1a Mon Sep 17 00:00:00 2001 From: test <11984118+c727@users.noreply.github.com> Date: Tue, 23 Jan 2018 01:58:12 +0100 Subject: [PATCH 1/6] Allow more custom ui and support custom_card component --- src/cards/ha-card-chooser.html | 14 ++++++++++---- src/components/ha-cards.html | 1 + src/more-infos/more-info-content.html | 11 ++++++++++- src/state-summary/state-card-content.html | 5 ++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 84ee7558cf13..57e5feeea017 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -23,10 +23,16 @@ cardDataChanged(newData) { if (!newData) return; - window.hassUtil.dynamicContentUpdater( - this, 'HA-' + newData.cardType.toUpperCase() + '-CARD', - newData - ); + var cardType; + if (newData.stateObj && window.hassUtil.computeDomain(newData.stateObj) === 'custom_ha_card' && newData.stateObj.attributes && 'ha_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.ha_card.toUpperCase(); + } else if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_ha_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.custom_ui_ha_card.toUpperCase(); + } else { + cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; + } + + window.hassUtil.dynamicContentUpdater(this, cardType, newData); } } customElements.define(HaCardChooser.is, HaCardChooser); diff --git a/src/components/ha-cards.html b/src/components/ha-cards.html index 298a29bcb694..7a1b7d7eb03b 100644 --- a/src/components/ha-cards.html +++ b/src/components/ha-cards.html @@ -88,6 +88,7 @@ persistent_notification: 0, plant: 3, weather: 4, + custom_ha_card: 0, }; // 4 types: diff --git a/src/more-infos/more-info-content.html b/src/more-infos/more-info-content.html index 398bcdd5813e..afdb5903b08c 100644 --- a/src/more-infos/more-info-content.html +++ b/src/more-infos/more-info-content.html @@ -48,8 +48,17 @@ this.lastChild.isVisible = false; } } else { + var moreInfoCardType; + var domain = window.hassUtil.computeDomain(stateObj); + if (domain === 'custom_ha_card' || domain === 'custom_state_card') { + moreInfoCardType = stateObj.attributes.more_info_card || 'MORE-INFO-HIDDEN'; + } else if (stateObj.attributes && 'custom_ui_more_info_card' in stateObj.attributes) { + moreInfoCardType = stateObj.attributes.custom_ui_more_info_card; + } else { + moreInfoCardType = 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(); + } window.hassUtil.dynamicContentUpdater( - this, 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(), + this, moreInfoCardType, { hass: hass, stateObj: stateObj, isVisible: true } ); } diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index 8c95f16ce8e3..faaab7daf286 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -40,7 +40,10 @@ inputChanged(hass, inDialog, stateObj) { let stateCardType; if (!stateObj || !hass) return; - if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { + var domain = window.hassUtil.computeDomain(stateObj); + if ((domain === 'custom_ha_card' || domain === 'custom_state_card') && stateObj.attributes && 'state_card' in stateObj.attributes) { + stateCardType = stateObj.attributes.state_card; + } else if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { stateCardType = stateObj.attributes.custom_ui_state_card; } else { stateCardType = 'state-card-' + window.hassUtil.stateCardType(hass, stateObj); From 74ef25fb3b8833662978052cb17e44c65e194e0f Mon Sep 17 00:00:00 2001 From: test <11984118+c727@users.noreply.github.com> Date: Tue, 30 Jan 2018 02:40:02 +0100 Subject: [PATCH 2/6] Rename ha_card to full_card --- src/cards/ha-card-chooser.html | 6 +++--- src/components/ha-cards.html | 2 +- src/more-infos/more-info-content.html | 2 +- src/state-summary/state-card-content.html | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 57e5feeea017..de022ccc5d99 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -24,9 +24,9 @@ if (!newData) return; var cardType; - if (newData.stateObj && window.hassUtil.computeDomain(newData.stateObj) === 'custom_ha_card' && newData.stateObj.attributes && 'ha_card' in newData.stateObj.attributes) { - cardType = newData.stateObj.attributes.ha_card.toUpperCase(); - } else if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_ha_card' in newData.stateObj.attributes) { + if (newData.stateObj && window.hassUtil.computeDomain(newData.stateObj) === 'custom_full_card' && newData.stateObj.attributes && 'full_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.full_card.toUpperCase(); + } else if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_full_card' in newData.stateObj.attributes) { cardType = newData.stateObj.attributes.custom_ui_ha_card.toUpperCase(); } else { cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; diff --git a/src/components/ha-cards.html b/src/components/ha-cards.html index 7a1b7d7eb03b..e3104c903bb8 100644 --- a/src/components/ha-cards.html +++ b/src/components/ha-cards.html @@ -88,7 +88,7 @@ persistent_notification: 0, plant: 3, weather: 4, - custom_ha_card: 0, + custom_full_card: 0, }; // 4 types: diff --git a/src/more-infos/more-info-content.html b/src/more-infos/more-info-content.html index afdb5903b08c..495c596518ac 100644 --- a/src/more-infos/more-info-content.html +++ b/src/more-infos/more-info-content.html @@ -50,7 +50,7 @@ } else { var moreInfoCardType; var domain = window.hassUtil.computeDomain(stateObj); - if (domain === 'custom_ha_card' || domain === 'custom_state_card') { + if (domain === 'custom_full_card' || domain === 'custom_state_card') { moreInfoCardType = stateObj.attributes.more_info_card || 'MORE-INFO-HIDDEN'; } else if (stateObj.attributes && 'custom_ui_more_info_card' in stateObj.attributes) { moreInfoCardType = stateObj.attributes.custom_ui_more_info_card; diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index faaab7daf286..026367198b82 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -41,7 +41,7 @@ let stateCardType; if (!stateObj || !hass) return; var domain = window.hassUtil.computeDomain(stateObj); - if ((domain === 'custom_ha_card' || domain === 'custom_state_card') && stateObj.attributes && 'state_card' in stateObj.attributes) { + if ((domain === 'custom_full_card' || domain === 'custom_state_card') && stateObj.attributes && 'state_card' in stateObj.attributes) { stateCardType = stateObj.attributes.state_card; } else if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { stateCardType = stateObj.attributes.custom_ui_state_card; From f4cebbabdaf413757ed5bea2061a190968afc9ac Mon Sep 17 00:00:00 2001 From: test <11984118+c727@users.noreply.github.com> Date: Tue, 30 Jan 2018 12:50:26 +0100 Subject: [PATCH 3/6] Use custom_ui_XXX for custom_card component --- src/cards/ha-card-chooser.html | 6 ++---- src/more-infos/more-info-content.html | 5 +---- src/state-summary/state-card-content.html | 5 +---- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index de022ccc5d99..809367fecc8c 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -24,10 +24,8 @@ if (!newData) return; var cardType; - if (newData.stateObj && window.hassUtil.computeDomain(newData.stateObj) === 'custom_full_card' && newData.stateObj.attributes && 'full_card' in newData.stateObj.attributes) { - cardType = newData.stateObj.attributes.full_card.toUpperCase(); - } else if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_full_card' in newData.stateObj.attributes) { - cardType = newData.stateObj.attributes.custom_ui_ha_card.toUpperCase(); + if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_full_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.custom_ui_full_card.toUpperCase(); } else { cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; } diff --git a/src/more-infos/more-info-content.html b/src/more-infos/more-info-content.html index 495c596518ac..2abbcc19aec9 100644 --- a/src/more-infos/more-info-content.html +++ b/src/more-infos/more-info-content.html @@ -49,10 +49,7 @@ } } else { var moreInfoCardType; - var domain = window.hassUtil.computeDomain(stateObj); - if (domain === 'custom_full_card' || domain === 'custom_state_card') { - moreInfoCardType = stateObj.attributes.more_info_card || 'MORE-INFO-HIDDEN'; - } else if (stateObj.attributes && 'custom_ui_more_info_card' in stateObj.attributes) { + if (stateObj.attributes && 'custom_ui_more_info_card' in stateObj.attributes) { moreInfoCardType = stateObj.attributes.custom_ui_more_info_card; } else { moreInfoCardType = 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(); diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index 026367198b82..8c95f16ce8e3 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -40,10 +40,7 @@ inputChanged(hass, inDialog, stateObj) { let stateCardType; if (!stateObj || !hass) return; - var domain = window.hassUtil.computeDomain(stateObj); - if ((domain === 'custom_full_card' || domain === 'custom_state_card') && stateObj.attributes && 'state_card' in stateObj.attributes) { - stateCardType = stateObj.attributes.state_card; - } else if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { + if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { stateCardType = stateObj.attributes.custom_ui_state_card; } else { stateCardType = 'state-card-' + window.hassUtil.stateCardType(hass, stateObj); From 2daf3c18cc98843ebd53f6e5a0ccdb47d7248fc3 Mon Sep 17 00:00:00 2001 From: test <11984118+c727@users.noreply.github.com> Date: Tue, 30 Jan 2018 12:58:56 +0100 Subject: [PATCH 4/6] Lint --- 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 809367fecc8c..ef5c156a0fde 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -29,7 +29,7 @@ } else { cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; } - + window.hassUtil.dynamicContentUpdater(this, cardType, newData); } } From e999425ee923139a8ebb7d0e19174bbe1a769787 Mon Sep 17 00:00:00 2001 From: test <11984118+c727@users.noreply.github.com> Date: Tue, 30 Jan 2018 18:23:06 +0100 Subject: [PATCH 5/6] Add new cards to customization config --- src/util/hass-attributes-util.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/hass-attributes-util.html b/src/util/hass-attributes-util.html index af74b3b97c29..05175100aed8 100644 --- a/src/util/hass-attributes-util.html +++ b/src/util/hass-attributes-util.html @@ -64,7 +64,9 @@ homebridge_name: { type: 'string' }, supported_features: undefined, attribution: undefined, + custom_ui_full_card: { type: 'string' }, custom_ui_state_card: { type: 'string' }, + custom_ui_more_info_card: { type: 'string' }, device_class: { type: 'array', options: window.hassAttributeUtil.DOMAIN_DEVICE_CLASS, From 121f1ff01aef1b5ad8248f91a6ff4bd5d8abdbc1 Mon Sep 17 00:00:00 2001 From: test <11984118+c727@users.noreply.github.com> Date: Tue, 30 Jan 2018 20:41:55 +0100 Subject: [PATCH 6/6] Move cusotm_ui stuff to another PR --- src/cards/ha-card-chooser.html | 12 ++++-------- src/more-infos/more-info-content.html | 8 +------- src/util/hass-attributes-util.html | 2 -- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index ef5c156a0fde..84ee7558cf13 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -23,14 +23,10 @@ cardDataChanged(newData) { if (!newData) return; - var cardType; - if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_full_card' in newData.stateObj.attributes) { - cardType = newData.stateObj.attributes.custom_ui_full_card.toUpperCase(); - } else { - cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; - } - - window.hassUtil.dynamicContentUpdater(this, cardType, newData); + window.hassUtil.dynamicContentUpdater( + this, 'HA-' + newData.cardType.toUpperCase() + '-CARD', + newData + ); } } customElements.define(HaCardChooser.is, HaCardChooser); diff --git a/src/more-infos/more-info-content.html b/src/more-infos/more-info-content.html index 2abbcc19aec9..398bcdd5813e 100644 --- a/src/more-infos/more-info-content.html +++ b/src/more-infos/more-info-content.html @@ -48,14 +48,8 @@ this.lastChild.isVisible = false; } } else { - var moreInfoCardType; - if (stateObj.attributes && 'custom_ui_more_info_card' in stateObj.attributes) { - moreInfoCardType = stateObj.attributes.custom_ui_more_info_card; - } else { - moreInfoCardType = 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(); - } window.hassUtil.dynamicContentUpdater( - this, moreInfoCardType, + this, 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(), { hass: hass, stateObj: stateObj, isVisible: true } ); } diff --git a/src/util/hass-attributes-util.html b/src/util/hass-attributes-util.html index 05175100aed8..af74b3b97c29 100644 --- a/src/util/hass-attributes-util.html +++ b/src/util/hass-attributes-util.html @@ -64,9 +64,7 @@ homebridge_name: { type: 'string' }, supported_features: undefined, attribution: undefined, - custom_ui_full_card: { type: 'string' }, custom_ui_state_card: { type: 'string' }, - custom_ui_more_info_card: { type: 'string' }, device_class: { type: 'array', options: window.hassAttributeUtil.DOMAIN_DEVICE_CLASS,