-
Notifications
You must be signed in to change notification settings - Fork 6
/
speaker.go
60 lines (48 loc) · 1.17 KB
/
speaker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package smarthome
type SetMuteRequest struct {
Mute bool `json:"mute"`
}
type SetVolumeRequest struct {
Volume int `json:"volume"`
}
type AdjustVolumeRequest struct {
VolumeDelta int `json:"volume"`
VolumeDefaut bool `json:"volumeDefault"`
}
type speaker struct {
sm *Smarthome
}
func (s *speaker) SetMute(endpoint Endpoint, payload SetMuteRequest) (resp EndpointResponse, err error) {
return s.sm.setPropAndEndpointHealthResponse(
endpoint,
"Alexa.Speaker",
"mute",
payload.Mute,
)
}
func (s *speaker) SetVolume(endpoint Endpoint, payload SetVolumeRequest) (resp EndpointResponse, err error) {
return s.sm.setPropAndEndpointHealthResponse(
endpoint,
"Alexa.Speaker",
"volume",
payload.Volume,
)
}
func (s *speaker) AdjustVolume(endpoint Endpoint, payload *AdjustVolumeRequest) (resp EndpointResponse, err error) {
var volume int
if val, err := s.sm.getValueForProperty(endpoint, "Alexa.Speaker", "volume"); err == nil {
volume = val.(int)
}
volume += payload.VolumeDelta
if volume > 100 {
volume = 100
} else if volume < 0 {
volume = 0
}
return s.sm.setPropAndEndpointHealthResponse(
endpoint,
"Alexa.Speaker",
"volume",
volume,
)
}