From 224d52d1033d8ccce5087c9bee5a63457830a13a Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 20 Dec 2025 14:11:13 +0100 Subject: Use default config The default config JSON is embedded as bytes into the executable. Instead of constants the default values are now parsed from these embedded bytes. --- homematic.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'homematic.go') diff --git a/homematic.go b/homematic.go index 7ccc1ad..4bae0ca 100644 --- a/homematic.go +++ b/homematic.go @@ -8,19 +8,19 @@ import ( "xengineering.eu/homematic-go/homematic" ) -const ( - OPENCCU = `http://127.0.0.1:8080` - POLLING_PERIOD = 50 * time.Millisecond -) - -func HomematicRun(tx chan MQTTMessage) { - req, inventory, err := Start() +func HomematicRun(config HomematicConfig, tx chan MQTTMessage) { + req, inventory, err := Start(config.CCU) if err != nil { log.Fatalf("Failed startup process: %v", err) } cache := NewCache(tx) + pollingPeriod, err := time.ParseDuration(config.PollingPeriod) + if err != nil { + log.Fatalf("Failed to parse Homematic polling period: %v", err) + } + for { start := time.Now() @@ -28,18 +28,18 @@ func HomematicRun(tx chan MQTTMessage) { cache.Update(states) - WaitUntil(start.Add(POLLING_PERIOD)) + WaitUntil(start.Add(pollingPeriod)) } } -func Start() (homematic.Requester, homematic.Devices, error) { +func Start(ccu string) (homematic.Requester, homematic.Devices, error) { var req homematic.Requester var inventory homematic.Devices var err error - req = homematic.NewRequester(OPENCCU) - log.Printf("Created Homematic requester (%s).", OPENCCU) + req = homematic.NewRequester(ccu) + log.Printf("Created Homematic requester (%s).", ccu) inventory, err = req.ListDevices() if err != nil { -- cgit v1.2.3-70-g09d2