-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from foxthefox/new1.0.0
1.0.0
- Loading branch information
Showing
20 changed files
with
2,718 additions
and
284 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
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 |
---|---|---|
|
@@ -11,11 +11,12 @@ This library is not, in any way, affiliated or related to AVM GmbH. Use it at yo | |
* control switches, thermostats, blinds, lamps | ||
* control grouped devices | ||
* control configured templates | ||
* uses new session ID method (FW >7.25), as well as the fallback to md5 method as a fallback | ||
* no production dependencies | ||
* uses new session ID method (FW >7.25), as well as the fallback to md5 method | ||
* no production dependencies for the API itself (the dependencies are only related to the testscript and emulation) | ||
|
||
## Getting Started | ||
it is an ES module with named exports | ||
it is an common js module with named exports. | ||
it exposes 2 classes, the API (Fritz) and an emulation (FritzEmu) | ||
|
||
### Prerequisites | ||
* nodejs >14 (may work with older version, but tested with > 14) | ||
|
@@ -27,10 +28,29 @@ install the released version on npm with | |
npm install fritzdect-aha-nodejs | ||
``` | ||
|
||
### Usage | ||
```javascript | ||
const Fritz = require('fritzdect-aha-nodejs').Fritz; | ||
fritz = new Fritz(yourUsername, yourPassword, your.Url || '', your.options || {}); | ||
|
||
//your async function | ||
... | ||
const login = await fritz.login_SID(); | ||
const devicelistinfos = await fritz.getDeviceListInfos(); | ||
const logout = await fritz.logout_SID(); | ||
... | ||
``` | ||
see the example.js. | ||
|
||
## API Calls | ||
* todo for 1.0.1 | ||
|
||
## Changelog | ||
### **WORK IN PROGRESS** | ||
* 0.9.1 (foxthefox) first release on npm | ||
* 0.0.1 (foxthefox) initial release | ||
### 1.0.0 | ||
* (foxthefox) common js module with 2 named exports Fritz and FritzEmu | ||
|
||
### 0.9.1 | ||
* (foxthefox) first release on npm as ESM | ||
|
||
## License | ||
Copyright (c) 2022 foxthefox <[email protected]> | ||
|
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,66 @@ | ||
//--------------- sample code ---------------- | ||
|
||
const Fritz = require('./index.js').Fritz; | ||
|
||
const fritz = new Fritz('admin', 'password', 'http://localhost:3333'); | ||
|
||
async function test() { | ||
const login = await fritz.login_SID().catch((e) => { | ||
console.log('fault calling login() ', e); | ||
}); | ||
console.log('login', login); | ||
if (login) { | ||
await fritz | ||
.getDeviceListInfos() | ||
.then(function(response) { | ||
console.log('Devices' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler Devicelist ', e); | ||
}); | ||
|
||
await fritz | ||
.getUserPermissions() | ||
.then(function(response) { | ||
console.log('Rights : ' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler getUserPermissions', e); | ||
}); | ||
|
||
await fritz | ||
.check_SID() | ||
.then(function(response) { | ||
console.log('Checkresponse : ' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler checkSID', e); | ||
}); | ||
await fritz | ||
.logout_SID() | ||
.then(function(response) { | ||
console.log('logout : ' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler logout_SID', e); | ||
}); | ||
} | ||
//with relogin | ||
await fritz | ||
.getDeviceListInfos() | ||
.then(function(response) { | ||
console.log('Devices' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler Devicelist ', e); | ||
}); | ||
await fritz | ||
.logout_SID() | ||
.then(function(response) { | ||
console.log('logout : ' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler logout_SID', e); | ||
}); | ||
} | ||
test(); |
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 |
---|---|---|
@@ -1,4 +1 @@ | ||
import Fritz from './lib/fritz_ahaapi.js'; | ||
import FritzEmu from './lib/fritz_mockserver.js'; | ||
|
||
export { Fritz, FritzEmu }; | ||
module.exports = { Fritz: require('./lib/fritz_ahaapi.js'), FritzEmu: require('./lib/fritz_mockserver.js') }; |
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,111 @@ | ||
const Fritz = require('fritzdect-aha-nodejs'); | ||
const commandLineArgs = require('command-line-args'); | ||
const getUsage = require('command-line-usage'); | ||
const parser = require('xml2json-light'); | ||
|
||
const cmdOptionsDefinition = [ | ||
{ name: 'username', alias: 'u', type: String, description: 'username for FB login' }, | ||
{ name: 'password', alias: 'p', type: String, description: 'password of that user' }, | ||
{ | ||
name: 'url', | ||
type: String, | ||
description: 'the url of the FB' | ||
}, | ||
{ name: 'help', alias: 'h', type: Boolean } | ||
]; | ||
|
||
const cmdOptions = commandLineArgs(cmdOptionsDefinition); | ||
|
||
if ( | ||
cmdOptions.username === undefined || | ||
cmdOptions.password === undefined || | ||
cmdOptions.url === undefined || | ||
cmdOptions.help | ||
) { | ||
const sections = [ | ||
{ | ||
header: 'Fritzbox Setup Check', | ||
content: | ||
'A simple app checking the Fritzbox Setup. call: node testscript.js -u admin -p password --url http:/192.168.178.1' | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: cmdOptionsDefinition | ||
} | ||
]; | ||
console.log(getUsage(sections)); | ||
} else { | ||
var fritz = new Fritz(cmdOptions.username, cmdOptions.password, cmdOptions.url, null); | ||
|
||
async function test() { | ||
console.log('\n Try to Login ...\n'); | ||
const login = await fritz.login_SID().catch((e) => { | ||
console.log('fault calling login() ', e); | ||
}); | ||
console.log('login OK? : ', login); | ||
if (login) { | ||
const devicelistinfos = await fritz.getDeviceListInfos(); | ||
let devices = parser.xml2json(devicelistinfos); | ||
// devices | ||
devices = [].concat((devices.devicelist || {}).device || []).map((device) => { | ||
//id │ functionbitmask │ fwversion │ manufacturer │ productname │ present │ txbusy,name | ||
// remove spaces in AINs | ||
//device.identifier = device.identifier.replace(/\s/g, ''); | ||
const dev = { | ||
identifier: device.identifier, | ||
id: device.id, | ||
functionbitmask: device.functionbitmask, | ||
fwversion: device.fwversion, | ||
manufacturer: device.manufacturer, | ||
productname: device.productname, | ||
present: device.present, | ||
name: device.name | ||
}; | ||
return dev; | ||
}); | ||
console.log('\n your devices\n'); | ||
console.table(devices); | ||
let groups = parser.xml2json(devicelistinfos); | ||
// devices | ||
groups = [].concat((groups.devicelist || {}).group || []).map((device) => { | ||
//id │ functionbitmask │ fwversion │ manufacturer │ productname │ present │ txbusy,name | ||
// remove spaces in AINs | ||
//device.identifier = device.identifier.replace(/\s/g, ''); | ||
const dev = { | ||
identifier: device.identifier, | ||
id: device.id, | ||
functionbitmask: device.functionbitmask, | ||
fwversion: device.fwversion, | ||
present: device.present, | ||
name: device.name | ||
}; | ||
return dev; | ||
}); | ||
console.log('\n your groups\n'); | ||
console.table(groups); | ||
|
||
await fritz | ||
.check_SID() | ||
.then(function(response) { | ||
console.log('Check SID OK?: ' + response.session + '\n'); | ||
console.log('Check Rights : \n'); | ||
console.log('1 = read only; 2 = ready and write \n'); | ||
console.table(parser.xml2json(response.rights)); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler checkSID', e); | ||
}); | ||
await fritz | ||
.logout_SID() | ||
.then(function(response) { | ||
console.log('\n logout : ' + response); | ||
}) | ||
.catch((e) => { | ||
console.log('Fehler logout_SID', e); | ||
}); | ||
} else { | ||
console.log('your login was not successful '); | ||
} | ||
} | ||
test(); | ||
} |
Oops, something went wrong.