16 809
правок
Строка 349: | Строка 349: | ||
dev["water_meters/water_meter_1"] = ((parseInt(newValue) - counterCorrection) * inpulseValue) + meterCorrection; // Умножаем значение счетчика на количество литров/импульс и прибавляем корректировочное значение. | dev["water_meters/water_meter_1"] = ((parseInt(newValue) - counterCorrection) * inpulseValue) + meterCorrection; // Умножаем значение счетчика на количество литров/импульс и прибавляем корректировочное значение. | ||
} | } | ||
} | |||
}); | |||
</syntaxhighlight> | |||
== Инвертирование значения контрола == | |||
[[Image:wb-rules-ex-buzzer-invert.png|300px|thumb|right|Пример устройств с вкладки Устройства]] | |||
Правило ниже создаёт виртуальное устройство ''my-invert-buzzer'', с контролом ''disabled'', который инвертирует состояние контрола ''enabled'' системной пищалки ''Buzzer''. | |||
<syntaxhighlight lang="ecmascript"> | |||
defineVirtualDevice('my-invert-buzzer', { | |||
title: 'Buzzer Invert' , | |||
cells: { | |||
Disabled: { | |||
title: "disabled", | |||
type: "switch", | |||
value: !dev["buzzer/enabled"] | |||
} | |||
} | |||
}) | |||
defineRule({ | |||
whenChanged: ["buzzer/enabled"], | |||
then: function(newValue, devName, cellName) { | |||
dev["my-invert-buzzer/Disabled"] = !newValue; | |||
} | |||
}); | |||
defineRule({ | |||
whenChanged: ["my-invert-buzzer/Disabled"], | |||
then: function(newValue, devName, cellName){ | |||
dev["buzzer/enabled"] = !newValue; | |||
} | } | ||
}); | }); |