Добрый день.
Пытаюсь настроить правила для управления группами освещения сконфигурированными на EcoDim.
Скомпилировал правило, но в логах выдаёт ошибку:
ERROR: [rule error] ECMAScript error: TypeError: invalid base value | |
---|---|
duk_hobject_props.c:2000 | |
getDevValue /usr/share/wb-rules-system/scripts/lib.js:70 preventsyield | |
switchDimmer_Hall /etc/wb-rules/Выключатели.js:153 preventsyield | |
apply native strict preventsyield | |
anon /etc/wb-rules/Выключатели.js:69 strict preventsyield | |
30-06-2024 22:00:42.146 [wb-rules] | ERROR: control ecodim_dali_gw2_21/Group 3 Brightness SetValue() error: can’t convert control value ‘true’ (type bool) to datatype ‘2’ |
Судя по ней ошибка в вспомогательной функции, которая инвертирует значение, но понять где и чего менять не могу пока.
С wb-rules и ECMA только разбираюсь.
Само правило:
(function () {
'use strict';
var ActionButtons = {};
ActionButtons.onButtonPress = function (trigger, action, timeToNextPress, timeOfLongPress) {
log.info("LongPress ActionButtons.onButtonPress")//Это лог. Он попадает в /var/log/messages
var buttonPressedCounter = 0;
var timerWaitNextShortPress = null;
var timerLongPress = null;
var isLongPress = false;
var ruleName = "on_button_press_" + trigger.replace("/", "_");
defineRule(ruleName, {
whenChanged: trigger,
then: function (newValue, devName, cellName) {
log.info("LongPress defineRule")//Лог
// If button is pressed, wait for a long press
if (newValue) {
if (timerWaitNextShortPress) {
clearTimeout(timerWaitNextShortPress);
}
timerLongPress = setTimeout(function () {
if (typeof action.longPress === "object") {
if (typeof action.longPress.func === "function") {
action.longPress.func.apply(this, action.longPress.prop);
}
}
// log(">>>>>>> long press <<<<<<");
isLongPress = true; // Long press identified, we will skip short press
buttonPressedCounter = 0;
}, timeOfLongPress);
}
// If button is released, then it is not a "long press", start to count clicks
else {
if (!isLongPress) {
clearTimeout(timerLongPress);
buttonPressedCounter += 1;
timerWaitNextShortPress = setTimeout(function () {
switch (buttonPressedCounter) {
// Counter equals 1 - it's a single short press
case 1:
if (typeof action.singlePress === "object") {
if (typeof action.singlePress.func === "function") {
action.singlePress.func.apply(this, action.singlePress.prop);
}
}
// log(">>>>>> short press - single <<<<<<");
break;
// Counter equals 2 - it's a double short press
case 2:
if (typeof action.doublePress === "object") {
if (typeof action.doublePress.func === "function") {
action.doublePress.func.apply(this, action.doublePress.prop);
}
}
// log(">>>>>> short press - double <<<<<<");
break;
}
// Reset the counter
buttonPressedCounter = 0;
}, timeToNextPress);
}
// Catch button released after long press
else {
if (typeof action.longRelease === "object") {
if (typeof action.longRelease.func === "function") {
if (typeof action.longRelease.prop === "array") {
action.longRelease.func.apply(this, action.longRelease.prop);
} else {
action.longRelease.func.apply(this, []);
}
}
}
isLongPress = false;
}
}
}
});
};
// export as Node module / AMD module / browser variable
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = ActionButtons;
} else if (typeof define === 'function' && define.amd) {
define(ActionButtons);
} else {
global.ActionButtons = ActionButtons;
}
}());
ActionButtons.onButtonPress(
"wb-gpio/EXT1_IN2", //Вход, за которым следим.
{
singlePress: {
func: switchDimmer_Hall,
prop: ["ecodim_dali_gw2_21", "Group 3 Brightness"]
},
doublePress: {
func: switchDimmer_Hall,
prop: ["ecodim_dali_gw2_21", "Group 3 Brightness"]
},
longPress: {
func: switchDimmer_Hall,
prop: ["ecodim_dali_gw2_21", "Group 3 Brightness"]
}
},
300, 1000
);
/**
* Helper Functions
*/
function switchRelay(device, control) { //Принимает в параметрах устройство и выход. Переключает состояние выхода на противоположное.
log.info("LongPress switchRelay" ,device, control)//Лог
dev[device][control] = !dev[device + "/" + control];
}
function switchDimmer_Hall(relayDevice, relayControl, dimmerDevice, range) {
dev[relayDevice][relayControl] = true;
if (dev[dimmerDevice + "/Brightness"+range] !== "0") {
dev[dimmerDevice]["Brightness"+range] == "254";
}
else {
dev[dimmerDevice]["Brightness"] = dev[relayDevice + "/Brightness"];
}
}