Skip to content

Commit

Permalink
Merge pull request #4 from SteMaker/integration-test
Browse files Browse the repository at this point in the history
Integration test finally working reliably
  • Loading branch information
SteMaker authored Jan 25, 2022
2 parents 69fa476 + d7f8042 commit 8f810e1
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 61 deletions.
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Mocha integration test",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"args": [
"test/integration",
"--exit"
]
}
]
}
40 changes: 16 additions & 24 deletions build/src/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/src/main.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"common": {
"name": "hdg-bavaria",
"version": "0.3.1",
"version": "0.3.2",
"news": {
"0.3.1": {
"0.3.2": {
"en": "Integration test added",
"de": "Integrationstest hinzugefügt"
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.hdg-bavaria",
"version": "0.3.1",
"version": "0.3.2",
"description": "Access HDG Control of HDG Bavaria boilers",
"author": {
"name": "stemaker",
Expand Down
39 changes: 14 additions & 25 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ class HdgBavaria extends utils.Adapter {
native: {},
});

this.createLogStates();
this.createStatisticsStates();
this.nodes += await this.createLogStates();
await this.createStatisticsStates();
this.log.info("All states created! Using "+this.nodes+" to query HDG");

// Fix nodes string and do a first query
this.nodes = this.nodes.substring(1);
this.nodes = "nodes="+this.nodes;
this.hdgComm = new HdgComm(this.config.ip, this.nodes)
this.log.info(this.nodes);
await new Promise(r => setTimeout(r, 1000));
this.poll();

// Schedule regular polling
Expand Down Expand Up @@ -193,12 +192,13 @@ class HdgBavaria extends utils.Adapter {
return (false);
}

private createLogStates(): void {
private async createLogStates(): Promise<string> {
let nodes = "";
for (let i = 0; i < this.components.length; i++) {
const c = this.components[i];
const channel = c!.channel;
this.log.info("Create channel " + this.config.name + "." + c!.channel);
this.setObject(this.config.name + "." + c!.channel, {
await this.setObjectNotExistsAsync(this.config.name + "." + c!.channel, {
type: "channel",
common: {
name: c!.name,
Expand All @@ -219,42 +219,32 @@ class HdgBavaria extends utils.Adapter {
read: true,
write: true,
}
this.createState(this.config.name, c!.channel, state.id, stateCommon);
this.nodes += "-" + state.dataid + "T";
await this.createStateAsync(this.config.name, c!.channel, state.id, stateCommon);
nodes += "-" + state.dataid + "T";
}
}
console.log("createLogStates returning "+nodes)
return nodes//new Promise<string>(() => {console.log("resolving");resolve(nodes)});
}

private createStatisticsStates(): void {
private async createStatisticsStates(): Promise<void> {
// Create statistics channel
this.setObject(this.config.name + ".statistics", {
await this.setObjectNotExistsAsync(this.config.name + ".statistics", {
type: "channel",
common: {
name: "statistics",
},
native: {},
});
this.createBufferEnergyStates();
}

private createBufferEnergyStates(): void {
//if(this.bufferEnergy.datapoints.length == 0) return;
//this.createState(this.config.name, "statistics", "PufferEnergieabgabeHeute", {
// name: "Puffer Energieabgabe heute",
// type: "number",
// role: "value",
// unit: "Wh",
// read: true,
// write: false,
//});
this.createState(this.config.name, "statistics", "ThermischeKapazitaet", {
await this.createStateAsync(this.config.name, "statistics", "ThermischeKapazitaet", {
name: "Aktuelle thermische Kapazität des Puffers",
type: "number",
role: "level",
unit: "Wh",
read: true,
write: false,
});
return
}

private poll(): void {
Expand All @@ -273,7 +263,6 @@ class HdgBavaria extends utils.Adapter {
try {
const value = this.parseDatapoint(state, data[dpCnt].text);
if (value != undefined) {
console.log("Setting "+state.id+" to "+value);
this.setState(this.config.name + "." + c.channel + "." + state.id, { val: value, ack: true });
state.value = value;
}
Expand Down
25 changes: 18 additions & 7 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('log-timestamp');
const path = require("path");
const ServerMock = require("mock-http-server");
const { tests, utils } = require("@iobroker/testing");
const { expect } = require('chai');

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
Expand Down Expand Up @@ -50,7 +51,11 @@ tests.integration(path.join(__dirname, ".."), {
status: 200,
headers: { "content-type": "application/json" },
body: function(req) {
console.log("mock server reply POST");
expect(req).to.be.a("object");
expect(req).to.have.property("body")
expect(req.body).to.have.property("nodes")
expect(req.body.nodes.search("26000T")).to.be.greaterThanOrEqual(0)
console.log("mock server reply POST to request "+JSON.stringify(req.body));
return requestJson
}
}
Expand All @@ -59,15 +64,21 @@ tests.integration(path.join(__dirname, ".."), {
console.log("Starting Adapter");
await harness.startAdapterAndWait();
console.log("Adapter started");
await sleep(2000);
await sleep(5000);
console.log("Checking state ...");
harness.states.getState("hdg-bavaria.0.Test.heizkreis.vorlauftemperatur", function(err, state) {
harness.states.getState("hdg-bavaria.0.Test.heizkreis.vorlauftemperatur", function (err, state) {
if (err) console.error(err);
if (state.val == valueInt) {
console.log("Got the correct value :): "+state.val);
resolve(0);
expect(state).to.exist;
if(!state) {
console.log("Could not retrieve state hdg-bavaria.0.Test.heizkreis.vorlauftemperatur");
} else {
console.log("Got an incorrect value :(: "+state.val);
expect(state.val).to.exist
if(!state.val) {
console.log("Could not retrieve value of state hdg-bavaria.0.Test.heizkreis.vorlauftemperatur");
} else {
expect(state.val).to.be.equal(valueInt);
resolve(0);
}
}
});
});
Expand Down

0 comments on commit 8f810e1

Please sign in to comment.