From 88ad11778596178ff272fb03acd0357b0f0b5aab Mon Sep 17 00:00:00 2001 From: janfromberlin <46612658+janfromberlin@users.noreply.github.com> Date: Sun, 3 Feb 2019 11:48:58 +0100 Subject: [PATCH] bugfix: button widget did not handle primitive boolean commands Tested with iobroker.rpi2 adapter and GPIOs of Raspberry 3B+ --- src/app/widgets/button/button.widget.js | 40 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/app/widgets/button/button.widget.js b/src/app/widgets/button/button.widget.js index 2edb7cd4..f6ee4b22 100755 --- a/src/app/widgets/button/button.widget.js +++ b/src/app/widgets/button/button.widget.js @@ -116,28 +116,48 @@ }); vm.sendCommand = function () { - if (this.widget.command === '') this.widget.command = true; - if (this.widget.command_alt === '') this.widget.command_alt = false; - + // Convert boolean-like commands to the data type of item state, to avoid comparison trouble. + if (typeof vm.state === "boolean") { + if (this.widget.command == null || this.widget.command === '' || this.widget.command === "true") { + this.widget.command = true; + } else if (this.widget.command === "false") { + this.widget.command = false; + } + if (this.widget.command_alt == null || this.widget.command_alt === '' || this.widget.command_alt === "false") { + this.widget.command_alt = false; + } else if (this.widget.command_alt === "true") { + this.widget.command_alt = true; + } + } else { + if (this.widget.command == null || this.widget.command === '' || this.widget.command === true) { + this.widget.command = "true"; + } else if (this.widget.command === false) { + this.widget.command = "false"; + } + if (this.widget.command_alt == null || this.widget.command_alt === '' || this.widget.command_alt === false) { + this.widget.command_alt = "false"; + } else if (this.widget.command_alt === true) { + this.widget.command_alt = "true"; + } + } + switch (vm.widget.action_type) { case "navigate": onNavigate(); break; case "toggle": - if (vm.widget.command != null && vm.widget.command_alt != null) { - if (vm.state === vm.widget.command) { - OHService.sendCmd(this.widget.item, this.widget.command_alt); - } else { - OHService.sendCmd(this.widget.item, this.widget.command); - } + if (vm.state === vm.widget.command) { + OHService.sendCmd(this.widget.item, this.widget.command_alt); + } else { + OHService.sendCmd(this.widget.item, this.widget.command); } break; default: OHService.sendCmd(this.widget.item, this.widget.command); break; } - } + }; }