smartfritz-promise
Advanced tools
Comparing version 0.5.6 to 0.6.0
@@ -9,8 +9,2 @@ /** | ||
var request = require('request').defaults({ strictSSL: false }); // be less strict about SSL errors | ||
var cheerio = require('cheerio'); | ||
var parser = require('xml2json-light'); | ||
var extend = require('extend'); | ||
var Promise = require('bluebird'); | ||
var fritz = require('./smartfritz.js'); | ||
@@ -25,5 +19,16 @@ | ||
var ain = '109710195784'; | ||
fritz.getBatteryCharge(sid, ain).then(function(res) { | ||
console.log(res); | ||
fritz.getDeviceList(sid).then(function(deviceList) { | ||
console.log(deviceList); | ||
var options = { | ||
deviceList: deviceList | ||
} | ||
fritz.getSwitchList(sid, ain).then(function(ains) { | ||
console.log(ains); | ||
}); | ||
var ain = '109710195784'; | ||
fritz.getBatteryCharge(sid, ain, options).then(function(res) { | ||
console.log(res); | ||
}); | ||
}); | ||
@@ -33,26 +38,32 @@ | ||
console.log(res); | ||
}); | ||
res.activate_guest_access = true; | ||
fritz.setGuestWlan(sid, res).then(function(res) { | ||
console.log(res); | ||
}); | ||
}); | ||
// display switch information | ||
fritz.getSwitchList(sid).then(function(switches) { | ||
console.log("Switches: " + switches); | ||
// fritz.getSwitchList(sid).then(function(switches) { | ||
// console.log("Switches: " + switches); | ||
if (switches.length) { | ||
fritz.getSwitchName(sid, switches[0]).then(function(name) { | ||
console.log("Switch name [" + switches[0] + "]: " + name); | ||
// if (switches.length) { | ||
// fritz.getSwitchName(sid, switches[0]).then(function(name) { | ||
// console.log("Switch name [" + switches[0] + "]: " + name); | ||
fritz.getSwitchPresence(sid, switches[0]).then(function(presence) { | ||
console.log("Switch presence [" + switches[0] + "]: " + presence); | ||
// fritz.getSwitchPresence(sid, switches[0]).then(function(presence) { | ||
// console.log("Switch presence [" + switches[0] + "]: " + presence); | ||
fritz.getSwitchState(sid, switches[0]).then(function(state) { | ||
console.log("Switch state [" + switches[0] + "]: " + state); | ||
}); | ||
// fritz.getSwitchState(sid, switches[0]).then(function(state) { | ||
// console.log("Switch state [" + switches[0] + "]: " + state); | ||
// }); | ||
fritz.getTemperature(sid, switches[0]).then(function(temp) { | ||
console.log("Switch temperature [" + switches[0] + "]: " + temp + "°C"); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); | ||
// fritz.getTemperature(sid, switches[0]).then(function(temp) { | ||
// console.log("Switch temperature [" + switches[0] + "]: " + temp + "°C"); | ||
// }); | ||
// }); | ||
// }); | ||
// } | ||
// }); | ||
@@ -59,0 +70,0 @@ // display thermostat information |
{ | ||
"name": "smartfritz-promise", | ||
"version": "0.5.6", | ||
"version": "0.6.0", | ||
"description": "SmartHome for Fritz!Box and Dect!200 Node to communicate with AVM FritzBox over the aha-http-interface", | ||
@@ -14,6 +14,2 @@ "author": { | ||
{ | ||
"name": "Andreas Goetz", | ||
"email": "cpuidle@gmx.de" | ||
}, | ||
{ | ||
"name": "Steffen Timm", | ||
@@ -20,0 +16,0 @@ "email": "s.timm@nischi.net" |
@@ -8,4 +8,5 @@ # smartfritz | ||
- Get the session ID (`getSessionID`) | ||
- Get device list as XML (`getDeviceListInfo`) >FritzOS 6.10 | ||
- Get device list (`getDeviceList`) >FritzOS 6.10 | ||
- Get device list as XML (`getDeviceListInfo`) >FritzOS 6.10 | ||
- Get device (`getDevice`) >FritzOS 6.10 | ||
- Get temperature (`getTemperature`) | ||
@@ -35,4 +36,7 @@ | ||
- Get night temperature (`getTempNight`) | ||
- Get battery charge status (`getBatteryCharge`) | ||
**Note** as of FritzOS 6.36 there is are no official function to obtain a list of thermostats, neither to get the thermostat's temperature. Also the switches `getSwitchTemperature()` function is not working in that firmware version. | ||
**Note** | ||
As of FritzOS 6.36 there is are no official function to obtain a list of thermostats, neither to get the thermostat's temperature. Also the switches `getSwitchTemperature()` function is not working in that firmware version. | ||
For an alternative approach the `getTemperature()` polyfill function was added which supports both switches and thermostats. | ||
@@ -42,5 +46,9 @@ | ||
- Get the guest wlan settings (`getGuestWlan`) | ||
- Set the guest wlan (`setGuestWlan`) | ||
- Get the guest wlan settings (`getGuestWlan`) | ||
**Note** | ||
`getGuestWlan` returns a structure containing all wifi settings found in the Fritz!Box UI. The `setGuestWlan` function accepts either a settings structure such as this or a single boolean value. | ||
All functions have been tested on FritzOS 6.20/6.36/6.51 using the FritzBox 7390. The WLAN functions may be less stable. | ||
@@ -47,0 +55,0 @@ |
@@ -205,2 +205,17 @@ /** | ||
module.exports.getDevice = function(sid, ain, options) | ||
{ | ||
var deviceList = options && options.deviceList | ||
? Promise.resolve(options.deviceList) | ||
: module.exports.getDeviceList(sid, options); | ||
return deviceList.then(function(devices) { | ||
var dev = devices.find(function(device) { | ||
return device.identifier.replace(/\s/g, '') == ain; | ||
}); | ||
return dev || Promise.reject(); | ||
}); | ||
} | ||
// get temperature- both switches and thermostats are supported | ||
@@ -291,3 +306,7 @@ module.exports.getTemperature = function(sid, ain, options) | ||
{ | ||
return module.exports.getDeviceList(sid, options).then(function(devices) { | ||
var deviceList = options && options.deviceList | ||
? Promise.resolve(options.deviceList) | ||
: module.exports.getDeviceList(sid, options); | ||
return deviceList.then(function(devices) { | ||
// get thermostats- right now they're only available via the XML api | ||
@@ -341,11 +360,3 @@ var thermostats = devices.filter(function(device) { | ||
{ | ||
return module.exports.getDeviceList(sid).then(function(devices) { | ||
var dev = devices.find(function(device) { | ||
return device.identifier.replace(/\s/g, '') == ain; | ||
}); | ||
if (dev === undefined) { | ||
return Promise.reject(); | ||
} | ||
return module.exports.getDevice(sid, ain, options).then(function(device) { | ||
var req = { | ||
@@ -357,3 +368,3 @@ method: 'POST', | ||
no_sidrenew: '', | ||
device: dev.id, | ||
device: device.id, | ||
oldpage: '/net/home_auto_hkr_edit.lua', | ||
@@ -388,7 +399,11 @@ back_to_page: '/net/network.lua' | ||
{ | ||
return executeCommand(sid, null, null, options, '/wlan/guest_access.lua?0=0').then(function(body) { | ||
var settings = extend(parseHTML(body), { | ||
activate_guest_access: enable | ||
}); | ||
var settings = enable instanceof Object | ||
? Promise.resolve(enable) | ||
: executeCommand(sid, null, null, options, '/wlan/guest_access.lua?0=0').then(function(body) { | ||
return extend(parseHTML(body), { | ||
activate_guest_access: enable | ||
}); | ||
}); | ||
return settings.then(function(settings) { | ||
// convert boolean to checkbox | ||
@@ -395,0 +410,0 @@ for (var property in settings) { |
22616
458
112