Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ts rewrite and DPT 22, 28 29, 213, 235, 242, 249, 251, 275, 99, 60001 support #2

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e2c509f
feat: ts rewrite
robertsLando Apr 2, 2024
164fb01
fix: merge Connection into FSM for better types
robertsLando Apr 3, 2024
e8ef57d
feat: convert tests to ts
robertsLando Apr 3, 2024
b6696b7
fix: replace deprecated new Buffer
robertsLando Apr 3, 2024
fb98cbd
fix: add missing types
robertsLando Apr 3, 2024
4663803
fix: working on tests
robertsLando Apr 3, 2024
914cab4
fix: make tests work
robertsLando Apr 3, 2024
0dbedbe
Merge branch 'master' of https://github.com/ekarak/knx into typescript
robertsLando Apr 3, 2024
b7c4cb8
feat: eslint + prettier
robertsLando Apr 3, 2024
d3d8f09
fix: typo
robertsLando Apr 3, 2024
196a493
fix: use default logger in dptlib
robertsLando Apr 3, 2024
f1238d3
fix: typescript example
robertsLando Apr 3, 2024
c6afdde
fix: add dpts export in index
robertsLando Apr 3, 2024
366940e
fix: missing types
robertsLando Apr 3, 2024
2e1eb24
fix: add missing types
robertsLando Apr 3, 2024
772218f
fix: lint
robertsLando Apr 3, 2024
f457341
fix: jsdocs
robertsLando Apr 3, 2024
ccda6fe
fix: js docs
robertsLando Apr 3, 2024
b8e38e5
fix: some docs
robertsLando Apr 3, 2024
6fe22c8
fix: split FSM and KnxClient
robertsLando Apr 4, 2024
8270a94
fix: docs and manual tests
robertsLando Apr 4, 2024
f1213db
docs: fix tests
robertsLando Apr 4, 2024
be1badc
fix: import
robertsLando Apr 4, 2024
3949a2a
fix: use relative imports
robertsLando Apr 4, 2024
1e843ee
chore: remove manualtest from ts build
robertsLando Apr 4, 2024
5466dba
fix: better types for Connect and BindSocket
robertsLando Apr 4, 2024
de9a06a
feat: add some missing dpts
robertsLando Apr 5, 2024
5eaad9c
fix: use correct logger in dpts
robertsLando Apr 5, 2024
2829edf
fix: ensure logger is re-created when options are passed
robertsLando Apr 5, 2024
8dae420
fix: ensure logger is unique
robertsLando Apr 5, 2024
49b200e
fix: move info log in client constructor
robertsLando Apr 5, 2024
3bbeb34
fix: load missing dpts
robertsLando Apr 5, 2024
2853126
fix: import type
robertsLando Apr 5, 2024
4d76d6b
fix: dpts tests
robertsLando Apr 5, 2024
7f93ccc
fix: better binary protocol types
robertsLando Apr 11, 2024
94d92c0
fix: types
robertsLando Apr 11, 2024
3233f6d
fix: add constants
robertsLando Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/typescript-sample/
/manualtest/
/build/


*.js
48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint/eslint-plugin'],
env: {
node: true,
},
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:prettier/recommended',
'plugin:@typescript-eslint/recommended'
],
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
tsconfigRootDir: __dirname
},
rules: {
'global-require': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-unused-vars': 'off',
'no-underscore-dangle': 'off',
'no-param-reassign': 'off',
'no-restricted-syntax': 'off',
camelcase: 'off',
'default-case': 'off',
'consistent-return': 'off',
'import/order': 'off',
'max-classes-per-file': 'off',
'no-plusplus': 'off',
'guard-for-in': 'off',
'no-bitwise': 'off',
'class-methods-use-this': 'off',
'no-continue': 'off',
'prefer-destructuring': 'off',
'no-use-before-define': 'off',
'no-restricted-globals': 'off',
'radix': 'off',
'func-names': 'off',
// Typescript rules
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-use-before-define': 'off',
}
}
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ jobs:
- name: Install Dependencies
run: npm ci

# - name: Lint
# if: matrix.node-version == '20.x'
# # only run on latest node version, no reason to run on all
# run: |
# npm run lint
- name: Lint
if: matrix.node-version == '20.x'
# only run on latest node version, no reason to run on all
run: |
npm run lint

- name: Test NodeJS
run: npm run test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.tags*
node_modules
build
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ manualtest
bitbucket-pipelines.yml
README*.md
typescript-sample
run-wired-tests.sh
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

/typescript-sample/
/manualtest/
/build/

*.md
README.md
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: false,
singleQuote: true,
useTabs: true,
tabWidth: 4,
endOfLine: "lf",
};
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"eslint.format.enable": true,
"eslint.lintTask.enable": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.fixAll.markdownlint": "explicit"
},
}
11 changes: 7 additions & 4 deletions README-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

By default *you only need to specify a 'handlers' object* containing your functions to handle KNX events. All the other options have defaults that can be overridden according to your needs.


```js
var connection = new knx.Connection( {
var { KnxClient, DataPoint } = require('knx');

var connection = new KnxClient( {
// ip address and port of the KNX router or interface
ipAddr: '127.0.0.1', ipPort: 3671,
// in case you need to specify the multicast interface (say if you have more than one)
Expand Down Expand Up @@ -83,13 +84,15 @@ you start defining datapoints (and devices as we'll see later), your code
*needs to ensure that the connection has been established*, usually by declaring them in the 'connected' handler:

```js
var connection = knx.Connection({
var { KnxClient, DataPoint } = require('knx');

var connection = new KnxClient({
handlers: {
connected: function() {
console.log('----------');
console.log('Connected!');
console.log('----------');
var dp = new knx.Datapoint({ga: '1/1/1'}, connection);
var dp = new Datapoint({ga: '1/1/1'}, connection);
// Now send off a couple of requests:
dp.read((src, value) => {
console.log("**** RESPONSE %j reports current value: %j", src, value);
Expand Down
3 changes: 1 addition & 2 deletions README-resilience.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ This library is, to the best of my knowledge, the only one that can handle the *
27 Oct 15:45:36 - [info] [knx-in:input] GroupValue_Read {"srcphy":"15.15.15","dstgad":"0/0/15"}
```


## A note on resilience

There are basically *two* ways to talk to KNX via UDP/IP:
Expand All @@ -30,7 +29,7 @@ There are basically *two* ways to talk to KNX via UDP/IP:
- Finally, this library allows a **hybrid** approach, that's taking the best of the two methods above: You can use **multicast** transport with a **tunnelling** connection to ensure reliable communication. *Unfortunately this deviates from the official KNXnet/IP spec*, and is therefore not compatible with some IP routers. You can enable this "hybrid mode" by enabling the `forceTunneling` option when constructing a new Connection object as follows:

```js
var connection = new knx.Connection( {
var connection = new knx.KnxClient( {
// use tunneling with multicast - this is NOT supported by all routers!
forceTunneling: true,
...
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Make sure your machine has Node.JS (version 4.x or greater) and do:
At last, here's a **reliable** KNX connection that simply works without any configs. To get a basic KNX monitor, you just need to run this in Node:

```js
var knx = require('knx');
var connection = knx.Connection({
var { KnxClient } = require('knx');
var connection = new KnxClient({
handlers: {
connected: function() {
console.log('Connected!');
Expand All @@ -49,8 +49,8 @@ Ahhh, KNX telegrams, what a joy:

## Development documentation

- [Basic API usage](../master/README-API.md)
- [List of supported datapoints](../master/README-datapoints.md)
- [List of supported events](../master/README-events.md)
- [eibd/knxd compatibility](../master/README-knxd.md)
- [On resilience](../master/README-resilience.md)
* [Basic API usage](../master/README-API.md)
* [List of supported datapoints](../master/README-datapoints.md)
* [List of supported events](../master/README-events.md)
* [eibd/knxd compatibility](../master/README-knxd.md)
* [On resilience](../master/README-resilience.md)
119 changes: 0 additions & 119 deletions index.d.ts

This file was deleted.

19 changes: 0 additions & 19 deletions index.js

This file was deleted.

11 changes: 5 additions & 6 deletions manualtest/test-toggle.js → manualtest/test-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
* (C) 2016-2017 Elias Karakoulakis
*/

var knx = require('knx');
import { Datapoint, KnxClient } from "../src";

if (process.argv.length < 3) {
console.log('usage: %s <ga> <optional: status_ga> to toggle a light on & off',
process.argv[1]);
process.exit(1);
}
var connection = knx.Connection({
const connection = new KnxClient({
debug: true,
handlers: {
connected: function() {
console.log('----------');
console.log('Connected!');
console.log('----------');
// define a datapoint:
var dp = new knx.Datapoint({
const dp = new Datapoint({
ga: process.argv[2],
dpt: 'DPT1.001'
}, connection);
if (process.argv[3]) {
var status_ga = new knx.Datapoint({
const status_ga = new Datapoint({
ga: process.argv[3],
dpt: 'DPT1.001'
}, connection);
Expand All @@ -36,14 +36,13 @@ var connection = knx.Connection({
console.log('\n\n\n');
console.log('PRESS ANY KEY TO TOGGLE %s AND "q" TO QUIT.', process.argv[2]);
console.log('\n\n\n');
var dpVal = false;
let dpVal = false;
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', (data) => {
console.log(JSON.stringify(data));
if (data[0] === 113) {
process.exit(0);
return;
}
dpVal = !dpVal;
console.log("Sending " + dpVal);
Expand Down
Loading