-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgo-nest-temp-monitor.go
69 lines (57 loc) · 1.54 KB
/
go-nest-temp-monitor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"fmt"
"go-nest-temp-monitor/accuweather"
"go-nest-temp-monitor/configuration"
"go-nest-temp-monitor/nest"
"go-nest-temp-monitor/openweathermap"
"go-nest-temp-monitor/weathergov"
"log"
"net/url"
"time"
influxClient "github.com/influxdata/influxdb1-client"
)
func main() {
var configFile = flag.String("c", "./config.json", "Specify path to config.json")
flag.Parse()
config := configuration.GetConfig(*configFile)
database := config.InfluxConfig.Database
influxURL, _ := url.Parse(
fmt.Sprintf(
"%s://%s:%d",
config.InfluxConfig.Protocol,
config.InfluxConfig.Hostname,
config.InfluxConfig.Port,
),
)
influxConf := influxClient.Config{
URL: *influxURL,
Username: config.InfluxConfig.Username,
Password: config.InfluxConfig.Password,
}
influxCon, err := influxClient.NewClient(influxConf)
if err != nil {
log.Print("Could not connect to InfluxDB")
log.Fatal(err)
}
if config.NestConfig.Enabled == true {
nest.Initialize(config.NestConfig)
go nest.RefreshLogin()
time.Sleep(time.Second * 10)
go nest.WriteNest(influxCon, database)
}
if config.AccuWeatherConfig.Enabled == true {
go accuweather.WriteWeather(config.AccuWeatherConfig, influxCon, database)
}
if config.OpenWeatherMapConfig.Enabled == true {
go openweathermap.WriteWeather(config.OpenWeatherMapConfig, influxCon, database)
}
if config.WeatherGovConfig.Enabled == true {
go weathergov.WriteWeather(config.WeatherGovConfig, influxCon, database)
}
for {
time.Sleep(time.Hour)
log.Print("Keep alive")
}
}