Skip to content

Commit

Permalink
Fix bug on setting systemvalue
Browse files Browse the repository at this point in the history
remove log
Add first Unittest
  • Loading branch information
jenszech committed Mar 2, 2021
1 parent 5e3fd3e commit a94b8e1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"collectCoverage": true,
"automock": false,
"setupFiles": [
"./setupJest.js"
]
}
3 changes: 3 additions & 0 deletions setupJest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*jslint node: true */
"use strict";
// require("jest-fetch-mock").enableMocks();
25 changes: 25 additions & 0 deletions src/__tests__/utils/ccuApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getCurrentVariables, getSysMgr, setValueToSysVar } from '../../utils/ccuApi';
import { getMeasureFromConfig } from '../../jobs/InfluxExporter';
import { logger } from '../../logger';
import { SystemVariable } from 'homematic-js-xmlapi';

test('ccuAPi.setValueTpSysVar', () => {
const sysMgr = getSysMgr();
const testObj = new SystemVariable({
_attributes: {
name: 'TestObject',
ise_id: '1234',
value: 5,
value_list: '',
type: 4,
timestamp: Date.now(),
},
});
sysMgr.updateSysVar(testObj);

const sysVar = getSysMgr().getVariableByName('TestObject');
expect(sysVar).not.toBeNull();
expect(sysVar?.value).toBe(5);
setValueToSysVar(sysVar, 1);
expect(sysVar?.value).toBe(1);
});
4 changes: 0 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,13 @@ function importKm200Values() {
function levelUpdate(level: LevelData) {
const sysVar = getSysMgr().getVariableByName(myConfig.jobs.LevelJetImport.name);
const measure = getMeasureFromConfig(myConfig.jobs.LevelJetImport.name);
logger.info('levelUpdate 1: ' + level.fheight + ' -> ' + sysVar?.value);
setValueToSysVar(sysVar, level.fheight);
logger.info('levelUpdate 2: ' + level.fheight + ' -> ' + sysVar?.value);
if (measure) {
logger.info('Export LevelData');
exportVariable(measure, sysVar);
} else {
logger.warn('NOT Found ---> ' + myConfig.jobs.LevelJetImport.name);
}
const sysVar2 = getSysMgr().getVariableByName(myConfig.jobs.LevelJetImport.name);
logger.info('levelUpdate 3: ' + level.fheight + ' -> ' + sysVar2?.value);
}

// -----------------------------------------------------------------------------
1 change: 1 addition & 0 deletions src/utils/ccuApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function setValue(valuename: string, value: number | boolean) {
}
export function setValueToSysVar(sysvar: SystemVariable | null, value: number | boolean) {
if (sysvar) {
sysvar.value = value;
setValueToCCU(sysvar.iseId, value);
}
}
Expand Down

0 comments on commit a94b8e1

Please sign in to comment.