diff options
| author | xengineering <me@xengineering.eu> | 2025-12-09 21:06:22 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2025-12-09 21:06:22 +0100 |
| commit | 1db9a99d2a62747a241315733617dfef46bc59c8 (patch) | |
| tree | 35addf2cfd222c3e80d7ba431ed50b80cf126d8a | |
| parent | 26c1040ffbd5ed10d5114d06d635cd1d882758f8 (diff) | |
| download | homematic-go-1db9a99d2a62747a241315733617dfef46bc59c8.tar homematic-go-1db9a99d2a62747a241315733617dfef46bc59c8.tar.zst homematic-go-1db9a99d2a62747a241315733617dfef46bc59c8.zip | |
Add main.go
This program connects to the Homematic central device, requests a list
of all devices and prints the state of all which have the type
`SHUTTER_CONTACT`.
This makes it possible to test the library in a realistic scenario.
| -rw-r--r-- | main.go | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "log" + + "xengineering.eu/homematic-go/homematic" +) + +const ( + HOST = `127.0.0.1` + PORT = 8080 +) + +func main() { + server := fmt.Sprintf("http://%s:%d", HOST, PORT) + + req := homematic.NewRequester(server) + + inventory, err := req.ListDevices() + if err != nil { + log.Fatalf("Failed to retrieve device list: %v", err) + } + + for _, device := range inventory { + if device.Type == `SHUTTER_CONTACT` { + state, err := req.GetValue(device.Address) + if err != nil { + log.Fatalf("Failed to get value: %v", err) + } + + log.Printf("%s %s has state %t", device.Type, device.Address, state) + } + } +} |
