-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathswitch.go
More file actions
50 lines (43 loc) · 1 KB
/
switch.go
File metadata and controls
50 lines (43 loc) · 1 KB
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
package miio
// SwitchState describes a state of the switch.
type SwitchState struct {
Click ClickType
Battery float32
}
// Switch defines a Xiaomi switch.
type Switch struct {
XiaomiDevice
ID string
Gateway *Gateway
State *SwitchState
}
// Stops is not uses for gateway devices.
func (s *Switch) Stop() {
}
// GetUpdateMessage returns device's state update message.
func (s *Switch) GetUpdateMessage() *DeviceUpdateMessage {
return &DeviceUpdateMessage{
ID: s.ID,
State: s.State,
}
}
// UpdateState performs a device update.
func (s *Switch) UpdateState() {
s.State.Battery = s.GetBatteryLevel(s.State.Battery)
clType, err := internalClickString(s.getFieldValue(fieldStatus))
if err != nil {
s.State.Click = ClickNo
}
switch clType {
case clClick:
s.State.Click = ClickSingle
case clDoubleClick:
s.State.Click = ClickDouble
case clLongClickPress:
s.State.Click = ClickLongPress
case clLongClickRelease:
s.State.Click = ClickLongRelease
default:
s.State.Click = ClickNo
}
}