Skip to content

Commit

Permalink
Merge pull request #318 from markusressel/bugfix/fan-init-cmd-cannot-…
Browse files Browse the repository at this point in the history
…find-curve

Bugfix/fan init cmd cannot find curve
  • Loading branch information
markusressel authored Oct 3, 2024
2 parents 12eb126 + f306327 commit d52d202
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmd/fan/init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fan

import (
"github.com/markusressel/fan2go/internal"
"github.com/markusressel/fan2go/internal/configuration"
"github.com/markusressel/fan2go/internal/control_loop"
"github.com/markusressel/fan2go/internal/controller"
Expand All @@ -27,7 +28,10 @@ var initCmd = &cobra.Command{
ui.Info("Using persistence at: %s", dbPath)

p := persistence.NewPersistence(dbPath)

_, err = internal.InitializeObjects()
if err != nil {
return err
}
fanController := controller.NewFanController(
p,
fan,
Expand Down
15 changes: 12 additions & 3 deletions internal/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ func RunDaemon() {

pers := persistence.NewPersistence(configuration.CurrentConfig.DbPath)

fanControllers, err := initializeObjects(pers)
fanMap, err := InitializeObjects()
if err != nil {
ui.Fatal("Error initializing objects: %v", err)
}

fanControllers, err := initializeFanControllers(pers, fanMap)
if err != nil {
ui.Fatal("Error initializing fan controllers: %v", err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -221,7 +226,7 @@ func startStatisticsServer() *echo.Echo {
return echoPrometheus
}

func initializeObjects(pers persistence.Persistence) (map[fans.Fan]controller.FanController, error) {
func InitializeObjects() (map[configuration.FanConfig]fans.Fan, error) {
controllers := hwmon.GetChips()

err := initializeSensors(controllers)
Expand All @@ -233,12 +238,16 @@ func initializeObjects(pers persistence.Persistence) (map[fans.Fan]controller.Fa
return nil, fmt.Errorf("error initializing curves: %v", err)
}

var result = map[fans.Fan]controller.FanController{}
fanMap, err := initializeFans(controllers)
if err != nil {
return nil, fmt.Errorf("error initializing fans: %v", err)
}

return fanMap, err
}

func initializeFanControllers(pers persistence.Persistence, fanMap map[configuration.FanConfig]fans.Fan) (result map[fans.Fan]controller.FanController, err error) {
result = map[fans.Fan]controller.FanController{}
for config, fan := range fanMap {
updateRate := configuration.CurrentConfig.ControllerAdjustmentTickRate

Expand Down

0 comments on commit d52d202

Please sign in to comment.