Skip to content

Commit

Permalink
Backup EQ profile
Browse files Browse the repository at this point in the history
  • Loading branch information
hilli committed Feb 11, 2024
1 parent f73ef44 commit 78cfcc2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 24 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ func main() {
- [x] Turn on/off
- [x] Track next/previous
- [x] Discover speakers automatically
- [x] Display cover art in ASCII (wifi media)
- [x] Backup speaker settings/eq profiles to file
- [ ] Restore speaker settings/eq profiles to file
- [ ] Play Podcasts/Radio
- [ ] Play titles from built-in music streaming services (Tidal, Qobus)
- [ ] Backup/restore speaker settings/eq profiles to file
- [ ] Play titles from built-in music streaming services (Amazon Music, Deezer, Qobus, Spotify, Tidal)

### Usage

Expand Down Expand Up @@ -114,6 +116,13 @@ Turn the speakers off
kefw2 off
```

Backup the current EQ Profile

```shell
kefw2 eq_profile > my_profile.json
```


All with tab completion available of the options.

## Player
Expand Down Expand Up @@ -142,7 +151,7 @@ Not there yet.
- [ ] Status page, refreshing, display artwork and track info in wifi mode (web)
- [ ] Settings page, editing (web)
- [ ] Backup/restore settings to file download (web)
- [ ] ?? Streaming page, playing Tidal, Qobus, podcasts, radio (web)
- [ ] ?? Streaming page, playing Tidal, Qobus, podcasts, radio, etc (web)

## License

Expand Down
23 changes: 23 additions & 0 deletions cmd/kefw2/cmd/eq_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// muteCmd toggles the mute state of the speakers
var eqProfileCmd = &cobra.Command{
Use: "eq_profile",
Short: "Get the equaliser Profile of the speakers",
Long: `Get the equaliser Profile of the speakers`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
eqProfile, _ := currentSpeaker.GetEQProfileV2()
fmt.Println(eqProfile)
},
}

func init() {
rootCmd.AddCommand(eqProfileCmd)
}
59 changes: 38 additions & 21 deletions kefw2/eqprofilev2.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
package kefw2

import "encoding/json"

type EQProfileV2 struct {
SubwooferCount int `json:"subwooferCount"` // 0, 1, 2
TrebleAmount float32 `json:"trebleAmount"`
DeskMode bool `json:"deskMode"`
BassExtension string `json:"bassExtension"` // less, standard, more
HighPassMode bool `json:"highPassMode"`
AudioPolarity string `json:"audioPolarity"`
IsExpertMode bool `json:"isExpertMode"`
DeskModeSetting int `json:"deskModeSetting"`
SubwooferPreset string `json:"subwooferPreset"`
HighPassModeFreq int `json:"highPassModeFreq"`
WallModeSetting float32 `json:"wallModeSetting"`
Balance int `json:"balance"`
SubEnableStereo bool `json:"subEnableStereo"`
SubwooferPolarity string `json:"subwooferPolarity"`
SubwooferGain int `json:"subwooferGain"`
IsKW1 bool `json:"isKW1"`
PhaseCorrection bool `json:"phaseCorrection"`
WallMode bool `json:"wallMode"`
ProfileId string `json:"profileId"`
ProfileName string `json:"profileName"`
SubOutLPFreq float32 `json:"subOutLPFreq"`
SubwooferCount int `json:"subwooferCount"` // 0, 1, 2
TrebleAmount float32 `json:"trebleAmount"`
DeskMode bool `json:"deskMode"`
BassExtension string `json:"bassExtension"` // less, standard, more
HighPassMode bool `json:"highPassMode"`
AudioPolarity string `json:"audioPolarity"`
IsExpertMode bool `json:"isExpertMode"`
DeskModeSetting int `json:"deskModeSetting"`
SubwooferPreset string `json:"subwooferPreset"`
HighPassModeFreq int `json:"highPassModeFreq"`
WallModeSetting float32 `json:"wallModeSetting"`
Balance int `json:"balance"`
SubEnableStereo bool `json:"subEnableStereo"`
SubwooferPolarity string `json:"subwooferPolarity"`
SubwooferGain int `json:"subwooferGain"`
IsKW1 bool `json:"isKW1"`
PhaseCorrection bool `json:"phaseCorrection"`
WallMode bool `json:"wallMode"`
ProfileId string `json:"profileId"`
ProfileName string `json:"profileName"`
SubOutLPFreq float32 `json:"subOutLPFreq"`
SubwooferOutHotfix bool `json:"subwooferOutHotfix"`
SubwooferOut bool `json:"subwooferOut"`
}

// GetEQProfileV2 returns the current EQProfileV2 for the speaker
// EQ Profiles are connected to the selected source
func (s *KEFSpeaker) GetEQProfileV2() (EQProfileV2, error) {
eqProfile, err := JSONUnmarshalValue(s.getData("kef:eqProfile/v2"))
return eqProfile.(EQProfileV2), err
}

// String dumps a json EQProfileV2
func (e EQProfileV2) String() string {
profile, _ := json.MarshalIndent(e, "", " ")
return string(profile)
}
10 changes: 10 additions & 0 deletions kefw2/json_parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func JSONUnmarshalValue(data []byte, err error) (value any, err2 error) {
value = SpeakerStatus(jsonData[0]["kefSpeakerStatus"].(string))
case "kefCableMode":
value = CableMode(jsonData[0]["kefCableMode"].(string))
case "kefEqProfileV2":
// Unmarshal the EQProfileV2 part of the JSON data.
// But turn the relevant part of the jsonData into json again first.
var eqProfile EQProfileV2
eqPJSON, _ := json.Marshal(jsonData[0]["kefEqProfileV2"])
err2 = json.Unmarshal(eqPJSON, &eqProfile)
if err2 != nil {
return nil, err2
}
value = eqProfile
default:
return nil, errors.New("Unknown type: " + tvalue)
}
Expand Down

0 comments on commit 78cfcc2

Please sign in to comment.