thermostat.php 7.31 KB
Newer Older
nextime's avatar
nextime committed
1
<? @include_once("../../includes/common.php"); ?>
nextime's avatar
nextime committed
2

nextime's avatar
nextime committed
3
<script>
nextime's avatar
nextime committed
4 5 6 7 8 9 10 11 12 13 14 15 16

function thermoResetGaugeLevel(g,l) {
   var gau=gaugeArray[g];
   gau.config.customSectors[2]={color: gau.config.customSectors[2].color,
                                  lo: gau.config.customSectors[2].lo,
                                  hi: l}
   gau.config.customSectors[3]={color: gau.config.customSectors[3].color,
                                  lo: l,
                                  hi: gau.config.customSectors[3].hi};
   gau.refresh(gau.config.value);

}

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
function changeClimaStatus(newstatus, request){
   $("[data-domotika-type=btn-choosestatuses]").each(
      function(){
         $(this).html("<b>"+newstatus+'<b> <i class="glyphicon glyphicon-chevron-down"></i>')
      }
   );
   $("[data-domotika-type=statusselect]").each(
      function(){
         if($(this).attr('data-domotika-statusselect')==newstatus)
            $(this).hide();
         else
            $(this).show();
      }
   );
   if(typeof(request)!='undefined') {
      console.debug("Change status to "+newstatus);
      $.post("/rest/v1.2/clima/status/json", 'status='+newstatus);
   }
}

37
function changeThermostatStatus(newstatus, parts2, parts3, nopost)
38 39 40
{
   var program=$("#thermo-btnprogram-"+parts2+'-'+parts3);
   var manual=$("#thermo-btnmanual-"+parts2+'-'+parts3);
41 42 43
   var slide=$("#thermo-level-"+parts2+'-'+parts3);
   if(typeof(nopost)=='undefined')
      nopost=false;
44 45 46
   if(newstatus=='manual'){
      program.alterClass(program.attr('data-dmcolor-on'), program.attr('data-dmcolor-off'));
      manual.alterClass(manual.attr('data-dmcolor-off'), manual.attr('data-dmcolor-on'));
47 48
      if(!nopost)
         $.post("/rest/v1.2/clima/thermostat/"+manual.attr('data-domotika-thermostat')+"/json", 'function=manual&set='+slide.val().toString());
49 50 51
   } else {
      program.alterClass(program.attr('data-dmcolor-off'), program.attr('data-dmcolor-on'));
      manual.alterClass(manual.attr('data-dmcolor-on'), manual.attr('data-dmcolor-off'));
52 53
      if(!nopost)
         $.post("/rest/v1.2/clima/thermostat/"+manual.attr('data-domotika-thermostat')+"/json", 'function=program');
54 55 56
   }
}

nextime's avatar
nextime committed
57 58 59 60 61 62
function checkSliderSet(slider){
   if(slider.data('lastchanged'))
   {
      if(Date.now()-slider.data('lastchanged')>1000)
      {
         slider.data('lastchanged', false);
63 64 65
         var parts=slider.attr('id').split('-');  
         changeThermostatStatus('manual', parts[2], parts[3]);

nextime's avatar
nextime committed
66 67 68 69 70 71 72 73 74 75
      }
   }
   if(slider.val()!=slider.data('oldval'))
   {
      slider.data('lastchanged', Date.now());
      slider.data('oldval', slider.val());
   }
   setTimeout(function(){checkSliderSet(slider)}, 500);
}

nextime's avatar
nextime committed
76 77 78
$("[data-domotika-type=thermo-level]").each(
   function(){
      $(this).noUiSlider({
nextime's avatar
nextime committed
79 80
         range: [parseFloat($(this).attr('data-domotika-minval')), parseFloat($(this).attr('data-domotika-maxval'))],
         start: parseFloat($(this).attr('data-domotika-setval')),
nextime's avatar
nextime committed
81 82 83 84 85 86 87 88
         handles: 1,
         connect: 'lower',
         orientation: 'vertical',
         direction: 'rtl',
         step:0.1,
         slide: function() {
                  var parts=$(this).attr('id').split("-");
                  $("#thermo-showset-"+parts[2]+'-'+parts[3]).text(parseFloat($(this).val()).toFixed(1));
nextime's avatar
nextime committed
89
                  thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val()));
90
               }
nextime's avatar
nextime committed
91
      });
nextime's avatar
nextime committed
92 93 94 95 96
      $(this).data('oldval', $(this).val());
      $(this).data('lastchanged', false);
      slider=$(this);
      setTimeout(function(){checkSliderSet(slider)}, 1000);

nextime's avatar
nextime committed
97 98 99 100 101 102 103 104 105 106 107 108
      var parts=$(this).attr('id').split('-');
      var btn=$("#thermo-showset-"+parts[2]+'-'+parts[3]);
      btn.text(parseFloat($(this).val()).toFixed(1));

      $(this).mousewheel(function(event) {
         if(event.deltaY>0)
            $(this).val(parseFloat($(this).val())+0.5);
         else if(event.deltaY<0)
            $(this).val(parseFloat($(this).val())-0.5);
         if(event.deltaY!=0)
         {
            $('#'+$(this).attr('id').replace('thermo-level-','thermo-showset-')).text(parseFloat($(this).val()).toFixed(1));
nextime's avatar
nextime committed
109
            thermoResetGaugeLevel('gauge-'+parts[2]+'-'+parts[3], parseFloat($(this).val()));
nextime's avatar
nextime committed
110 111 112
         }
      });

nextime's avatar
nextime committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
      var plus=$('#'+$(this).attr('id').replace('thermo-level-','thermo-plus-'));
      var minus=$('#'+$(this).attr('id').replace('thermo-level-','thermo-minus-'));

      minus.continouoshold(function(){
         var slide=$('#'+$(this).attr('id').replace('thermo-minus-','thermo-level-'));
         slide.val(parseFloat(slide.val())-0.5);
         $('#'+$(this).attr('id').replace('thermo-minus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1));
      }, 200, 700, true);

      plus.continouoshold(function(){
         var slide=$('#'+$(this).attr('id').replace('thermo-plus-','thermo-level-'));
         slide.val(parseFloat(slide.val())+0.5);
         $('#'+$(this).attr('id').replace('thermo-plus-','thermo-showset-')).text(parseFloat(slide.val()).toFixed(1));
      }, 200, 700, true);

nextime's avatar
nextime committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
   }
);

$("[data-domotika-type=btn-choosestatuses]").each(
   function() {
      $(this).fastClick(function(){
         var parts=$(this).attr('id').split("-");
         var panel="#thermo-statuschooselist-"+parts[2]+"-"+parts[3];
         if($(panel).css('display')=='block')
         {
            $(panel).hide(150);
         } else {
            $(panel).show(300);
         }
      });
   }
);

$("[data-domotika-type=statusselect]").each(
   function(){
      $(this).fastClick(function(){
         var panel="#"+$(this).attr('data-domotika-panel');
         $(panel).hide(150);
151 152
         var newstatus=$(this).attr('data-domotika-statusselect');
         changeClimaStatus(newstatus, true);
nextime's avatar
nextime committed
153 154 155 156
      });
   }
);

nextime's avatar
nextime committed
157 158 159 160 161
$("[data-domotika-type=btnprogram]").each(
   function(){$(this).fastClick(
      function() {
         var parts=$(this).attr('id').split("-");
         var other=$("#thermo-btnmanual-"+parts[2]+'-'+parts[3]);
162
         changeThermostatStatus('program', parts[2], parts[3]);
nextime's avatar
nextime committed
163 164 165 166 167 168 169 170
      });
   }
);

$("[data-domotika-type=btnmanual]").each(
   function(){$(this).fastClick(
      function() {
         var parts=$(this).attr('id').split("-");
171
         changeThermostatStatus('manual', parts[2], parts[3]);
nextime's avatar
nextime committed
172 173 174
      });
   }
);
nextime's avatar
nextime committed
175

176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
var thermostatEvent = function(event) {
   var data=$.parseJSON(event.data);
   console.debug(data);
   if(typeof(data.data.action) != 'undefined'){
      var action=data.data.action;
      if(action=='climastatus'){
         changeClimaStatus(data.data.status);        
      }else if(action=='function'){
         $("[data-domotika-thermostat="+jQueryEscapesel(data.data.thermostat)+"][data-domotika-type=btnprogram]").each(
            function(){
               var parts=$(this).attr('id').split("-");
               changeThermostatStatus(data.data.func, parts[2], parts[3], true);
            }
         );
      }else if(action=='setval'){
         $("[data-domotika-thermostat="+jQueryEscapesel(data.data.thermostat)+"][data-domotika-type=btnprogram]").each(
            function(){
               var parts=$(this).attr('id').split("-");
               var slide=$("#thermo-level-"+parts[2]+'-'+parts[3]);              
               slide.val(parseFloat(data.data.val));
nextime's avatar
nextime committed
196
               slider.data('oldval', slider.val());
197 198 199 200 201 202 203 204 205
               $('#thermo-showset-'+parts[2]+'-'+parts[3]).text(parseFloat(data.data.val).toFixed(1));
            }
         );
      }
   }
}

es.addEventListener("thermostat", thermostatEvent);

nextime's avatar
nextime committed
206 207
</script>