"use strict";

$(document).ready(function(){

  var $btnLight = $("#btnLight");

  var lightText = $btnLight.text();
  var lightOn;
  if (lightText = "Light On") {
    lightOn = true;
  } else {
    lightOn = false;
  }

  function toggleGarageDoor() {
    $.post("/toggle");
  }

  function turnLightOn() {
    $.post("/light?state=on");
  }

  function turnLightOff() {
    $.post("/light?state=off");
  }

  $("#btnDoorToggle").on("click", function( event ) {
    toggleGarageDoor();
  });

  $btnLight.on("click", function( event ) {
    if (lightOn) {
      turnLightOff();
      lightOn = false;
      $btnLight.text("Light On")
    } else {
      turnLightOn();
      lightOn = true;
      $btnLight.text("Light Off")
    }
  });
});

"use strict";

$(document).ready(function(){

  var $btnLight = $("#btnLight");

  var lightText = $btnLight.text();
  var lightOn = (lightText == "Light Off");

  function toggleGarageDoor() {
    $.post("/toggle");
  }

  function turnLightOn() {
    $.post("/light?state=on", parseLightState);
  }

  function turnLightOff() {
    $.post("/light?state=off", parseLightState);
  }

  function parseLightState(data) {
    data = $.parseJSON(data);
    lightOn = data.LightOn;

    if (lightOn) {
      $btnLight.text("Light Off");
    } else {
      $btnLight.text("Light On");
    }

    if (!data.StateKnown) {
      $btnLight.prop('disabled', true);
    }
  }

  $("#btnDoorToggle").on("click", function( event ) {
    toggleGarageDoor();
  });

  $btnLight.on("click", function( event ) {
    if (lightOn) {
      turnLightOff();
    } else {
      turnLightOn();
    }
  });
});

Add callback for homepage javascript light POST request.
Add callback for homepage javascript light POST request.
