Skip to content

Commit 581cc6c

Browse files
author
Lord of Scripts
committed
v1.2 final
1 parent 5046c9b commit 581cc6c

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
> Govee API Utility `govee` written in pure GO
44
5+
## [1.2](https://github.com/lordofscripts/govee/compare/v1.2...v1.1) (2024-07-13)
6+
7+
> A quick maintenance release with support for MacOS & Windows. GoveeLux has
8+
> now gone beyond the Raspberry Pi box boundaries.
9+
10+
### New Features
11+
12+
* Added `-init` command-line flag. Creates sample configuration.
13+
* It should now work on Linux, MacOS & Windows
14+
15+
### Other Changes
16+
17+
* README now has informational badges and Go mascot cheering Govee
18+
* The configuration file name is now `goveelux.json`
19+
* The resulting executable is now `goveelux`
20+
* Coverage improvements: new tests.
21+
* Some refactoring to improve readability and maintenance
22+
* Formatting changes to boost Go Report Card from C to A.
23+
* Implemented GitHub workflow for Go
24+
25+
526
## [1.1](https://github.com/lordofscripts/govee/compare/v1.1...v1.0) (2024-07-10)
627

728
> Added basic support for light control.

cmd/main.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ func findByMAC(mac string) *govee.GoveeDevice {
6060
return nil
6161
}
6262

63+
func resolveAlias(deviceID, defAddress, defModel string) (address, model string) {
64+
if len(deviceID) != 0 {
65+
cfg := govee.ReadConfig()
66+
candidates := cfg.Devices.Where(govee.FieldALIAS, deviceID)
67+
cnt := candidates.Count()
68+
if cnt == 0 {
69+
die(RETVAL_CFG_ALIAS, "Could not find alias %q in repository\n", deviceID)
70+
}
71+
72+
if cnt > 1 {
73+
die(RETVAL_CFG_ALIAS, "Found %d entries. Alias not unique, please correct config\n", cnt)
74+
}
75+
76+
fmt.Println("\tFound ", candidates[0], "\n\tAt :", candidates[0].Location)
77+
address = candidates[0].MacAddress
78+
model = candidates[0].Model
79+
} else {
80+
address = defAddress
81+
model = defModel
82+
}
83+
84+
return address, model
85+
}
86+
6387
// print a message and terminate application execution
6488
func die(retVal int, format string, v ...any) {
6589
fmt.Printf(format+"\n", v...)
@@ -85,8 +109,8 @@ func main() {
85109
const (
86110
DEF_BRIGHT uint = 101
87111
)
88-
fmt.Printf("\t\t../ %s (c)2023-%d Lord of Scripts \\..\n", govee.Version, time.Now().Year())
89-
fmt.Println("\t\t https://allmylinks.com/lordofscripts")
112+
fmt.Printf("\t../ %s (c)2023-%d Lord of Scripts \\..\n", govee.Version, time.Now().Year())
113+
fmt.Println("\t https://allmylinks.com/lordofscripts")
90114
// declare real CLI options
91115
var optHelp, optList, optOn, optOff, optState, optInit bool
92116
// declare CLI options which have an explicit value
@@ -145,22 +169,7 @@ func main() {
145169
}
146170

147171
// Config
148-
if len(inAlias) != 0 {
149-
cfg := govee.ReadConfig()
150-
candidates := cfg.Devices.Where(govee.FieldALIAS, inAlias)
151-
cnt := candidates.Count()
152-
if cnt == 0 {
153-
die(RETVAL_CFG_ALIAS, "Could not find alias %q in repository\n", inAlias)
154-
}
155-
156-
if cnt > 1 {
157-
die(RETVAL_CFG_ALIAS, "Found %d entries. Alias not unique, please correct config\n", cnt)
158-
}
159-
160-
fmt.Println("\tFound ", candidates[0], "\n\tAt :", candidates[0].Location)
161-
inDevice = candidates[0].MacAddress
162-
inModel = candidates[0].Model
163-
}
172+
inDevice, inModel = resolveAlias(inAlias, inDevice, inModel)
164173

165174
// with STATE, ON & OFF commands DEVICE & MODEL are required
166175
if (optOn || optOff || optState) && ((len(inDevice) == 0) && (len(inModel) == 0)) {

govee_config.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package govee
99
import (
1010
"encoding/json"
1111
"fmt"
12+
"log"
1213
"os"
1314
"path"
1415
"runtime"
@@ -68,13 +69,15 @@ func CreateSampleConfigFile() (bool, error) {
6869
sample.Devices = append(sample.Devices, sampleDev)
6970

7071
if fd, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0640); err != nil {
72+
log.Println("ERR-CFG", err.Error())
7173
return false, err
7274
} else {
7375
defer fd.Close()
7476

7577
jsonEncoder := json.NewEncoder(fd)
7678
jsonEncoder.SetIndent("", "\t")
7779
if err := jsonEncoder.Encode(sample); err != nil {
80+
log.Println("ERR-CFG", err.Error())
7881
return false, err
7982
} else {
8083
created = true
@@ -158,13 +161,8 @@ func getEnvAPI() (string, bool) {
158161
// build the full path to the GoveeLux configuration file and take into
159162
// account whether it is MacOS, Linux or Windows.
160163
func getConfigFullPath() string {
161-
const (
162-
HOME_ENV = "HOME" // environment var. holding user home directory
163-
MY_CONFIG = ".config/goveelux.json" // config file relative to HOME_ENV
164-
)
165164
// platform-generic user profile directory 'HOME'
166-
basename := MY_CONFIG
167-
envVar := HOME_ENV
165+
var basename, envVar string
168166

169167
switch runtime.GOOS {
170168
case "windows":
@@ -176,10 +174,11 @@ func getConfigFullPath() string {
176174
basename = ".goveelux.json"
177175
break
178176
case "linux":
179-
fallthrough
177+
envVar = "HOME"
178+
basename = ".config/goveelux.json"
179+
break
180180
default:
181-
envVar = HOME_ENV
182-
basename = MY_CONFIG
181+
log.Fatal("ERR-CFG", "unknown OS")
183182
}
184183

185184
return path.Join(os.Getenv(envVar), basename)

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323
)
2424

2525
// NOTE: Change these values accordingly
26-
var Version string = version{NAME, "1.1.1", statusReleased, 1}.String()
26+
var Version string = version{NAME, "1.2", statusReleased, 0}.String()
2727

2828
/* ----------------------------------------------------------------
2929
* T y p e s

0 commit comments

Comments
 (0)