Skip to content

Commit 2f7c363

Browse files
committed
Store config and data in ~/.config
1 parent 86df272 commit 2f7c363

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

hklightd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import (
55
"fmt"
66
"github.com/brutella/hc"
77
"github.com/brutella/hc/accessory"
8-
"github.com/brutella/log"
98
"github.com/yosssi/gmq/mqtt"
109
"github.com/yosssi/gmq/mqtt/client"
1110
"io/ioutil"
11+
"log"
12+
"os/user"
13+
"path/filepath"
1214
)
1315

1416
func main() {
15-
log.Verbose = true
16-
log.Info = true
17-
18-
file, err := ioutil.ReadFile("./hklightd.json")
17+
usr, _ := user.Current()
18+
file, err := ioutil.ReadFile(filepath.Join(usr.HomeDir, ".config/hkdaemons/hklightd.json"))
1919
if err != nil {
2020
panic(err)
2121
}
@@ -150,7 +150,7 @@ func main() {
150150
accessories = append(accessories, acc.Accessory)
151151
}
152152

153-
transport_config := hc.Config{Pin: config["pin"].(string), StoragePath: config["storage_path"].(string)}
153+
transport_config := hc.Config{Pin: config["pin"].(string), StoragePath: filepath.Join(usr.HomeDir, ".config/hkdaemons/data/hklightd")}
154154
t, err := hc.NewIPTransport(transport_config, accessories[0], accessories[1:]...)
155155
if err != nil {
156156
log.Fatal(err)

hkswitchd.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import (
55
"fmt"
66
"github.com/brutella/hc"
77
"github.com/brutella/hc/accessory"
8-
"github.com/brutella/log"
98
"github.com/yosssi/gmq/mqtt"
109
"github.com/yosssi/gmq/mqtt/client"
1110
"io/ioutil"
11+
"log"
12+
"os/user"
13+
"path/filepath"
1214
)
1315

1416
func main() {
15-
log.Verbose = true
16-
log.Info = true
1717

18-
file, err := ioutil.ReadFile("./hkswitchd.json")
18+
usr, _ := user.Current()
19+
file, err := ioutil.ReadFile(filepath.Join(usr.HomeDir, ".config/hkdaemons/hkswitchd.json"))
1920
if err != nil {
2021
panic(err)
2122
}
@@ -99,7 +100,7 @@ func main() {
99100
accessories = append(accessories, acc.Accessory)
100101
}
101102

102-
transport_config := hc.Config{Pin: config["pin"].(string), StoragePath: config["storage_path"].(string)}
103+
transport_config := hc.Config{Pin: config["pin"].(string), StoragePath: filepath.Join(usr.HomeDir, ".config/hkdaemons/data/hkswitchd")}
103104
t, err := hc.NewIPTransport(transport_config, accessories[0], accessories[1:]...)
104105
if err != nil {
105106
log.Fatal(err)

hkthermostatd.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import (
99
"github.com/yosssi/gmq/mqtt/client"
1010
"io/ioutil"
1111
"log"
12+
"os/user"
13+
"path/filepath"
1214
"strconv"
1315
)
1416

1517
func main() {
1618

17-
file, err := ioutil.ReadFile("./hkthermostatd.json")
19+
usr, _ := user.Current()
20+
file, err := ioutil.ReadFile(filepath.Join(usr.HomeDir, ".config/hkdaemons/hkthermostatd.json"))
1821
if err != nil {
1922
panic(err)
2023
}
@@ -186,7 +189,7 @@ func main() {
186189

187190
}
188191

189-
transport_config := hc.Config{Pin: config["pin"].(string), StoragePath: config["storage_path"].(string)}
192+
transport_config := hc.Config{Pin: config["pin"].(string), StoragePath: filepath.Join(usr.HomeDir, ".config/hkdaemons/data/hkthermostatd")}
190193
t, err := hc.NewIPTransport(transport_config, accessories[0], accessories[1:]...)
191194
if err != nil {
192195
log.Fatal(err)

0 commit comments

Comments
 (0)