Skip to content

Commit

Permalink
Merge pull request #24 from foxthefox/new1.0.0
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
foxthefox authored Nov 19, 2022
2 parents e06b0a9 + b8caffb commit 43ef0df
Show file tree
Hide file tree
Showing 20 changed files with 2,718 additions and 284 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Check if PR should be auto-merged
uses: ahmadnassri/action-dependabot-auto-merge@v2
uses: ahmadnassri/action-dependabot-auto-merge@v3
with:
# This must be a personal access token with push access
github-token: ${{ secrets.AUTO_MERGE_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
node-version: '14.x'

Expand All @@ -41,15 +41,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [14, 16, 18]
os: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
Expand Down
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]>
Expand Down
66 changes: 66 additions & 0 deletions example.js
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();
5 changes: 1 addition & 4 deletions index.js
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') };
111 changes: 111 additions & 0 deletions lib/conn_test/fritz.js
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();
}
Loading

0 comments on commit 43ef0df

Please sign in to comment.