Skip to content

Commit d1d26f6

Browse files
committed
Add a setting "invert_percentage"
1 parent 8891a0b commit d1d26f6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This card allows to open, close or set a shutter to the opening rate you want.
2424
| name | string | False | _Friendly name of the entity_ | Name to display for the shutter
2525
| buttons_position | string | False | `left` | Set buttons on `left` or on `right` of the shutter
2626
| title_position | string | False | `top` | Set title on `top` or on `bottom` of the shutter
27+
| invert_percentage | boolean | False | `false` | Set it to `true` if your shutter is 100% when it is closed, and 0% when it is opened
2728

2829
_Remark : you can also just give the entity ID (without to specify `entity:`) if you don't need to specify the other configurations._
2930

hass-shutter-card.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class ShutterCard extends HTMLElement {
3131
if (entity && entity.title_position) {
3232
titlePosition = entity.title_position.toLowerCase();
3333
}
34+
35+
let invertPercentage = false;
36+
if (entity && entity.invert_percentage) {
37+
invertPercentage = entity.invert_percentage;
38+
}
3439

3540
let shutter = document.createElement('div');
3641

@@ -107,7 +112,11 @@ class ShutterCard extends HTMLElement {
107112

108113
let percentagePosition = (newPosition - _this.minPosition) * 100 / (_this.maxPosition - _this.minPosition);
109114

110-
_this.updateShutterPosition(hass, entityId, 100 - percentagePosition);
115+
if (invertPercentage) {
116+
_this.updateShutterPosition(hass, entityId, percentagePosition);
117+
} else {
118+
_this.updateShutterPosition(hass, entityId, 100 - percentagePosition);
119+
}
111120

112121
document.removeEventListener('mousemove', mouseMove);
113122
document.removeEventListener('touchmove', mouseMove);
@@ -184,6 +193,11 @@ class ShutterCard extends HTMLElement {
184193
if (entity && entity.entity) {
185194
entityId = entity.entity;
186195
}
196+
197+
let invertPercentage = false;
198+
if (entity && entity.invert_percentage) {
199+
invertPercentage = entity.invert_percentage;
200+
}
187201

188202
const shutter = _this.card.querySelector('div[data-shutter="' + entityId +'"]');
189203
const slide = shutter.querySelector('.sc-shutter-selector-slide');
@@ -201,7 +215,12 @@ class ShutterCard extends HTMLElement {
201215
shutter.querySelectorAll('.sc-shutter-position').forEach(function (shutterPosition) {
202216
shutterPosition.innerHTML = currentPosition + '%';
203217
})
204-
_this.setPickerPositionPercentage(100 - currentPosition, picker, slide);
218+
219+
if (invertPercentage) {
220+
_this.setPickerPositionPercentage(currentPosition, picker, slide);
221+
} else {
222+
_this.setPickerPositionPercentage(100 - currentPosition, picker, slide);
223+
}
205224
}
206225
});
207226
}

0 commit comments

Comments
 (0)