Skip to content

Commit

Permalink
Drop any types in GetId and use structs for json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
hilli committed Feb 22, 2024
1 parent 91e4d6c commit 3fd0296
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions kefw2/kefw2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ type KEFSpeaker struct {
MaxVolume int `mapstructure:"max_volume" json:"max_volume" yaml:"max_volume"`
}

type KEFGrouping struct {
GroupingMembers []KEFGroupingmember `json:"groupingMember"`
}

type KEFGroupingmember struct {
Master KEFGroupingData `json:"master`
Follower KEFGroupingData `json:"folloer"`
}

type KEFGroupingData struct {
Id string `json:"id"`
Name string `json:"name"`
}

var (
Models = map[string]string{
"lsxii": "KEF LSX II",
Expand Down Expand Up @@ -77,13 +91,12 @@ func (s *KEFSpeaker) getId() (err error) {
if err != nil {
return err
}
var groupData map[string]interface{}
groupData := KEFGrouping{}
err = json.Unmarshal(data, &groupData)
speakersets := groupData["rows"].([]interface{})
speakersets := groupData.GroupingMembers
for _, speakerset := range speakersets {
speakerset := speakerset.(map[string]interface{})
if speakerset["title"] == s.Name {
s.Id = speakerset["id"].(string)
if speakerset.Master.Name == s.Name {
s.Id = speakerset.Master.Id
}
}
return err
Expand Down

0 comments on commit 3fd0296

Please sign in to comment.