summaryrefslogtreecommitdiff
path: root/homematic.go
diff options
context:
space:
mode:
Diffstat (limited to 'homematic.go')
-rw-r--r--homematic.go22
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 {