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(inputs.knx_listener): Add support for string data type #15169

Merged

Conversation

martinvonwittich
Copy link
Contributor

Summary

KNX has string data types like DPT 16.000 (ASCII text) which can transfer up to 14 bytes of ASCII text. knx_listener didn't support these yet and therefore couldn't log telegrams of this type; this PR adds the required support.

Please review this carefully; I've never written Go before.

Checklist

  • No AI generated code was used in this PR

Related issues

resolves #15158

KNX has string data types like DPT 16.000 (ASCII text) which can
transfer up to 14 bytes of ASCII text. knx_listener didn't support these
yet and therefore couldn't log telegrams of this type; this PR adds the
required support.
@telegraf-tiger telegraf-tiger bot added feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins labels Apr 16, 2024
@telegraf-tiger
Copy link
Contributor

@powersj
Copy link
Contributor

powersj commented Apr 16, 2024

@martinvonwittich,

Thanks for taking the time to put this up! I think the only thing missing would be a test. In knx_listener_test.go, there is a test called TestRegularReceives_DPT. It has a long table of tests, could you add one that ensures the string it parsed like the following:

    {"16/1/1", "16.000", false, "foobar", "foobar"},

@srebhan is that the right address and DPT to use?

@martinvonwittich
Copy link
Contributor Author

@martinvonwittich,

Thanks for taking the time to put this up! I think the only thing missing would be a test.

The PR should contain a test...? It displays for me:

{"16/0/0", "16.000", false, "hello world", "hello world"},

@powersj
Copy link
Contributor

powersj commented Apr 16, 2024

The PR should contain a test...? It displays for me:

🤦 how did I miss that in a 5 line diff

@powersj powersj added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Apr 16, 2024
@martinvonwittich
Copy link
Contributor Author

Also a side note about the test that I forgot to mention: when creating the PR, I used git stash to temporarily stash the feature implementation and implemented the test first, to ensure that the test fails when the feature isn't implemented. This didn't work quite as expected - without the feature implementation, the test just hangs forever. Running it with go test -v shows that it throws the expected error, but then never terminates:

[...]
2024/04/16 20:30:27 D! [knx_listener] Matched GA "14/0/3" to measurement "test" with value 92.69 s⁻¹
2024/04/16 20:30:27 D! [knx_listener] Matched GA "14/0/4" to measurement "test" with value 1.01 mol
2024/04/16 20:30:27 D! [knx_listener] Matched GA "14/1/0" to measurement "test" with value 5963.78 m²
2024/04/16 20:30:27 D! [knx_listener] Matched GA "14/1/1" to measurement "test" with value 150.95 F
2024/04/16 20:30:27 D! [knx_listener] Matched GA "16/0/0" to measurement "test" with value hello world
2024/04/16 20:30:27 E! [knx_listener] Type conversion string failed for address "16/0/0"

When the feature is implemented, the test works as expected:

[...]
2024/04/16 20:31:36 D! [knx_listener] Matched GA "14/1/0" to measurement "test" with value 5963.78 m²
2024/04/16 20:31:36 D! [knx_listener] Matched GA "14/1/1" to measurement "test" with value 150.95 F
2024/04/16 20:31:36 D! [knx_listener] Matched GA "16/0/0" to measurement "test" with value hello world
--- PASS: TestRegularReceives_DPT (0.00s)
=== RUN   TestRegularReceives_MultipleMessages
2024/04/16 20:31:36 D! [knx_listener] Group-address mapping for measurement "temperature":
2024/04/16 20:31:36 D! [knx_listener]   1/1/1 --> 1.001
2024/04/16 20:31:36 I! [knx_listener] Trying to connect to "dummy" at ""
2024/04/16 20:31:36 I! [knx_listener] Connected!
2024/04/16 20:31:36 D! [knx_listener] Matched GA "1/1/1" to measurement "temperature" with value On
2024/04/16 20:31:36 D! [knx_listener] Matched GA "1/1/1" to measurement "temperature" with value Off
2024/04/16 20:31:36 I! [knx_listener] Ignoring message {Command:Write Source:0.0.0 Destination:1/1/2 Data:[0]} for unknown GA "1/1/2"
--- PASS: TestRegularReceives_MultipleMessages (0.00s)
=== RUN   TestReconnect
2024/04/16 20:31:36 D! [knx_listener] Group-address mapping for measurement "temperature":
2024/04/16 20:31:36 D! [knx_listener]   1/1/1 --> 1.001
2024/04/16 20:31:36 I! [knx_listener] Trying to connect to "dummy" at ""
2024/04/16 20:31:36 I! [knx_listener] Connected!
2024/04/16 20:31:36 D! [knx_listener] Matched GA "1/1/1" to measurement "temperature" with value On
2024/04/16 20:31:36 D! [knx_listener] Matched GA "1/1/1" to measurement "temperature" with value Off
2024/04/16 20:31:36 I! [knx_listener] Ignoring message {Command:Write Source:0.0.0 Destination:1/1/2 Data:[0]} for unknown GA "1/1/2"
2024/04/16 20:31:36 I! [knx_listener] Trying to connect to "dummy" at ""
2024/04/16 20:31:36 I! [knx_listener] Connected!
2024/04/16 20:31:36 D! [knx_listener] Matched GA "1/1/1" to measurement "temperature" with value On
2024/04/16 20:31:36 D! [knx_listener] Matched GA "1/1/1" to measurement "temperature" with value Off
--- PASS: TestReconnect (0.40s)
PASS
ok      github.com/influxdata/telegraf/plugins/inputs/knx_listener      0.455s

I assume that the strange failing behavior is an existing issue in the test code.

@srebhan srebhan changed the title feat(inputs.knx_listener): add support for String data type feat(inputs.knx_listener): Add support for string data type Apr 16, 2024
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @martinvonwittich!

@srebhan srebhan merged commit 583e7cd into influxdata:master Apr 16, 2024
27 checks passed
@github-actions github-actions bot added this to the v1.31.0 milestone Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inputs.knx_listener: add support for String data type
4 participants