forked from orktes/go-alexa-smarthome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colortemperaturecontroller.go
54 lines (45 loc) · 1.65 KB
/
colortemperaturecontroller.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
package smarthome
import "time"
type SetColorTemperatureRequest struct {
ColorTemperatureInKelvin int `json:"colorTemperatureInKelvin"`
}
type colorTemperatureController struct {
sm *Smarthome
}
func (cc *colorTemperatureController) action(endpoint Endpoint, action string) (resp EndpointResponse, err error) {
val, err := cc.sm.invokeAction(endpoint, "Alexa.ColorTemperatureController", action, nil)
if err != nil {
return resp, err
}
resp.Properties = append(resp.Properties, Property{
Namespace: "Alexa.ColorTemperatureController",
Name: "colorTemperatureInKelvin",
Value: val,
TimeOfSample: zuluTime{time.Now()},
UncertaintyInMilliseconds: 0,
})
resp.Properties = append(resp.Properties, Property{
Namespace: "Alexa.EndpointHealth",
Name: "connectivity",
Value: map[string]interface{}{
"value": "OK",
},
TimeOfSample: zuluTime{time.Now()},
UncertaintyInMilliseconds: 0,
})
return
}
func (cc *colorTemperatureController) DecreaseColorTemperature(endpoint Endpoint) (resp EndpointResponse, err error) {
return cc.action(endpoint, "DecreaseColorTemperature")
}
func (cc *colorTemperatureController) IncreaseColorTemperature(endpoint Endpoint) (resp EndpointResponse, err error) {
return cc.action(endpoint, "IncreaseColorTemperature")
}
func (cc *colorTemperatureController) SetColorTemperature(endpoint Endpoint, payload SetColorTemperatureRequest) (resp EndpointResponse, err error) {
return cc.sm.setPropAndEndpointHealthResponse(
endpoint,
"Alexa.ColorTemperatureController",
"colorTemperatureInKelvin",
payload.ColorTemperatureInKelvin,
)
}