Skip to content

Commit

Permalink
go-staticcheck & go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwichmann committed Mar 29, 2023
1 parent 4226968 commit 2f90dcc
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 69 deletions.
9 changes: 5 additions & 4 deletions archive.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,12 +26,13 @@ import (
"archive/zip"
"compress/gzip"
"errors"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
)

func extractBinaryFromZipArchive(archiveFile string, binaryName string, destinationFolder string) (binaryFile string, err error) {
Expand Down Expand Up @@ -82,7 +83,7 @@ func extractBinaryFromZipArchive(archiveFile string, binaryName string, destinat
}
}

return "", errors.New("Binary not found in archive")
return "", errors.New("binary not found in archive")
}

func extractBinaryFromTarArchive(archiveFile string, binaryName string, destinationFolder string) (binaryFile string, err error) {
Expand Down Expand Up @@ -136,5 +137,5 @@ func extractBinaryFromTarArchive(archiveFile string, binaryName string, destinat
}
}

return "", errors.New("Binary not found in archive")
return "", errors.New("binary not found in archive")
}
14 changes: 7 additions & 7 deletions bridge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -164,7 +164,7 @@ func (bridge *HueBridge) discover(ip string) error {

func (bridge *HueBridge) register() error {
if bridge.BridgeIP == "" {
return errors.New("Registration at bridge not possible because no IP is configured. Start discovery first or enter manually")
return errors.New("registration at bridge not possible because no IP is configured. Start discovery first or enter manually")
}

bridge.bridge = *hue.NewBridge(bridge.BridgeIP, "")
Expand All @@ -191,11 +191,11 @@ func (bridge *HueBridge) register() error {

func (bridge *HueBridge) connect() error {
if bridge.BridgeIP == "" {
return errors.New("No bridge IP configured")
return errors.New("no bridge IP configured")
}

if bridge.Username == "" {
return errors.New("No username on bridge configured")
return errors.New("no username on bridge configured")
}
bridge.bridge = *hue.NewBridge(bridge.BridgeIP, bridge.Username)

Expand Down Expand Up @@ -275,19 +275,19 @@ func (bridge *HueBridge) validateSofwareVersion() {

func (bridge *HueBridge) validateBridge() error {
if bridge.BridgeIP == "" {
return errors.New("No bridge configured. Could not validate")
return errors.New("no bridge configured. Could not validate")
}
resp, err := http.Get("http://" + bridge.BridgeIP + "/description.xml")
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return fmt.Errorf("Could not read bridge description: %v", err)
return fmt.Errorf("could not read bridge description: %v", err)
}

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("Could not read bridge description: %v", err)
return fmt.Errorf("could not read bridge description: %v", err)
}
if strings.Contains(string(data), "<modelNumber>929000226503</modelNumber>") {
bridge.Version = 1
Expand Down
2 changes: 1 addition & 1 deletion colorspace.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -162,7 +162,7 @@ func InitializeConfiguration(configurationFile string, enableWebInterface bool)
// Write saves a configuration to disk.
func (configuration *Configuration) Write() error {
if configuration.ConfigurationFile == "" {
return errors.New("No configuration filename configured")
return errors.New("no configuration filename configured")
}

if !configuration.HasChanged() {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (configuration *Configuration) Write() error {
// Read loads a configuration from disk.
func (configuration *Configuration) Read() error {
if configuration.ConfigurationFile == "" {
return errors.New("No configuration filename configured")
return errors.New("no configuration filename configured")
}

raw, err := ioutil.ReadFile(configuration.ConfigurationFile)
Expand Down
15 changes: 9 additions & 6 deletions configuration_migration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -21,9 +21,12 @@
// SOFTWARE.
package main

import "time"
import "fmt"
import log "github.com/sirupsen/logrus"
import (
"fmt"
"time"

log "github.com/sirupsen/logrus"
)

func (configuration *Configuration) migrateToLatestVersion() {
log.Debugf("⚙ Migrating configuration to latest version...")
Expand Down Expand Up @@ -83,10 +86,10 @@ func migrateTimestampFormat(timestamp string) (string, error) {

// Already new format? Return unchanged
layout = "15:04"
t, err = time.Parse(layout, timestamp)
_, err = time.Parse(layout, timestamp)
if err == nil {
return timestamp, nil
}

return "", fmt.Errorf("Invalid timestamp format: %s", timestamp)
return "", fmt.Errorf("invalid timestamp format: %s", timestamp)
}
10 changes: 5 additions & 5 deletions download.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -57,7 +57,7 @@ func downloadLatestReleaseInfo(url string) (releaseName string, assetURL string,
} else if releaseInfo["name"] != nil {
name = releaseInfo["name"].(string)
} else {
return "", "", errors.New("No releases available")
return "", "", errors.New("no releases available")
}

releaseAssets := releaseInfo["assets"].([]interface{})
Expand All @@ -70,7 +70,7 @@ func downloadLatestReleaseInfo(url string) (releaseName string, assetURL string,
}
}

return "", "", errors.New("No matching release found")
return "", "", errors.New("no matching release found")
}

func assetMatchesPlattform(asset map[string]interface{}) (bool, string) {
Expand All @@ -92,8 +92,8 @@ func assetMatchesPlattform(asset map[string]interface{}) (bool, string) {
// special case for arm64 vs arm, skip arm64 builds
if plattform == "arm" && strings.Contains(assetName, "arm64") {
return false, ""
}
}

// match file extension
if !(strings.Contains(assetName, "zip") || strings.Contains(assetName, "tar.gz")) {
return false, ""
Expand Down
21 changes: 6 additions & 15 deletions huelight.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -86,10 +86,7 @@ func (light *HueLight) supportsColorTemperature() bool {
}

func (light *HueLight) supportsBrightness() bool {
if light.Dimmable {
return true
}
return false
return light.Dimmable
}

func (light *HueLight) updateCurrentLightState(attr hue.LightAttributes) {
Expand Down Expand Up @@ -207,15 +204,9 @@ func (light *HueLight) hasColorTemperature(colorTemperature int) bool {
}

if light.SupportsXYColor && light.CurrentColorMode == "xy" {
if equalsFloat(colorTemperatureToXYColor(colorTemperature), light.CurrentColor, 0.001) {
return true
}
return false
return equalsFloat(colorTemperatureToXYColor(colorTemperature), light.CurrentColor, 0.001)
} else if light.SupportsColorTemperature && light.CurrentColorMode == "ct" {
if equalsInt(light.CurrentColorTemperature, mapColorTemperature(colorTemperature), 2) {
return true
}
return false
return equalsInt(light.CurrentColorTemperature, mapColorTemperature(colorTemperature), 2)
}

// Missmatch in color modes? Log warning for debug purposes and assume unchanged
Expand Down Expand Up @@ -246,7 +237,7 @@ func (light *HueLight) getCurrentColorTemperature() (int, error) {
return int(float64(1000000) / float64(light.CurrentColorTemperature)), nil
}

return 0, errors.New("Could not determine current color temperature")
return 0, errors.New("could not determine current color temperature")
}

func (light *HueLight) getCurrentBrightness() (int, error) {
Expand All @@ -258,7 +249,7 @@ func (light *HueLight) getCurrentBrightness() (int, error) {
return int((float64(light.CurrentBrightness) / float64(254)) * float64(100)), nil
}

return 0, errors.New("Could not determine current brightness")
return 0, errors.New("could not determine current brightness")
}

func mapColorTemperature(colorTemperature int) int {
Expand Down
2 changes: 1 addition & 1 deletion interval.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion light.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion lightstate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion location.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion scenes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions schedule.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -43,7 +43,7 @@ type Schedule struct {
func (schedule *Schedule) currentInterval(timestamp time.Time) (Interval, error) {
// check if timestamp respresents the current day
if timestamp.After(schedule.endOfDay) {
return Interval{TimeStamp{time.Now(), 0, 0}, TimeStamp{time.Now(), 0, 0}}, fmt.Errorf("No current interval as the requested timestamp (%v) lays after the end of the current schedule (%v)", timestamp, schedule.endOfDay)
return Interval{TimeStamp{time.Now(), 0, 0}, TimeStamp{time.Now(), 0, 0}}, fmt.Errorf("no current interval as the requested timestamp (%v) lays after the end of the current schedule (%v)", timestamp, schedule.endOfDay)
}

// if we are between todays sunrise and sunset, return daylight interval
Expand Down
2 changes: 1 addition & 1 deletion time.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2018 Stefan Wichmann
// # Copyright (c) 2018 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion upgrade.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 3 additions & 6 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -33,7 +33,7 @@ import (

func containsString(slice []string, element string) bool {
for _, current := range slice {
if strings.ToLower(current) == strings.ToLower(element) {
if strings.EqualFold(current, element) {
return true
}
}
Expand Down Expand Up @@ -92,10 +92,7 @@ func equalsFloat(a []float32, b []float32, maxDiff float32) bool {
}

func equalsInt(a int, b int, maxDiff int) bool {
if abs(a-b) > maxDiff {
return false
}
return true
return abs(a-b) <= maxDiff
}

// Restart the running binary.
Expand Down
2 changes: 1 addition & 1 deletion util_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2019 Stefan Wichmann
// # Copyright (c) 2019 Stefan Wichmann
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 2f90dcc

Please sign in to comment.