forked from savaki/go.wemo
/
power.go
54 lines (47 loc) · 949 Bytes
/
power.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 main
import (
"github.com/codegangsta/cli"
"github.com/savaki/go.wemo"
)
var onCommand = cli.Command{
Name: "on",
Flags: []cli.Flag{
cli.StringFlag{"host", "", "device host and ip e.g. 10.0.1.2:49128", ""},
},
Action: onAction,
}
func onAction(c *cli.Context) {
host := c.String("host")
device := &wemo.Device{
Host: host,
}
device.On()
}
var offCommand = cli.Command{
Name: "off",
Flags: []cli.Flag{
cli.StringFlag{"host", "", "device host and ip e.g. 10.0.1.2:49128", ""},
},
Action: offAction,
}
func offAction(c *cli.Context) {
host := c.String("host")
device := &wemo.Device{
Host: host,
}
device.Off()
}
var toggleCommand = cli.Command{
Name: "toggle",
Flags: []cli.Flag{
cli.StringFlag{"host", "", "device host and ip e.g. 10.0.1.2:49128", ""},
},
Action: toggleAction,
}
func toggleAction(c *cli.Context) {
host := c.String("host")
device := &wemo.Device{
Host: host,
}
device.Toggle()
}