summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2025-12-09 21:06:22 +0100
committerxengineering <me@xengineering.eu>2025-12-09 21:06:22 +0100
commit1db9a99d2a62747a241315733617dfef46bc59c8 (patch)
tree35addf2cfd222c3e80d7ba431ed50b80cf126d8a /main.go
parent26c1040ffbd5ed10d5114d06d635cd1d882758f8 (diff)
downloadhomematic-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.
Diffstat (limited to 'main.go')
-rw-r--r--main.go35
1 files changed, 35 insertions, 0 deletions
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)
+ }
+ }
+}