diff options
| author | xengineering <me@xengineering.eu> | 2025-12-20 14:11:13 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2025-12-20 14:11:13 +0100 |
| commit | 224d52d1033d8ccce5087c9bee5a63457830a13a (patch) | |
| tree | cfd0b61e66258a0121ef20d4572561aee84b8db3 /homematic.go | |
| parent | d6fa255b1df26a12329a614601a027e074aabeb2 (diff) | |
| download | sia-server-224d52d1033d8ccce5087c9bee5a63457830a13a.tar sia-server-224d52d1033d8ccce5087c9bee5a63457830a13a.tar.zst sia-server-224d52d1033d8ccce5087c9bee5a63457830a13a.zip | |
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.
Diffstat (limited to 'homematic.go')
| -rw-r--r-- | homematic.go | 22 |
1 files changed, 11 insertions, 11 deletions
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 { |
