<commit_before>var overrideTemp = Number(0.0);

function getNewValues( immediate, initial ) {
  var url = "/heating/get/all_details";
  if( immediate ) {
    url = url + "/no_wait";
  }
  var qry = $.ajax({
    method: "GET",
    url: url,
    dataType: "json",
    cache: false
  })
  .done( function( data ) {
    processNewValues( data );
  })
  .always( function( data, textStatus, jqXHR ) {
    if ( initial )
      setTimeout( function() { getNewValues( false, initial )}, 55000 );
  });
}

function processNewValues( data ) {
  if (data.allowed_update) {
    enableChanges();
  } else {
    disableChanges();
  }

  for ( var key in data.temps ) {
    let timeout = $( "#"+key+"temp" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#"+key+"temp" ).html( data.temps[key].toFixed(1) + "&deg;" );
    $( "#"+key+"temp" ).data( "timeout", setTimeout(function() { $( "#"+key+"temp" ).text( "Unknown" ); }, 121000) );
  }

  if ( data.hasOwnProperty( "heating" ) ) {
    let timeout = $( "#heatingstatus" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#heatingstatus" ).data( "timeout", setTimeout(function() { $( "#heatingstatus" ).text( "Unknown" ); }, 121000 ) );

    if ( data.heating ) {
      $( "#heatingstatus" ).removeClass( "bgwhite" ).addClass( "bgred" ).text( "Heating: On" );
    } else {
      $( "#heatingstatus" ).removeClass( "bgred" ).addClass( "bgwhite" ).text( "Heating: Off" );
    }
  }

  if ( data.hasOwnProperty( "heating" ) ) {
    let timeout = $( "#preheatstatus" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#preheatstatus" ).data( "timeout", setTimeout(function() { $( "#preheatstatus" ).text( "Unknown" ); }, 121000 ) );
    if ( data.preheat ) {
      $( "#preheatstatus" ).removeClass( "bgwhite" ).addClass( "bgorange" ).text( "Preheat: On" );
    } else {
      $( "#preheatstatus" ).removeClass( "bgorange" ).addClass( "bgwhite" ).text( "Preheat: Off" );
    }
  }

  if (!isNaN(parseFloat(data.currentsetpoint)) && !isNaN(parseFloat(data.override))) {
    let timeout = $( "#currentsetpoint" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#currentsetpoint" ).data( "timeout", setTimeout(function() { $( "#currentsetpoint" ).text( "Unknown" ); }, 121000 ) );
    let currentsetpoint = Number(data.currentsetpoint.toFixed(1));
    overrideTemp = Number(data.override.toFixed(1));

    if ( overrideTemp > 0 ) {
      currentsetpoint = "" + currentsetpoint + "+" + overrideTemp + "&deg;";
    } else if ( overrideTemp < 0 ) {
      currentsetpoint = "" + currentsetpoint + overrideTemp + "&deg;";
    } else {
      currentsetpoint = "" + currentsetpoint + "&deg;";
    }
    $( "#currentsetpoint" ).html( currentsetpoint );

    $( "#override" ).html( "Override by " + overrideTemp + "&deg;" );
  }

  if ( data.nextsetpoint ) {
    let timeout = $( "#nextsetpoint" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#nextsetpoint" ).data( "timeout", setTimeout(function() { $( "#nextsetpoint" ).text( "Unknown" ); }, 121000 ) );
    $( "#nextsetpoint" ).html( data.nextsetpoint.toFixed(1) + "&deg;" );
  } else {
    $( "#nextsetpoint" ).text( "Unknown" ) ;
  }

  if ( data.nexteventstart ) {
    let timeout = $( "#nexteventstart" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#nexteventstart" ).data( "timeout", setTimeout(function() { $( "#nexteventstart" ).text( "Unknown" ); }, 121000 ) );
    var nexteventstart = new moment( data.nexteventstart );
    $( "#nexteventstart" ).text( nexteventstart.format( "DD/MM/YYYY HH:mm" ));
  } else {
    $( "#nexteventstart" ).text( "Unknown" );
  }

  var goneOutUntil = "";
  if ( data.goneoutuntil ) {
    goneOutUntil = moment( data.goneoutuntil );
    $( "#goneoutuntil" ).val( goneOutUntil.format( "HH:mm" ) );
  } else {
    $( "#goneoutuntil" ).val( "" );
  }
}

function enableChanges() {
  $( "#decrease" ).show()
    .click( function() {
      overrideTemp -= 0.5;
      $.ajax({
        method: "POST",
        url: "/heating/set/override/" + overrideTemp
      })
        .done( function () { getNewValues( true, false ) } );
    }
  );

  $( "#increase" ).show()
    .click( function() {
      overrideTemp += 0.5;
      $.ajax({
        method: "POST",
        url: "/heating/set/override/" + overrideTemp
      })
        .done( function () { getNewValues( true, false ) } );
    }
  );

  $( "#clear" ).show()
    .click( function() {
      $( "#goneoutuntil" ).val( "" );
      $.ajax({
        method: "POST",
        url: "/heating/set/gone_out_until/null"
      })
        .done( function () { getNewValues( true, false ) } )<commit_msg>Remove and re-add functions to stop adding a new one each time the script is run<commit_after>var overrideTemp = Number(0.0);

function getNewValues( immediate, initial ) {
  var url = "/heating/get/all_details";
  if( immediate ) {
    url = url + "/no_wait";
  }
  var qry = $.ajax({
    method: "GET",
    url: url,
    dataType: "json",
    cache: false
  })
  .done( function( data ) {
    processNewValues( data );
  })
  .always( function( data, textStatus, jqXHR ) {
    if ( initial )
      setTimeout( function() { getNewValues( false, initial )}, 55000 );
  });
}

function processNewValues( data ) {
  if (data.allowed_update) {
    enableChanges();
  } else {
    disableChanges();
  }

  for ( var key in data.temps ) {
    let timeout = $( "#"+key+"temp" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#"+key+"temp" ).html( data.temps[key].toFixed(1) + "&deg;" );
    $( "#"+key+"temp" ).data( "timeout", setTimeout(function() { $( "#"+key+"temp" ).text( "Unknown" ); }, 121000) );
  }

  if ( data.hasOwnProperty( "heating" ) ) {
    let timeout = $( "#heatingstatus" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#heatingstatus" ).data( "timeout", setTimeout(function() { $( "#heatingstatus" ).text( "Unknown" ); }, 121000 ) );

    if ( data.heating ) {
      $( "#heatingstatus" ).removeClass( "bgwhite" ).addClass( "bgred" ).text( "Heating: On" );
    } else {
      $( "#heatingstatus" ).removeClass( "bgred" ).addClass( "bgwhite" ).text( "Heating: Off" );
    }
  }

  if ( data.hasOwnProperty( "heating" ) ) {
    let timeout = $( "#preheatstatus" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#preheatstatus" ).data( "timeout", setTimeout(function() { $( "#preheatstatus" ).text( "Unknown" ); }, 121000 ) );
    if ( data.preheat ) {
      $( "#preheatstatus" ).removeClass( "bgwhite" ).addClass( "bgorange" ).text( "Preheat: On" );
    } else {
      $( "#preheatstatus" ).removeClass( "bgorange" ).addClass( "bgwhite" ).text( "Preheat: Off" );
    }
  }

  if (!isNaN(parseFloat(data.currentsetpoint)) && !isNaN(parseFloat(data.override))) {
    let timeout = $( "#currentsetpoint" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#currentsetpoint" ).data( "timeout", setTimeout(function() { $( "#currentsetpoint" ).text( "Unknown" ); }, 121000 ) );
    let currentsetpoint = Number(data.currentsetpoint.toFixed(1));
    overrideTemp = Number(data.override.toFixed(1));

    if ( overrideTemp > 0 ) {
      currentsetpoint = "" + currentsetpoint + "+" + overrideTemp + "&deg;";
    } else if ( overrideTemp < 0 ) {
      currentsetpoint = "" + currentsetpoint + overrideTemp + "&deg;";
    } else {
      currentsetpoint = "" + currentsetpoint + "&deg;";
    }
    $( "#currentsetpoint" ).html( currentsetpoint );

    $( "#override" ).html( "Override by " + overrideTemp + "&deg;" );
  }

  if ( data.nextsetpoint ) {
    let timeout = $( "#nextsetpoint" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#nextsetpoint" ).data( "timeout", setTimeout(function() { $( "#nextsetpoint" ).text( "Unknown" ); }, 121000 ) );
    $( "#nextsetpoint" ).html( data.nextsetpoint.toFixed(1) + "&deg;" );
  } else {
    $( "#nextsetpoint" ).text( "Unknown" ) ;
  }

  if ( data.nexteventstart ) {
    let timeout = $( "#nexteventstart" ).data( "timeout" );
    if ( timeout != 0 )
      clearTimeout( timeout );
    $( "#nexteventstart" ).data( "timeout", setTimeout(function() { $( "#nexteventstart" ).text( "Unknown" ); }, 121000 ) );
    var nexteventstart = new moment( data.nexteventstart );
    $( "#nexteventstart" ).text( nexteventstart.format( "DD/MM/YYYY HH:mm" ));
  } else {
    $( "#nexteventstart" ).text( "Unknown" );
  }

  var goneOutUntil = "";
  if ( data.goneoutuntil ) {
    goneOutUntil = moment( data.goneoutuntil );
    $( "#goneoutuntil" ).val( goneOutUntil.format( "HH:mm" ) );
  } else {
    $( "#goneoutuntil" ).val( "" );
  }
}

function enableChanges() {
  $( "#decrease" ).show()
    .off( "click" )
    .click( function() {
      overrideTemp -= 0.5;
      $.ajax({
        method: "POST",
        url: "/heating/set/override/" + overrideTemp
      })
        .done( function () { getNewValues( true, false ) } );
    }
  );

  $( "#increase" ).show()
    .off( "click" )
    .click( function() {
      overrideTemp += 0.5;
      $.ajax({
        method: "POST",
        url: "/heating/set/override/" + overrideTemp
      })
        .done( function () { getNewValues( true, false ) } );
    }
  );

  $( "#clear" ).show()
    .off( "click" )
    .click( function() {
      $( "#goneoutuntil" ).val( "" );
      $.ajax({
        method: "POST",
        url: "/heating/set/gone_out_until/null"
      })
        .done( function () { getNewValues( true, false ) } )
{'fraction_non_alphanumeric': 0.20188620582443775, 'fraction_numerical': 0.012229246554047052, 'mean_word_length': 2.8832997987927564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '175023', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3170, 'n_words': 703}