Rule Examples/en: различия между версиями

Нет описания правки
Строка 82: Строка 82:
If you need several such motion detectors, then in order not to copy the code, you can wrap the creation of the rule and variables in a function:
If you need several such motion detectors, then in order not to copy the code, you can wrap the creation of the rule and variables in a function:


<div class="mw-translate-fuzzy">
<syntaxhighlight lang="ecmascript">
<syntaxhighlight lang="ecmascript">
  function makeMotionDetector(name, timeout_ms, detector_control, relay_control) {
  function makeMotionDetector(name, timeout_ms, detector_control, relay_control) {
Строка 90: Строка 89:
       then: function(newValue, devName, cellName) {
       then: function(newValue, devName, cellName) {
           if (!newValue) {
           if (!newValue) {
               dev["wb-gpio"][relay_control] = true;
               dev["wb-gpio/relay_control"] = true;
               if (motion_timer_id) {
               if (motion_timer_id) {
                   clearTimeout(motion_timer_id);
                   clearTimeout(motion_timer_id);
               }
               }
</div>


               <div class="mw-translate-fuzzy">
               motion_timer_id = setTimeout(function() {
motion_timer_id = setTimeout(function() {
                   dev["wb-gpio/relay_control"] = false;
                   dev["wb-gpio"][relay_control] = false;
                   motion_timer_id = null;
                   motion_timer_id = null;
               }, timeout_ms);
               }, timeout_ms);
Строка 105: Строка 102:
   });
   });
}
}
</div>


makeMotionDetector("motion_detector_1", 20000, "EXT1_DR1", "EXT2_R3A1");
makeMotionDetector("motion_detector_1", 20000, "EXT1_DR1", "EXT2_R3A1");
translator, wb_editors
4265

правок