mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-23 14:18:53 +01:00
ohhhhhhh the callback signature
This commit is contained in:
@@ -25,6 +25,8 @@ var Characteristic = require("HAP-NodeJS").Characteristic;
|
|||||||
var url = require('url')
|
var url = require('url')
|
||||||
var request = require("request");
|
var request = require("request");
|
||||||
|
|
||||||
|
var communicationError = new Error('Can not communicate with Home Assistant.')
|
||||||
|
|
||||||
function HomeAssistantPlatform(log, config){
|
function HomeAssistantPlatform(log, config){
|
||||||
|
|
||||||
// auth info
|
// auth info
|
||||||
@@ -133,25 +135,25 @@ function HomeAssistantLight(log, data, client) {
|
|||||||
HomeAssistantLight.prototype = {
|
HomeAssistantLight.prototype = {
|
||||||
getPowerState: function(callback){
|
getPowerState: function(callback){
|
||||||
this.log("fetching power state for: " + this.name);
|
this.log("fetching power state for: " + this.name);
|
||||||
|
|
||||||
this.client.fetchState(this.entity_id, function(data){
|
this.client.fetchState(this.entity_id, function(data){
|
||||||
if (data) {
|
if (data) {
|
||||||
powerState = data.state == 'on'
|
powerState = data.state == 'on'
|
||||||
callback(powerState)
|
callback(null, powerState)
|
||||||
}else{
|
}else{
|
||||||
callback(null)
|
callback(communicationError)
|
||||||
}
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
getBrightness: function(callback){
|
getBrightness: function(callback){
|
||||||
this.log("fetching brightness for: " + this.name);
|
this.log("fetching brightness for: " + this.name);
|
||||||
that = this
|
|
||||||
this.client.fetchState(this.entity_id, function(data){
|
this.client.fetchState(this.entity_id, function(data){
|
||||||
if (data && data.attributes) {
|
if (data && data.attributes) {
|
||||||
that.log('returned brightness: ' + data.attributes.brightness)
|
|
||||||
brightness = ((data.attributes.brightness || 0) / 255)*100
|
brightness = ((data.attributes.brightness || 0) / 255)*100
|
||||||
callback(brightness)
|
callback(null, brightness)
|
||||||
}else{
|
}else{
|
||||||
callback(null)
|
callback(communicationError)
|
||||||
}
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
@@ -168,7 +170,7 @@ HomeAssistantLight.prototype = {
|
|||||||
that.log("Successfully set power state on the '"+that.name+"' to on");
|
that.log("Successfully set power state on the '"+that.name+"' to on");
|
||||||
callback()
|
callback()
|
||||||
}else{
|
}else{
|
||||||
callback(new Error('Can not communicate with Home Assistant.'))
|
callback(communicationError)
|
||||||
}
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
}else{
|
}else{
|
||||||
@@ -179,7 +181,7 @@ HomeAssistantLight.prototype = {
|
|||||||
that.log("Successfully set power state on the '"+that.name+"' to off");
|
that.log("Successfully set power state on the '"+that.name+"' to off");
|
||||||
callback()
|
callback()
|
||||||
}else{
|
}else{
|
||||||
callback(new Error('Can not communicate with Home Assistant.'))
|
callback(communicationError)
|
||||||
}
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
}
|
}
|
||||||
@@ -198,7 +200,7 @@ HomeAssistantLight.prototype = {
|
|||||||
that.log("Successfully set brightness on the '"+that.name+"' to " + level);
|
that.log("Successfully set brightness on the '"+that.name+"' to " + level);
|
||||||
callback()
|
callback()
|
||||||
}else{
|
}else{
|
||||||
callback(new Error('Can not communicate with Home Assistant.'))
|
callback(communicationError)
|
||||||
}
|
}
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user