Skip to content

Commit 159155a

Browse files
committed
Release 20180112
1 parent c31327e commit 159155a

11 files changed

+200
-55
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
## Changelog
22

33
*Note: Update to at least 20171227 required for HA 0.61+*
4+
5+
#### 2018-01-12
6+
* Allow setting margin on slider via `--ha-themed-slider-margin`.
7+
* Allow changing state-card badge margins via `--ha-badges-card-margin`.
8+
* `extra_badge`s can now be individually themed.
9+
* Allow changing the size and number of UI columns (requires `customizer`)
10+
411
#### 2017-12-27
512
* Hotfix for HA 0.61
613
* Change size of badges in state card to 85% to match the badges in the top section.

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
* **Update to at least 20171129 for HA 0.59-0.60**
3232
* **Update to at least 20171117 for HA 0.58**
3333

34+
#### 2018-01-12
35+
* Allow setting margin on slider via `--ha-themed-slider-margin`.
36+
* Allow changing state-card badge margins via `--ha-badges-card-margin`.
37+
* `extra_badge`s can now be individually themed.
38+
* Allow changing the size and number of UI columns (requires [customizer](https://github.com/andrey-git/home-assistant-customizer))
39+
3440
#### 2017-12-27
3541
* Hotfix for HA 0.61
3642
* Change size of badges in state card to 85% to match the badges in the top section.
@@ -63,13 +69,14 @@ See [installing](docs/installing.md)
6369
See [activating](docs/activating.md)
6470

6571
## Customizer component
66-
See instruction in dedicated repo: [https://github.com/andrey-git/home-assistant-customizer](https://github.com/andrey-git/home-assistant-customizer/)
72+
See instruction in a dedicated repository: [https://github.com/andrey-git/home-assistant-customizer](https://github.com/andrey-git/home-assistant-customizer/)
6773
Provides the following features:
6874
* Load CustomUI files (HA 0.53+)
6975
* Register CustomUI panel (HA 0.52 and below).
7076
* Hide CustomUI attributes in `more-info` (HA 0.50 - 0.52)
7177
* Hide arbitrary attributes in `more-info` (Requires HA 0.50+)
7278
* Dynamic customization.
79+
* Set the width and number of UI columns (Requires CustomUI 20180112+)
7380

7481

7582
## CustomUI panel
@@ -290,6 +297,9 @@ extra_badge:
290297
unit: W
291298
```
292299

300+
If you use the first format, i.e. a real sensor, you can use context-aware theming
301+
on it.
302+
293303
In both cases you can specify a blacklist of badge "states", when you don't want to see the badge.
294304
```yaml
295305
extra_badge:

src/hooks.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
window.customUI = window.customUI || {
3-
VERSION: '20171227',
3+
VERSION: '20180112',
44

55
SUPPORTED_SLIDER_MODES: [
66
'single-line', 'break-slider', 'break-slider-toggle', 'hide-slider', 'no-slider',

state-card-custom-ui-dbg-es5.html

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div hidden="" by-polymer-bundler=""><script>
22
window.customUI = window.customUI || {
3-
VERSION: '20171227',
3+
VERSION: '20180112',
44

55
SUPPORTED_SLIDER_MODES: ['single-line', 'break-slider', 'break-slider-toggle', 'hide-slider', 'no-slider'],
66

@@ -33,6 +33,7 @@
3333
}
3434
break;
3535
case 'MORE-INFO-GROUP':
36+
case 'STATE-CARD-CONTENT':
3637
if (element.stateObj) {
3738
elem._context.push(element.stateObj.entity_id);
3839
}
@@ -216,10 +217,30 @@
216217
version.textContent = 'Custom UI ' + window.customUI.VERSION;
217218
about.insertBefore(version, secondP);
218219
},
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+
},
219237
useCustomizer: function useCustomizer() {
220238
var main = window.customUI.lightOrShadow(document, 'home-assistant');
221239
var customizer = main.hass.states['customizer.customizer'];
222240
if (!customizer) return;
241+
if (customizer.attributes.columns) {
242+
window.customUI.controlColumns(customizer.attributes.columns);
243+
}
223244

224245
if (customizer.attributes.hide_attributes) {
225246
if (window.hassUtil.LOGIC_STATE_ATTRIBUTES) {
@@ -459,6 +480,9 @@
459480
<dom-module id="ha-themed-slider">
460481
<template>
461482
<style>
483+
:host {
484+
margin: var(--ha-themed-slider-margin, initial);
485+
}
462486
.disable-off-when-min {
463487
--paper-slider-pin-start-color: var(--paper-slider-pin-color);
464488
}
@@ -707,7 +731,7 @@
707731
</style>
708732
<div class$="[[extraClass(extraObjVisible)]] horizontal layout">
709733
<template is="dom-if" if="[[extraObjVisible]]">
710-
<template is="dom-repeat" items="[[extraObj]]">
734+
<template is="dom-repeat" items="[[extraObj]]" on-dom-change="extraDomChanged">
711735
<ha-state-label-badge hass="[[hass]]" state="[[item]]"></ha-state-label-badge>
712736
</template>
713737
</template>
@@ -752,20 +776,35 @@
752776
}
753777

754778
_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+
}, {
755791
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 [];
758796
var extraBadges = stateObj.attributes.extra_badge;
759797
if (!Array.isArray(extraBadges)) {
760798
extraBadges = [extraBadges];
761799
}
762800
return extraBadges.map(function (extraBadge) {
763801
var result = null;
764802
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) {
767806
result = {
768-
state: stateObj.attributes[extraBadge.attribute],
807+
state: String(stateObj.attributes[extraBadge.attribute]),
769808
_domain: 'none',
770809
entity_id: null,
771810
attributes: { unit_of_measurement: extraBadge.unit }
@@ -823,7 +862,7 @@
823862
}, {
824863
key: 'tapHandler',
825864
value: function tapHandler(e) {
826-
var _this2 = this;
865+
var _this3 = this;
827866

828867
this.$$('#overlay').style.pointerEvents = 'none';
829868
var lock = this.$$('#lock');
@@ -832,14 +871,29 @@
832871
lock.style.opacity = '0.1';
833872
}
834873
window.setTimeout(function () {
835-
_this2.$$('#overlay').style.pointerEvents = '';
874+
_this3.$$('#overlay').style.pointerEvents = '';
836875
if (lock) {
837876
lock.icon = 'mdi:lock-outline';
838877
lock.style.opacity = '';
839878
}
840879
}, 5000);
841880
e.stopPropagation();
842881
}
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+
}
843897
}], [{
844898
key: 'is',
845899
get: function get() {
@@ -858,8 +912,9 @@
858912
controlElement: String,
859913
extraObj: {
860914
type: Array,
861-
computed: 'computeExtra(hass, stateObj)'
915+
computed: 'computeExtra(hass, stateObj, _attached)'
862916
},
917+
_attached: Boolean,
863918
extraObjVisible: {
864919
type: Boolean,
865920
computed: 'computeExtraVisible(extraObj, inDialog)'
@@ -993,11 +1048,14 @@
9931048
}, {
9941049
key: '_setMode',
9951050
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+
};
9981055
if (!this.showSlider) {
999-
this.breakSlider = true;
1056+
obj.breakSlider = true;
10001057
}
1058+
this.setProperties(obj);
10011059
}
10021060
}, {
10031061
key: '_onIronResize',
@@ -1007,15 +1065,19 @@
10071065
return;
10081066
}
10091067
if (this.mode === 'no-slider') {
1010-
this.hideSlider = true;
1011-
this.breakSlider = true;
1068+
this.setProperties({
1069+
hideSlider: true,
1070+
breakSlider: true
1071+
});
10121072
return;
10131073
}
10141074
var prevBreakSlider = this.breakSlider;
10151075
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+
});
10191081
var container = this.$.container;
10201082

10211083
var containerWidth = container.clientWidth;
@@ -1100,21 +1162,22 @@
11001162
this.sliderValue = 0;
11011163
}
11021164
if (stateObj) {
1103-
this.setProperties({
1165+
var obj = {
11041166
minLineBreak: 0,
11051167
maxLineBreak: 999,
11061168
hideSlider: false,
11071169
breakSlider: false,
11081170
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;
11121174
} else {
1113-
this.mode = DEFAULT_MODE;
1175+
obj.mode = DEFAULT_MODE;
11141176
}
11151177
if (stateObj.attributes.stretch_slider) {
1116-
this.stretchSlider = true;
1178+
obj.stretchSlider = true;
11171179
}
1180+
this.setProperties(obj);
11181181
this._waitForLayout();
11191182
}
11201183
}
@@ -1308,7 +1371,7 @@
13081371
this._container.style.display = 'inline-block';
13091372
var params = { display: 'inline-block' };
13101373
if (this._container.classList.contains('state')) {
1311-
params.margin = '0 -6px';
1374+
params.margin = 'var(--ha-badges-card-margin, 0 -6px)';
13121375
}
13131376
this.updateStyles(params);
13141377
}

state-card-custom-ui-dbg-es5.html.gz

370 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)