Skip to content

Commit

Permalink
Add a setting "invert_percentage"
Browse files Browse the repository at this point in the history
  • Loading branch information
Deejayfool committed Jun 27, 2020
1 parent 8891a0b commit d1d26f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This card allows to open, close or set a shutter to the opening rate you want.
| name | string | False | _Friendly name of the entity_ | Name to display for the shutter
| buttons_position | string | False | `left` | Set buttons on `left` or on `right` of the shutter
| title_position | string | False | `top` | Set title on `top` or on `bottom` of the shutter
| invert_percentage | boolean | False | `false` | Set it to `true` if your shutter is 100% when it is closed, and 0% when it is opened

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

Expand Down
23 changes: 21 additions & 2 deletions hass-shutter-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ShutterCard extends HTMLElement {
if (entity && entity.title_position) {
titlePosition = entity.title_position.toLowerCase();
}

let invertPercentage = false;
if (entity && entity.invert_percentage) {
invertPercentage = entity.invert_percentage;
}

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

Expand Down Expand Up @@ -107,7 +112,11 @@ class ShutterCard extends HTMLElement {

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

_this.updateShutterPosition(hass, entityId, 100 - percentagePosition);
if (invertPercentage) {
_this.updateShutterPosition(hass, entityId, percentagePosition);
} else {
_this.updateShutterPosition(hass, entityId, 100 - percentagePosition);
}

document.removeEventListener('mousemove', mouseMove);
document.removeEventListener('touchmove', mouseMove);
Expand Down Expand Up @@ -184,6 +193,11 @@ class ShutterCard extends HTMLElement {
if (entity && entity.entity) {
entityId = entity.entity;
}

let invertPercentage = false;
if (entity && entity.invert_percentage) {
invertPercentage = entity.invert_percentage;
}

const shutter = _this.card.querySelector('div[data-shutter="' + entityId +'"]');
const slide = shutter.querySelector('.sc-shutter-selector-slide');
Expand All @@ -201,7 +215,12 @@ class ShutterCard extends HTMLElement {
shutter.querySelectorAll('.sc-shutter-position').forEach(function (shutterPosition) {
shutterPosition.innerHTML = currentPosition + '%';
})
_this.setPickerPositionPercentage(100 - currentPosition, picker, slide);

if (invertPercentage) {
_this.setPickerPositionPercentage(currentPosition, picker, slide);
} else {
_this.setPickerPositionPercentage(100 - currentPosition, picker, slide);
}
}
});
}
Expand Down

0 comments on commit d1d26f6

Please sign in to comment.