Skip to content

Commit

Permalink
Merge pull request #31 from foxthefox/1.0.2
Browse files Browse the repository at this point in the history
1.0.2
  • Loading branch information
foxthefox authored Feb 11, 2023
2 parents b265993 + ba289a0 commit fe559eb
Show file tree
Hide file tree
Showing 10 changed files with 358 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ const logout = await fritz.logout_SID();
see the example.js.

## API Calls
* todo for 1.0.2
* todo for 1.0.3

## Changelog
### 1.0.2
* (foxthefox) use of User-Agent
* (foxthefox) implementation of new commands from API version 1.57

### 1.0.1
* skipping usage of chalk, figlet
* (foxthefox) skipping usage of chalk, figlet

### 1.0.0
* (foxthefox) common js module with 2 named exports Fritz and FritzEmu
Expand Down
5 changes: 5 additions & 0 deletions lib/data/getriggerlistinfos.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<triggerlist version="1">
<trigger identifier="trg695F2D-3CBF1DC25" active="1">
<name>Trigger AlertOn</name>
</trigger>
</triggerlist>
49 changes: 49 additions & 0 deletions lib/data/template_new_fail.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<templatelist version="1">
<template identifier="tmp5665DB-3A12B8D82" id="60001" functionbitmask="320" autocreate="0" applymask="2">
<name>alles aus</name>
<metadata></metadata>
<devices></devices>
<triggers></triggers>
<sub_templates></sub_templates>
<applymask>
<hkr_summer />
</applymask>
</template>
<template identifier="tmp5665DB-3E6BC84CE" id="60031" functionbitmask="16384" autocreate="0" applymask="2048">
<name>testSzenario</name>
<metadata>{&quot;type&quot;:&quot;generic&quot;,&quot;icon&quot;:3}</metadata>
<devices></devices>
<triggers></triggers>
<sub_templates>
<template identifier="tmp5665DB-3A12B8D82" />
</sub_templates>
<applymask>
<sub_templates />
</applymask>
</template>
<template identifier="tmp5665DB-3A1C9EFDD" id="60003" functionbitmask="35456" autocreate="0" applymask="64">
<name>vorlage210200</name>
<metadata></metadata>
<devices>
<device identifier="08761 0006102" />
<device identifier="11657 0074380" />
</devices>
<triggers></triggers>
<sub_templates></sub_templates>
<applymask>
<relay_automatic />
</applymask>
</template>
<template identifier="tmp5665DB-3A1C9EC6F" id="60002" functionbitmask="35456" autocreate="0" applymask="64">
<name>vorlage_dect200</name>
<metadata></metadata>
<devices>
<device identifier="08761 0006102" />
</devices>
<triggers></triggers>
<sub_templates></sub_templates>
<applymask>
<relay_automatic />
</applymask>
</template>
</templatelist>
33 changes: 32 additions & 1 deletion lib/data/test_api_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,35 @@
<lastalertchgtimestamp>1617368283</lastalertchgtimestamp>
</alert>
</device>
</devicelist>
<device>
<identifier>11934 0318081</identifier>
<id>407</id>
<functionbitmask>1</functionbitmask>
<fwversion>31.20</fwversion>
<manufacturer>0x0feb</manufacturer>
<productname>HAN-FUN</productname>
<present>1</present>
<txbusy>0</txbusy>
<name>HAN-FUN #2</name>
</device>
<device>
<identifier>11934 0318081-1</identifier>
<id>2001</id>
<functionbitmask>8208</functionbitmask>
<fwversion>0.0</fwversion>
<manufacturer>0x0feb</manufacturer>
<productname>HAN-FUN</productname>
<present>1</present>
<txbusy>0</txbusy>
<name>HAN-FUN #2</name>
<etsiunitinfo>
<etsideviceid>407</etsideviceid>
<unittype>514</unittype>
<interfaces>256</interfaces>
</etsiunitinfo>
<alert>
<state>0</state>
<lastalertchgtimestamp>1670596133</lastalertchgtimestamp>
</alert>
</device>
</devicelist>
52 changes: 50 additions & 2 deletions lib/fritz_ahaapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class Fritz {
}
}

// get trigger information (XML)
async getTriggerListInfos() {
try {
const body = this.executeCommand2('gettriggerlistinfos', '', 1);
return Promise.resolve(body);
} catch (error) {
return Promise.reject(error);
}
}

// get basic device stats (XML)
/**
* other generic functions
Expand Down Expand Up @@ -250,11 +260,12 @@ class Fritz {
}
}

// set color hue or saturation
// set color hue or saturation, limited to the colordefaults
/**
* @param {string} ain
* @param {string | number | boolean | null} saturation
* @param {string | number | boolean | null} hue
* duration is not supportet
*/
async setColor(ain, saturation, hue) {
try {
Expand All @@ -269,6 +280,40 @@ class Fritz {
}
}

// set color hue or saturation, free in the HSV-color schema
/**
* @param {string} ain
* @param {string | number | boolean | null} saturation
* @param {string | number | boolean | null} hue
* duration is not supportet
*/
async setUnmappedColor(ain, saturation, hue) {
try {
const body = await this.executeCommand2(
'setunmappedcolor&saturation=' + saturation + '&hue=' + hue + '&duration=0',
ain,
1
);
return Promise.resolve('OK');
} catch (error) {
return Promise.reject(error);
}
}

// set trigger active
/**
* @param {string} ain
* @param {string | number | boolean} active
*/
async setTriggerActive(ain, active) {
try {
const val = active === 1 || active === '1' || active === true ? '1' : '0';
const body = await this.executeCommand2('settriggeractive&param=' + val, ain, 1);
return Promise.resolve(active);
} catch (error) {
return Promise.reject(error);
}
}
// apply template
/**
* @param {string} ain
Expand Down Expand Up @@ -496,7 +541,8 @@ class Fritz {
path: LOGIN_SID_ROUTE,
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'fritzdect_aha_nodejs/1.0.0'
},
rejectUnauthorized: false
};
Expand All @@ -521,6 +567,7 @@ class Fritz {
// resolve on end
res.on('end', () => {
if (responseBody) {
// login probleme abfangen issue#377 fritzdect
const challenge = responseBody.match('<Challenge>(.*?)</Challenge>')[1];
const blocktime = Math.floor(responseBody.match('<BlockTime>(.*?)</BlockTime>')[1]);
const pbkf2 = challenge.startsWith('2$') ? true : false;
Expand Down Expand Up @@ -634,6 +681,7 @@ class Fritz {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'fritzdect_aha_nodejs/1.0.0',
'Content-Length': Buffer.byteLength(xFormBody)
},
rejectUnauthorized: false
Expand Down
12 changes: 9 additions & 3 deletions lib/fritz_mockserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
const http = require('http');
const fs = require('fs');
const { parse } = require('querystring');
const parser = require('xml2json-light');
const parser = require('./xml2json.js');
const crypto = require('crypto');

const path = require('path');
console.log('PATH ist ' + path.join(__dirname, './data/'));

const xmlDevicesGroups = fs.readFileSync(path.join(__dirname, './data/') + 'test_api_response.xml');
//var xmlDevicesGroups = fs.readFileSync('./test.xml');
const xmlTemplate = fs.readFileSync(path.join(__dirname, './data/') + 'template_answer.xml');
const xmlTemplate = fs.readFileSync(path.join(__dirname, './data/') + 'template_new_fail.xml');
const xmlTempStat = fs.readFileSync(path.join(__dirname, './data/') + 'devicestat_temp_answer.xml');
const xmlTriggerlist = fs.readFileSync(path.join(__dirname, './data/') + 'getriggerlistinfos.xml');
const xmlPowerStats = fs.readFileSync(path.join(__dirname, './data/') + 'devicestat_power_answer.xml');
const xmlColorDefaults = fs.readFileSync(path.join(__dirname, './data/') + 'color_defaults.xml');
const hkr_batt = fs.readFileSync(path.join(__dirname, './data/') + 'hkr_response.xml');
Expand Down Expand Up @@ -706,6 +707,11 @@ function homeautoswitchAnswer(
case 'setmetadata':
break;
case 'gettriggerlistinfo':
// todo empty templates
response.writeHead(200, { 'xmlDevicesGroups-Type': 'application/json' });
response.write(String(xmlTriggerlist));
response.end();
return response;
break;
case 'settriggeractive':
break;
Expand Down Expand Up @@ -756,7 +762,6 @@ class FritzEmu {
this.debugmode = debugmode;
this.deviceresponse = null;
}
// S7WebAPI
setupHttpServer(callback) {
console.log('\x1b[33m', ' _____ ____ _ _ _ _ ');
console.log('\x1b[33m', ' | ___| __ ) / \\ | | | | / \\ ');
Expand Down Expand Up @@ -876,6 +881,7 @@ class FritzEmu {
break;
}
}
console.log('\x1b[0m');

if (reqstring[0] == '/login_sid.lua') {
if (version == 2) {
Expand Down
Loading

0 comments on commit fe559eb

Please sign in to comment.