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

Input-plugin for KNX home-automation bus #7048

Merged
merged 35 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9b2cdfb
Add dependency for github.com/vapourismo/knx-go
DocLambda Feb 19, 2020
05258c3
Add a first version of the KNX listener input-plugin for the KNX home…
DocLambda Feb 19, 2020
a9d36e3
Add README for the KNX listener input-plugin.
DocLambda Feb 19, 2020
74eb161
Add the KNX listener input-plugin to the all-plugin list.
DocLambda Feb 19, 2020
05579db
Address review comments by ssoroka.
DocLambda Feb 20, 2020
36a56fe
Improve timeout-handling when collecting the metrics during test by u…
DocLambda Feb 24, 2020
a4d1d09
Update knx-go library.
DocLambda Feb 24, 2020
c10134f
Use upstream type-registry to produce the DPTs.
DocLambda Feb 24, 2020
a81d70c
Remove unused GetDatapointType() function.
DocLambda Feb 24, 2020
896337a
Update knx-go lib.
DocLambda Nov 28, 2020
a466b63
Remove punctuation for error message.
DocLambda Nov 28, 2020
6cc5a52
Check for duplicate GA specification.
DocLambda Nov 28, 2020
5ca98e1
Make GetKNXInterface() private.
DocLambda Nov 28, 2020
4f2e363
Move datapoint value construction to the only user and remove it.
DocLambda Nov 28, 2020
887ab1f
Dissolve getKNXInterface() to the respective place.
DocLambda Nov 28, 2020
50566f6
Move KNXInterface declaration to main block.
DocLambda Nov 28, 2020
7a7cbed
Remove superfluous sendRegularly() function.
DocLambda Nov 28, 2020
3c36e96
Rework test-cases, simplify and extend them.
DocLambda Dec 7, 2020
dcb39bf
Remove superfluous helpers.
DocLambda Dec 7, 2020
02e113d
Fix formatting. No functional changes.
DocLambda Dec 7, 2020
115bd28
Update plugins/inputs/knx_listener/README.md
DocLambda Jan 8, 2021
7024f8c
Replace unused accumulator parameter
DocLambda Jan 8, 2021
efcc1f6
Fix typo
DocLambda Jan 8, 2021
7573345
Use double-# for comments and make 'tunnel' the default type.
DocLambda Jan 8, 2021
d8c4583
Use telegraf logger and improve quoted-string constructs.
DocLambda Jan 8, 2021
0ea64cb
Fix parameter order in type-conversion error-message and always use q…
DocLambda Jan 8, 2021
64205bf
Save an indentation-level.
DocLambda Jan 8, 2021
3cb2508
Avoid spamming the log with unknown group-addresses.
DocLambda Jan 8, 2021
52317c3
Fix tests for Windows where the time might be equal.
DocLambda Jan 8, 2021
d712bc7
Fix typo.
DocLambda Jan 21, 2021
5541540
Add dependency to list.
DocLambda Jan 21, 2021
80d28ed
Add knx to the list of input plugins.
DocLambda Jan 21, 2021
ada8c37
Fix dependency lost during rebase.
DocLambda Mar 4, 2021
ea5b502
Wait for the listener to finish when stopping the plugin.
DocLambda Mar 4, 2021
5b1998a
Fix linter error by explicitly specifying the return values.
DocLambda Mar 17, 2021
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
Prev Previous commit
Next Next commit
Use telegraf logger and improve quoted-string constructs.
  • Loading branch information
DocLambda committed Mar 17, 2021
commit d8c4583cbc603b8e1e06efbd9076026f5e97a372
24 changes: 12 additions & 12 deletions plugins/inputs/knx_listener/knx_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package knx_listener

import (
"fmt"
"log"
"reflect"

"github.com/vapourismo/knx-go/knx"
Expand All @@ -29,9 +28,10 @@ type Measurement struct {
}

type KNXListener struct {
ServiceType string `toml:"service_type"`
ServiceAddress string `toml:"service_address"`
Measurements []Measurement `toml:"measurement"`
ServiceType string `toml:"service_type"`
ServiceAddress string `toml:"service_address"`
Measurements []Measurement `toml:"measurement"`
Log telegraf.Logger `toml:"-"`

client KNXInterface
gaTargetMap map[string]addressTarget
Expand Down Expand Up @@ -80,9 +80,9 @@ func (kl *KNXListener) Start(acc telegraf.Accumulator) error {
// of the measurement
kl.gaTargetMap = make(map[string]addressTarget)
for _, m := range kl.Measurements {
log.Printf("D! [inputs.KNXListener] group-address mapping for measurement \"%s\"", m.Name)
kl.Log.Debugf("Group-address mapping for measurement %q:", m.Name)
for _, ga := range m.Addresses {
log.Printf("D! [inputs.KNXListener] %v --> %s", ga, m.Dpt)
kl.Log.Debugf(" %v --> %s", ga, m.Dpt)
if _, ok := kl.gaTargetMap[ga]; ok {
return fmt.Errorf("duplicate specification of address %v", ga)
}
Expand All @@ -95,7 +95,7 @@ func (kl *KNXListener) Start(acc telegraf.Accumulator) error {
}

// Connect to the KNX-IP interface
log.Printf("I! [inputs.KNXListener] Trying to connect to \"%s\" at \"%s\"", kl.ServiceType, kl.ServiceAddress)
kl.Log.Infof("Trying to connect to %q at %q", kl.ServiceType, kl.ServiceAddress)
switch kl.ServiceType {
case "tunnel":
c, err := knx.NewGroupTunnel(kl.ServiceAddress, knx.DefaultTunnelConfig)
Expand All @@ -118,7 +118,7 @@ func (kl *KNXListener) Start(acc telegraf.Accumulator) error {
default:
return fmt.Errorf("invalid interface type: %s", kl.ServiceAddress)
}
log.Printf("I! [inputs.KNXListener] Connected!")
kl.Log.Infof("Connected!")

// Listen to the KNX bus
go kl.listen()
Expand All @@ -140,10 +140,10 @@ func (kl *KNXListener) listen() {
if ok {
err := target.datapoint.Unpack(msg.Data)
if err != nil {
log.Printf("E! [inputs.KNXListener] Unpacking data failed: %v", err)
kl.Log.Errorf("Unpacking data failed: %v", err)
continue
}
log.Printf("D! [inputs.KNXListener] Matched GA \"%v\" to measurement \"%v\" with value \"%v\"", ga, target.measurement, target.datapoint)
kl.Log.Debugf("Matched GA %q to measurement %q with value %v", ga, target.measurement, target.datapoint)

// Convert the DatapointValue interface back to its basic type again
// as otherwise telegraf will not push out the metrics and eat it
Expand All @@ -160,7 +160,7 @@ func (kl *KNXListener) listen() {
case reflect.Float32, reflect.Float64:
value = vi.Float()
default:
log.Printf("E! [inputs.KNXListener] Type conversion %v failed for address %v", ga, vi.Kind())
kl.Log.Errorf("Type conversion %v failed for address %v", ga, vi.Kind())
continue
}

Expand All @@ -173,7 +173,7 @@ func (kl *KNXListener) listen() {
}
kl.acc.AddFields(target.measurement, fields, tags)
} else {
log.Printf("I! [inputs.KNXListener] Ignoring message %+v for unknown GA \"%v\"", msg, ga)
kl.Log.Infof("Ignoring message %+v for unknown GA %q", msg, ga)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions plugins/inputs/knx_listener/knx_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestRegularReceives_DPT(t *testing.T) {
listener := KNXListener{
ServiceType: "dummy",
Measurements: measurements,
Log: testutil.Logger{Name: "knx_listener"},
}

// Setup the listener to test
Expand Down