Skip to content

Commit

Permalink
feat: add setting for volume step size
Browse files Browse the repository at this point in the history
  • Loading branch information
feuerrot committed Oct 14, 2020
1 parent 48efd80 commit 3048ecd
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions mpzbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import (
const volumedelta int = 5

type mpzbc struct {
mqttClient mqtt.Client
mqttServer string
mqttTopic string
mpdClient *mpd.Client
mpdServer string
mpdStatus string
mpdVolume int
update bool
mqttClient mqtt.Client
mqttServer string
mqttTopic string
mpdClient *mpd.Client
mpdServer string
mpdStatus string
mpdVolume int
mpdVolumeDelta int
update bool
}

type control struct {
Expand Down Expand Up @@ -53,14 +54,14 @@ func (m *mpzbc) mqttMessage(client mqtt.Client, msg mqtt.Message) {
m.updateMPD()
if m.mpdVolume != -1 {
if err := m.mpdClient.SetVolume(m.mpdVolume - volumedelta); err != nil {
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume-volumedelta, err)
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume-m.mpdVolumeDelta, err)
}
}
case "rotate_right":
m.updateMPD()
if m.mpdVolume != -1 {
if err := m.mpdClient.SetVolume(m.mpdVolume + volumedelta); err != nil {
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume+volumedelta, err)
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume+m.mpdVolumeDelta, err)
}
}
case "skip_backward":
Expand Down Expand Up @@ -161,6 +162,21 @@ func (m *mpzbc) getEnv() error {
}
log.Printf("MPD Server\t%s\n", m.mpdServer)

volumestepenv := os.Getenv("VOLUMESTEP")
if volumestepenv == "" {
log.Printf("VOLUMESTEP is empty, use default (%d)\n", volumedelta)
m.mpdVolumeDelta = volumedelta
} else {
volumestep, err := strconv.Atoi(volumestepenv)
if err != nil {
log.Printf("couldn't parse VOLUMESTEP \"%s\" as int, use default (%d): %v", volumestepenv, volumedelta, err)
m.mpdVolumeDelta = volumedelta
} else {
log.Printf("VOLUMESTEP: %d%%\n", volumestep)
m.mpdVolumeDelta = volumestep
}
}

return nil
}

Expand Down

0 comments on commit 3048ecd

Please sign in to comment.