Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
goedh452 authored Aug 19, 2018
1 parent 79953a9 commit c0d8b4f
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ HttpSprinkler.prototype =

var that = this;

this.log("setPowerState function activatied");

if (!this.onUrl || !this.offUrl)
{
this.log("Ignoring request: No power url defined.");
Expand Down Expand Up @@ -197,12 +199,59 @@ HttpSprinkler.prototype =
}.bind(this))

this.log("HTTP power function succeeded!");
//this.valveService.getCharacteristic(Characteristic.InUse).updateValue(inuse);
this.valveService.getCharacteristic(Characteristic.InUse).updateValue(inuse);
callback();

},


setPowerStatePolling: function (powerOn, callback)
{
var url;
var body;
var inuse;

var that = this;

this.log("setPowerStatePolling function activatied");

if (!this.onUrl || !this.offUrl)
{
this.log("Ignoring request: No power url defined.");
callback(new Error("No power url defined."));
return;
}

if (powerOn)
{
url = this.onUrl;
inuse = 1;
this.log("Setting power state to on");
}
else
{
url = this.offUrl;
inuse = 0;
this.log("Setting power state to off");
}

this.httpRequest(url, "", "GET", function (error, response, body)
{
if (error)
{
that.log("HTTP set status function failed %s", error.message);
}
}.bind(this))

this.log("HTTP power function succeeded!");

// InUse characteristic is set with the polling mechanism

callback();

},


getServices: function ()
{
var that = this;
Expand Down Expand Up @@ -246,7 +295,7 @@ HttpSprinkler.prototype =
.on('get', function (callback)
{ callback(null, that.statusOn) })

.on('set', this.setPowerState.bind(this))
.on('set', this.setPowerStatePolling.bind(this))

break;
default:
Expand Down

0 comments on commit c0d8b4f

Please sign in to comment.