-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtapo.go
133 lines (107 loc) · 4.17 KB
/
tapo.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package tapo
import (
"github.com/fabiankachlock/tapo-api/pkg/devices"
tapoutil "github.com/fabiankachlock/tapo-api/pkg/util"
)
// TapoClient is the main struct to interact with the Tapo API
type TapoClient struct {
username string
password string
}
// NewClient creates a new TapoClient
func NewClient(username, password string) TapoClient {
return TapoClient{username, password}
}
// Generic creates a new generic Tapo device
func (t TapoClient) Generic(ip string) (*devices.TapoGenericDevice, error) {
return devices.NewGenericDevice(ip, t.username, t.password)
}
// Plug creates a new Tapo plug device
func (t TapoClient) Plug(ip string) (*devices.TapoPlug, error) {
return devices.NewPlug(ip, t.username, t.password)
}
// Light creates a new Tapo light device
func (t TapoClient) Light(ip string) (*devices.TapoLight, error) {
return devices.NewLight(ip, t.username, t.password)
}
// ColorLight creates a new Tapo color light device
func (t TapoClient) ColorLight(ip string) (*devices.TapoColorLight, error) {
return devices.NewColorLight(ip, t.username, t.password)
}
// RgbLightStrip creates a new Tapo RGB light strip device
func (t TapoClient) RgbLightStrip(ip string) (*devices.TapoRgbLightStrip, error) {
return devices.NewRgbLightStrip(ip, t.username, t.password)
}
// RgbicLightStrip creates a new Tapo RGBIC light strip device
func (t TapoClient) RgbicLightStrip(ip string) (*devices.TapoRgbicLightStrip, error) {
return devices.NewRgbicLightStrip(ip, t.username, t.password)
}
// P100 creates a new Tapo P100 device
func (t TapoClient) P100(ip string) (*devices.TapoPlug, error) {
return devices.NewP100(ip, t.username, t.password)
}
// P105 creates a new Tapo P105 device
func (t TapoClient) P105(ip string) (*devices.TapoPlug, error) {
return devices.NewP105(ip, t.username, t.password)
}
// P100 creates a new Tapo P100 device
func (t TapoClient) P110(ip string) (*devices.TapoEnergyMonitoringPlug, error) {
return devices.NewP110(ip, t.username, t.password)
}
// P105 creates a new Tapo P105 device
func (t TapoClient) P115(ip string) (*devices.TapoEnergyMonitoringPlug, error) {
return devices.NewP115(ip, t.username, t.password)
}
// H100 creates a new Tapo H100 device
func (t TapoClient) H100(ip string) (*devices.TapoHub, error) {
return devices.NewH100(ip, t.username, t.password)
}
// H200 creates a new Tapo H200 device
func (t TapoClient) H200(ip string) (*devices.TapoHub, error) {
return devices.NewH200(ip, t.username, t.password)
}
// L900 creates a new Tapo L900 device
func (t TapoClient) L900(ip string) (*devices.TapoRgbLightStrip, error) {
return devices.NewL900(ip, t.username, t.password)
}
// L920 creates a new Tapo L920 device
func (t TapoClient) L920(ip string) (*devices.TapoRgbicLightStrip, error) {
return devices.NewL920(ip, t.username, t.password)
}
// L930 creates a new Tapo L930 device
func (t TapoClient) L930(ip string) (*devices.TapoRgbicLightStrip, error) {
return devices.NewL930(ip, t.username, t.password)
}
// L510 creates a new Tapo L510 device
func (t TapoClient) L510(ip string) (*devices.TapoLight, error) {
return devices.NewL510(ip, t.username, t.password)
}
// L520 creates a new Tapo L520 device
func (t TapoClient) L520(ip string) (*devices.TapoLight, error) {
return devices.NewL520(ip, t.username, t.password)
}
// L610 creates a new Tapo L610 device
func (t TapoClient) L610(ip string) (*devices.TapoLight, error) {
return devices.NewL610(ip, t.username, t.password)
}
// L530 creates a new Tapo L530 device
func (t TapoClient) L530(ip string) (*devices.TapoColorLight, error) {
return devices.NewL530(ip, t.username, t.password)
}
// L535 creates a new Tapo L535 device
func (t TapoClient) L535(ip string) (*devices.TapoColorLight, error) {
return devices.NewL535(ip, t.username, t.password)
}
// L630 creates a new Tapo L630 device
func (t TapoClient) L630(ip string) (*devices.TapoColorLight, error) {
return devices.NewL630(ip, t.username, t.password)
}
// GetNickname decodes a nickname of a device
func GetNickname(nickname string) string {
return tapoutil.GetNickname(nickname)
}
// GetSSID decodes an SSID of an device
func GetSSID(ssid string) string {
// nicknames and SSIDs are encoded the same way
return tapoutil.GetNickname(ssid)
}