From f9fac85222892e45554a2cc49dd93455a374ef68 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 10 Dec 2025 21:14:38 +0100 Subject: Adopt homematic-go example This requests a list of devices from the Homematic central device and then queries the state of every `SHUTTER_CONTACT`. This is a good starting point for the server logic. --- main.go | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 22c9b5a..2beb538 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,35 @@ package main import ( + "fmt" "log" + + "xengineering.eu/homematic-go/homematic" +) + +const ( + HOST = `127.0.0.1` + PORT = 8080 ) func main() { - log.Println("Hello world!") + 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