-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (83 loc) · 1.78 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"encoding/json"
"fmt"
"github.com/getcasa/sdk"
)
// Config define the casa plugin configuration
var Config = sdk.Configuration{
Name: "Ikea Tradfri",
Version: "1.0.0",
Author: "casa",
Description: "Control Ikea Tradfri ecosystem",
Discover: true,
Devices: []sdk.Device{
sdk.Device{
Name: "TRADFRI bulb E27 WS opal 1000lm",
DefaultTrigger: "",
DefaultAction: "toggle",
Triggers: []sdk.Trigger{},
Actions: []string{"toggle"},
},
},
Actions: []sdk.Action{
sdk.Action{
Name: "toggle",
Fields: []sdk.Field{},
},
},
}
func main() {
OnStart([]byte("{}"))
}
type savedConfig struct {
Identity string
PSK string
}
// ConfigPlugin store the saved config
var ConfigPlugin savedConfig
// Init plugin config
func Init() []byte {
res, _ := json.Marshal([]savedConfig{})
return res
}
// OnStart discover brdiges and create the global state
func OnStart(config []byte) {
if err := json.Unmarshal(config, &ConfigPlugin); err != nil {
panic(err)
}
Connect()
}
// Discover return array of all found devices
func Discover() []sdk.DiscoveredDevice {
var discovered []sdk.DiscoveredDevice
return discovered
}
// Params define actions parameters available
type Params struct {
State bool `json:"state"`
}
// CallAction call functions from actions
func CallAction(physicalID string, name string, params []byte, config []byte) {
if string(params) == "" {
fmt.Println("Params must be provided")
}
// declare parameters
var req Params
// unmarshal parameters to use in actions
err := json.Unmarshal(params, &req)
if err != nil {
fmt.Println(err)
}
// use name to call actions
switch name {
case "toggle":
//
default:
return
}
}
// OnStop close connection
func OnStop() {
Conn.Close()
}