-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dimmers New request method Added Switch Disabled security sensors
- Loading branch information
damianalarcon
committed
Sep 24, 2016
1 parent
89323c8
commit 85ae815
Showing
5 changed files
with
261 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
module.exports = function(HAPnode, config, functions) | ||
{ | ||
var Accessory = HAPnode.Accessory; | ||
var Service = HAPnode.Service; | ||
var Characteristic = HAPnode.Characteristic; | ||
var uuid = HAPnode.uuid; | ||
var debug = HAPnode.debug; | ||
|
||
var module = {}; | ||
|
||
module.newDevice = function(device) | ||
{ | ||
var Lightbulb = { | ||
powerOn: (parseInt(device.status) === 1)?true:false, | ||
|
||
setPower: function(on) | ||
{ | ||
if (on) | ||
{ | ||
binaryState = 1; | ||
Lightbulb.powerOn = true; | ||
} | ||
else | ||
{ | ||
binaryState = 0; | ||
Lightbulb.powerOn = false; | ||
} | ||
|
||
debug("Making request for device %s", device.name); | ||
|
||
return HAPnode.request({method:'GET',uri:"http://"+config.veraIP+":3480/data_request?id=lu_action&output_format=xml&DeviceNum=" + device.id + "&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=" + binaryState, resolveWithFullResponse: true}).then(function (res) | ||
{ | ||
if (res.statusCode === 200) | ||
{ | ||
status = (Lightbulb.powerOn)?'On':'Off'; | ||
debug("The %s has been turned %s", device.name, status); | ||
} | ||
else | ||
{ | ||
debug("Error while turning the %s on/off %s", device.name); | ||
} | ||
}); | ||
}, | ||
getStatus: function() | ||
{ | ||
debug("Making request for device %s", device.name); | ||
return HAPnode.request( | ||
{ | ||
method: 'POST', | ||
uri: 'http://'+config.veraIP+':3480/data_request?id=variableget&DeviceNum='+device.id+'&serviceId=urn:upnp-org:serviceId:SwitchPower1&Variable=Status', | ||
resolveWithFullResponse: true | ||
}).then(function (res) | ||
{ | ||
if (res.statusCode === 200) | ||
{ | ||
data = parseInt(res.body.toString('utf8')); | ||
this.powerOn = (data === 1)?true:false; | ||
status = (this.powerOn)?'On':'Off'; | ||
|
||
debug("Status for the light %s is %s", device.name, status); | ||
return this.powerOn; | ||
} | ||
else | ||
{ | ||
debug("Error while getting the status for %s", device.name); | ||
return this.powerOn; | ||
} | ||
}.bind(this)); | ||
}, | ||
identify: function() | ||
{ | ||
debug("Identify the light %s", device.name); | ||
} | ||
}; | ||
|
||
var light = new Accessory(device.name, uuid.generate('device:Lightbulb:'+config.cardinality+':'+device.id)); | ||
|
||
light.username = functions.genMac('device:'+config.cardinality+':'+device.id); | ||
light.pincode = config.pincode; | ||
light.deviceid = device.id; | ||
|
||
light | ||
.getService(Service.AccessoryInformation) | ||
.setCharacteristic(Characteristic.Manufacturer, "Oltica") | ||
.setCharacteristic(Characteristic.Model, "Rev-1") | ||
.setCharacteristic(Characteristic.SerialNumber, "A1S2NASF88EW"); | ||
|
||
light.on('identify', function(paired, callback) { | ||
Lightbulb.identify(); | ||
callback(); // success | ||
}); | ||
|
||
light | ||
.addService(Service.Lightbulb, device.name) | ||
.getCharacteristic(Characteristic.On) | ||
.on('set', function(value, callback) { | ||
Lightbulb.setPower(value); | ||
callback(); | ||
}); | ||
|
||
light | ||
.getService(Service.Lightbulb) | ||
.getCharacteristic(Characteristic.On) | ||
.on('get', function(callback) { | ||
var err = null; | ||
Lightbulb.getStatus().then(function(val) { | ||
callback(err, val); | ||
}); | ||
|
||
}); | ||
|
||
return light; | ||
}; | ||
|
||
return module; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module.exports = function(HAPnode, config, functions) | ||
{ | ||
var Accessory = HAPnode.Accessory; | ||
var Service = HAPnode.Service; | ||
var Characteristic = HAPnode.Characteristic; | ||
var uuid = HAPnode.uuid; | ||
var debug = HAPnode.debug; | ||
|
||
var module = {}; | ||
|
||
module.newScene = function(scene) | ||
{ | ||
var Switch = { | ||
powerOn: (parseInt(scene.active) === 1)?true:false, | ||
|
||
setPower: function(on) | ||
{ | ||
if (on) | ||
{ | ||
Switch.powerOn = true; | ||
} | ||
else | ||
{ | ||
Switch.powerOn = false; | ||
} | ||
|
||
debug("Making request for scene %s", scene.name); | ||
|
||
return HAPnode.request({method:'GET',uri:"http://"+config.veraIP+":3480/data_request?id=action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=" + scene.id, resolveWithFullResponse: true}).then(function (res) | ||
{ | ||
if (res.statusCode === 200) | ||
{ | ||
status = (Switch.powerOn)?'On':'Off'; | ||
debug("The scene %s has been turned %s", scene.name, status); | ||
} | ||
else | ||
{ | ||
debug("Error while turning the %s on/off %s", scene.name); | ||
} | ||
}); | ||
}, | ||
getStatus: function() | ||
{ | ||
return Switch.powerOn; | ||
}, | ||
identify: function() | ||
{ | ||
debug("Identify the light %s", scene.name); | ||
} | ||
}; | ||
|
||
var switchac = new Accessory(scene.name, uuid.generate('scene:switch:'+config.cardinality+':'+scene.id)); | ||
|
||
switchac.username = functions.genMac('scene:'+config.cardinality+':'+scene.id); | ||
switchac.pincode = config.pincode; | ||
switchac.deviceid = scene.id; | ||
|
||
switchac | ||
.getService(Service.AccessoryInformation) | ||
.setCharacteristic(Characteristic.Manufacturer, "Oltica") | ||
.setCharacteristic(Characteristic.Model, "Rev-1") | ||
.setCharacteristic(Characteristic.SerialNumber, "A1S2NASF88EW"); | ||
|
||
switchac.on('identify', function(paired, callback) { | ||
Switch.identify(); | ||
callback(); // success | ||
}); | ||
|
||
switchac | ||
.addService(Service.Switch, scene.name) | ||
.getCharacteristic(Characteristic.On) | ||
.on('set', function(value, callback) { | ||
Switch.setPower(value); | ||
callback(); | ||
}); | ||
|
||
switchac | ||
.getService(Service.Switch) | ||
.getCharacteristic(Characteristic.On) | ||
.on('get', function(callback) { | ||
callback(null, Switch.getStatus()); | ||
}); | ||
|
||
return switchac; | ||
}; | ||
|
||
return module; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Would you support a PR that lets a flag disable this, or exclude some device ids? Although there is technically a flag for active in scenes, UI7 has pretty much abandoned this, and scenes can be set up already in Homekit (but cannot be imported) so this tends to add quite a few crufty devices.