Skip to content

Commit 3048ecd

Browse files
committed
feat: add setting for volume step size
1 parent 48efd80 commit 3048ecd

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

mpzbc.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ import (
1515
const volumedelta int = 5
1616

1717
type mpzbc struct {
18-
mqttClient mqtt.Client
19-
mqttServer string
20-
mqttTopic string
21-
mpdClient *mpd.Client
22-
mpdServer string
23-
mpdStatus string
24-
mpdVolume int
25-
update bool
18+
mqttClient mqtt.Client
19+
mqttServer string
20+
mqttTopic string
21+
mpdClient *mpd.Client
22+
mpdServer string
23+
mpdStatus string
24+
mpdVolume int
25+
mpdVolumeDelta int
26+
update bool
2627
}
2728

2829
type control struct {
@@ -53,14 +54,14 @@ func (m *mpzbc) mqttMessage(client mqtt.Client, msg mqtt.Message) {
5354
m.updateMPD()
5455
if m.mpdVolume != -1 {
5556
if err := m.mpdClient.SetVolume(m.mpdVolume - volumedelta); err != nil {
56-
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume-volumedelta, err)
57+
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume-m.mpdVolumeDelta, err)
5758
}
5859
}
5960
case "rotate_right":
6061
m.updateMPD()
6162
if m.mpdVolume != -1 {
6263
if err := m.mpdClient.SetVolume(m.mpdVolume + volumedelta); err != nil {
63-
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume+volumedelta, err)
64+
log.Printf("error during mpdClient.SetVolume(%d): %v", m.mpdVolume+m.mpdVolumeDelta, err)
6465
}
6566
}
6667
case "skip_backward":
@@ -161,6 +162,21 @@ func (m *mpzbc) getEnv() error {
161162
}
162163
log.Printf("MPD Server\t%s\n", m.mpdServer)
163164

165+
volumestepenv := os.Getenv("VOLUMESTEP")
166+
if volumestepenv == "" {
167+
log.Printf("VOLUMESTEP is empty, use default (%d)\n", volumedelta)
168+
m.mpdVolumeDelta = volumedelta
169+
} else {
170+
volumestep, err := strconv.Atoi(volumestepenv)
171+
if err != nil {
172+
log.Printf("couldn't parse VOLUMESTEP \"%s\" as int, use default (%d): %v", volumestepenv, volumedelta, err)
173+
m.mpdVolumeDelta = volumedelta
174+
} else {
175+
log.Printf("VOLUMESTEP: %d%%\n", volumestep)
176+
m.mpdVolumeDelta = volumestep
177+
}
178+
}
179+
164180
return nil
165181
}
166182

0 commit comments

Comments
 (0)