dxdc/homebridge-blinds

Adding Status

Closed this issue · 2 comments

I'm trying to add in a status_url, without too much success. I have two methods that I can get data back from my controller;

I can get back a 0 for close (down), and a 100 for open (up). Doing this doesn't work well:

if (this.deviceType.match(/^blind/i)) {
// state vars
this.lastPosition = 0; // last known position of the blinds, down by default
this.lastStatePartial = 0;
this.currentPositionState = 2; // stopped by default
this.currentTargetPosition = 0; // down by default

// register the service and provide the functions
this.service = new Service.WindowCovering(this.name);

// the current position (0-100%)
// https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js#L493
this.service
    .getCharacteristic(Characteristic.CurrentPosition)
    .on('get', this.getCurrentStatePartial.bind(this));

// the position state
// 0 = DECREASING; 1 = INCREASING; 2 = STOPPED;
// https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js#L1138
this.service
    .getCharacteristic(Characteristic.PositionState)
    .on('get', this.getPositionState.bind(this));

// the target position (0-100%)
// https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js#L1564
this.service
    .getCharacteristic(Characteristic.TargetPosition)
    .on('get', this.getCurrentStatePartial.bind(this))
    .on('set', this.setTargetPosition.bind(this));

HttpMulti.prototype.getCurrentStatePartial = function(callback) {
this.log("Requested CurrentState: %s", this.lastStatePartial);
if (this.status_url !== undefined) {
request.get({
url: this.status_url,
}, function(error, response, body) {
this.log("Status_URL: %s", this.status_url);
if (!error && response.statusCode == 200) {
if (body !== undefined) {
if (!isNaN(parseFloat(body)) && isFinite(body)) {
this.lastStatePartial = parseInt(body);
this.log("Got Status %s",this.lastStatePartial);
} else {
this.log("Warning, status returned isn't numeric: %s",body);
}
} else {
this.log("Warning, data returned isn't defined");
}
this.log("callback CurrentState: %s", this.lastStatePartial);
callback(null, this.lastStatePartial);
}
}.bind(this));
} else {
callback(null, this.lastStatePartial);
}
}

Any ideas?

Hi @hplato!

First: why do you open an issue here instead doing so in the other project and assigning me there? ;)

Second, I assume you're not setting the state correctly in the accessory object, and as far as I remember that's what homebridge is reporting back. Wasn't this what I was doing in my original function? I will look into it tomorrow if you like.

Cheers

Neat, I didn’t know I could do that. I opened up the issue on my site, so you can close this.

On Oct 18, 2016, at 5:00 PM, Robin Temme notifications@github.com wrote:

Hi @hplato!

First: why do you open an issue here instead doing so in the other project and assigning me there? ;)

Second, I assume you're not setting the state correctly in the accessory object, and as far as I remember that's what homebridge is reporting back. Wasn't this what I was doing in my original function? I will look into it tomorrow if you like.

Cheers

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #6 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AExbSBXvpWvRjWLE4iCfzAzT8WO9ek9sks5q1U94gaJpZM4KaVz2.