-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decode can now do lookups for sensor types, reported during node presentation, and use that to enrich the emitted mysensors node message Also added more tests on controller class
- Loading branch information
Thomas Mørch
committed
Jul 13, 2018
1 parent
987dff7
commit 513ee20
Showing
18 changed files
with
740 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,6 +1,6 @@ | ||
import { IMysensorsMsg, INodeMessage } from '../mysensors-msg'; | ||
|
||
export interface IDecoder { | ||
decode(msg: INodeMessage): IMysensorsMsg| undefined; | ||
decode(msg: INodeMessage): Promise<IMysensorsMsg| undefined>; | ||
encode(msg: IMysensorsMsg): INodeMessage| undefined; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect } from 'chai'; | ||
import { IDatabase } from 'node-red-contrib-mysensors/src/lib/database.interface'; | ||
import * as sinon from 'sinon'; | ||
import { DatabaseSqlite } from './database-sqlite'; | ||
import { MysensorsController } from './mysensors-controller'; | ||
import { IMysensorsMsg } from './mysensors-msg'; | ||
import { mysensor_command, mysensor_internal } from './mysensors-types'; | ||
|
||
describe('Controller test', () => { | ||
let db: IDatabase; | ||
let controller: MysensorsController; | ||
sinon.stub(DatabaseSqlite.prototype, 'getFreeNodeId').callsFake(() => '777'); | ||
db = new DatabaseSqlite('dummy'); | ||
controller = new MysensorsController(db, true, true, 'CET', 'M', 'mys-out'); | ||
|
||
it('MQTT ID Request', async () => { | ||
const input: IMysensorsMsg = { | ||
payload: '', | ||
topic: 'mys-in/255/255/3/0/3', | ||
}; | ||
const expected: IMysensorsMsg = { | ||
payload: '777', | ||
subType: mysensor_internal.I_ID_RESPONSE, | ||
topicRoot: 'mys-out', | ||
}; | ||
expect(await controller.messageHandler(input)) | ||
.to.include(expected); | ||
}); | ||
|
||
it('Serial config request', async () => { | ||
const expected: IMysensorsMsg = { | ||
payload: '255;255;3;0;6;M', | ||
}; | ||
const request: IMysensorsMsg = {payload: '255;255;3;0;6;0'}; | ||
|
||
expect(await controller.messageHandler(request)).to.include(expected); | ||
}); | ||
|
||
it('Decoded time request', async () => { | ||
const request: IMysensorsMsg = { | ||
ack: 0, | ||
childSensorId: 255, | ||
messageType: mysensor_command.C_INTERNAL, | ||
nodeId: 10, | ||
payload: '', | ||
subType: mysensor_internal.I_TIME, | ||
}; | ||
|
||
const expected: IMysensorsMsg = { | ||
payload: '', | ||
subType: mysensor_internal.I_TIME, | ||
}; | ||
|
||
expect(await controller.messageHandler(request)).to.include.keys(expected); | ||
}); | ||
|
||
it('updates database uppon reception of package', async () => { | ||
const spy = sinon.spy(DatabaseSqlite.prototype, 'nodeHeard'); | ||
await controller.messageHandler({payload: '10;255;3;0;6;0'}); | ||
expect(spy.called).to.eq(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- UP | ||
|
||
ALTER TABLE node RENAME TO tmp_node; | ||
|
||
CREATE TABLE IF NOT EXISTS node ( | ||
nodeId integer PRIMARY KEY AUTOINCREMENT, | ||
label varchar, | ||
sketchName varchar, | ||
sketchVersion varchar, | ||
lastHeard timestamp, | ||
parentId integer, | ||
lastRestart timestamp, | ||
used boolean | ||
); | ||
|
||
INSERT INTO node(nodeId, label, sketchName, sketchVersion, lastHeard, parentId, lastRestart, used) | ||
SELECT id, label, sketchName, sketchVersion, lastHeard, parentId, lastRestart, used | ||
FROM tmp_node; | ||
|
||
drop table tmp_node; | ||
|
||
drop table child; | ||
|
||
CREATE TABLE IF NOT EXISTS child ( | ||
nodeId integer, | ||
childId integer, | ||
sType integer, | ||
description varchar, | ||
lastHeard timestamp, | ||
PRIMARY KEY(nodeId, childId), | ||
FOREIGN KEY(nodeId) REFERENCES node(nodeId)); | ||
|
||
|
||
-- DOWN |
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
Oops, something went wrong.