-
Notifications
You must be signed in to change notification settings - Fork 6
/
percentagecontroller.go
44 lines (36 loc) · 1.03 KB
/
percentagecontroller.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
package smarthome
type SetPercentageRequest struct {
Percentage int `json:"percentage"`
}
type AdjustPercentageRequest struct {
PercentageDelta int `json:"percentageDelta"`
}
type percentageController struct {
sm *Smarthome
}
func (bc *percentageController) SetPercentage(endpoint Endpoint, payload *SetPercentageRequest) (resp EndpointResponse, err error) {
return bc.sm.setPropAndEndpointHealthResponse(
endpoint,
"Alexa.PercentageController",
"percentage",
payload.Percentage,
)
}
func (bc *percentageController) AdjustPercentage(endpoint Endpoint, payload *AdjustPercentageRequest) (resp EndpointResponse, err error) {
var percentage int
if val, err := bc.sm.getValueForProperty(endpoint, "Alexa.PercentageController", "percentage"); err == nil {
percentage = val.(int)
}
percentage += payload.PercentageDelta
if percentage > 100 {
percentage = 100
} else if percentage < 0 {
percentage = 0
}
return bc.sm.setPropAndEndpointHealthResponse(
endpoint,
"Alexa.PercentageController",
"percentage",
percentage,
)
}