From 1db9a99d2a62747a241315733617dfef46bc59c8 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 9 Dec 2025 21:06:22 +0100 Subject: 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. --- main.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..2beb538 --- /dev/null +++ b/main.go @@ -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) + } + } +} -- cgit v1.2.3-70-g09d2