Skip to content

Commit

Permalink
Added max volume control
Browse files Browse the repository at this point in the history
  • Loading branch information
hilli committed Jun 19, 2023
1 parent 29e0c9b commit dea152d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
39 changes: 39 additions & 0 deletions cmd/kefw2/cmd/maxvolume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

// volumeCmd represents the volume command
var maxVolumeCmd = &cobra.Command{
Use: "maxvolume",
Aliases: []string{"maxvol"},
Short: "Get or adjust the max volume of the speakers",
Long: `Get or adjust the max volume of the speakers`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
volume, _ := currentSpeaker.GetMaxVolume()
fmt.Printf("Volume is: %d%%\n", volume)
return
}
volume, err := parseVolume(args[0])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = currentSpeaker.SetMaxVolume(volume)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
ValidArgsFunction: VolumeCompletion,
}

func init() {
rootCmd.AddCommand(maxVolumeCmd)
}
12 changes: 9 additions & 3 deletions kefw2/kefw2.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *KEFSpeaker) UpdateInfo() (err error) {
}
s.getId()
s.getModelAndVersion()
s.getMaxVolume()
s.GetMaxVolume()
return nil
}

Expand Down Expand Up @@ -157,11 +157,17 @@ func (s *KEFSpeaker) SpeakerState() (SpeakerStatus, error) {
return SpeakerStatus(speakerStatus.(SpeakerStatus)), err
}

func (s *KEFSpeaker) getMaxVolume() error {
func (s *KEFSpeaker) GetMaxVolume() (int, error) {
path := "settings:/kef/host/maximumVolume"
maxVolume, err := JSONIntValue(s.getData(path))
s.MaxVolume = maxVolume
return err
return maxVolume, err
}

func (s *KEFSpeaker) SetMaxVolume(maxVolume int) error {
path := "settings:/kef/host/maximumVolume"
s.MaxVolume = maxVolume
return s.setTypedValue(path, maxVolume)
}

func (s *KEFSpeaker) IsPlaying() (bool, error) {
Expand Down

0 comments on commit dea152d

Please sign in to comment.