Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repaired for fritzOS7 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fritz.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ function getSessionID(username, password, options) {
}

function getData(sid, options) {
options.path = '/data.lua?xhr=1&page=netDev&type=cleanup&no_sidrenew=&sid=' + sid
options.port = 49000
options.path = '/devicehostlist.lua?sid=' + sid
return Promise.try(() => {
return request(options)
})
Expand Down
25 changes: 19 additions & 6 deletions fritzbox-presence.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fritz = require('./fritz')
const bluebird = require('bluebird')
var parseXML = require('xml2js').parseString

function setNodeStatusToConnectionError(node, error) {
node.status({ fill: "red", shape: "dot", text: error.message })
Expand All @@ -21,7 +22,7 @@ module.exports = function(RED) {
var node = this
let sessionID

this.on('input', () => {
this.on('input', (msg) => {
setNodeStatusToQuerying(node)
const options = { host: hostname }
return fritz.checkSession(sessionID, options)
Expand All @@ -39,17 +40,29 @@ module.exports = function(RED) {
return fritz.getData(sessionID, options)
})
.then((response) => {
response = JSON.parse(response)
const devices = response.data.active
node.status({ fill: "green", shape: "ring", text: `${devices.length} active devices detected` })
node.send({ payload: devices, full_response: response })
var data = ""
parseXML(response, {trim: true, explicitArray: false}, function (err, result) {
data = result['List']['Item']
})
if(msg.payload === 'online' || msg.payload === 'offline') {
var newList = []
data.forEach( function(n) {
if(n.Active == (msg.payload==='online'?1:0))
newList.push(n)
})
data = newList
}
else
msg.payload = 'all'
node.status({ fill: "green", shape: "ring", text: `${data.length} devices (` + msg.payload + `)` })
node.send({ payload: data, full_response: response, mode: msg.payload})
})
.catch((err) => {
setNodeStatusToConnectionError(node, err)
})
})
this.on('error', () => {
console.log('ääääääääääääää')
console.log('error')
})
this.on('close', function() {
node.status({})
Expand Down