Skip to content

Commit

Permalink
Shorten isInverted checks
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Krug <michi.krug@gmail.com>
  • Loading branch information
michikrug committed Mar 27, 2022
1 parent 7ef0a09 commit 53c4d16
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion functions/commands/charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Charge extends DefaultCommand {

static convertParamsToValue(params, _, device) {
let charge = params.charge;
if (this.isInverted(device) === true) {
if (this.isInverted(device)) {
charge = !charge;
}
return charge ? 'ON' : 'OFF';
Expand Down
2 changes: 1 addition & 1 deletion functions/commands/mute.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Mute extends DefaultCommand {
if (itemType !== 'Switch') {
return mute ? '0' : undefined;
}
if (this.isInverted(device) === true) {
if (this.isInverted(device)) {
mute = !mute;
}
return mute ? 'ON' : 'OFF';
Expand Down
2 changes: 1 addition & 1 deletion functions/commands/onoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OnOff extends DefaultCommand {

static convertParamsToValue(params, _, device) {
let on = params.on;
if (this.isInverted(device) === true) {
if (this.isInverted(device)) {
on = !on;
}
return on ? 'ON' : 'OFF';
Expand Down
2 changes: 1 addition & 1 deletion functions/commands/openclose.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OpenClose extends DefaultCommand {
throw { statusCode: 400 };
}
let openPercent = params.openPercent;
if (this.isInverted(device) === true) {
if (this.isInverted(device)) {
openPercent = 100 - openPercent;
}
if (itemType === 'Rollershutter') {
Expand Down
7 changes: 7 additions & 0 deletions tests/commands/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ describe('Default Command', () => {
expect(Command.getItemName({ name: 'Item' }, {})).toBe('Item');
});

test('isInverted', () => {
expect(Command.isInverted({})).toBe(false);
expect(Command.isInverted({ id: 'Item', customData: {} })).toBe(false);
expect(Command.isInverted({ id: 'Item', customData: { inverted: false } })).toBe(false);
expect(Command.isInverted({ id: 'Item', customData: { inverted: true } })).toBe(true);
});

test('requiresItem', () => {
expect(Command.requiresItem({})).toBe(false);
});
Expand Down

0 comments on commit 53c4d16

Please sign in to comment.