-
Notifications
You must be signed in to change notification settings - Fork 1
/
xiaomibutton.go
42 lines (34 loc) · 1.19 KB
/
xiaomibutton.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
package deviceadapters
import (
"github.com/function61/hautomo/pkg/evdevcodes"
"github.com/function61/hautomo/pkg/ezstack/ezhub/hubtypes"
"github.com/function61/hautomo/pkg/ezstack/zcl/cluster"
)
func init() {
defineAdapter(modelAqaraButtonSensor,
aqaraVoltageEtc,
withBatteryType(BatteryCR2032),
attributeParser("genOnOff.onOff", xiaomiButtonGenOnOffOnOff),
attributeParser("genOnOff.unknown(32768)", xiaomiButtonMultiClick),
)
}
func xiaomiButtonGenOnOffOnOff(attr *cluster.Attribute, actx *hubtypes.AttrsCtx) error {
// Xiaomi push button sends single click as two events:
// power=off
// power=on
// only react on "on", so we don't broadcast multiple state changes.
// they might come in a single Zigbee message which makes this a non-issue, but better safe.
if attr.Value.(bool) {
actx.Attrs.Press = actx.PressUp(evdevcodes.Btn0)
}
return nil
}
// it sends click >= 2 as manufacturer-specific attribute
func xiaomiButtonMultiClick(attr *cluster.Attribute, actx *hubtypes.AttrsCtx) error {
count := int(attr.Value.(uint64))
actx.Attrs.Press = actx.PressUp(evdevcodes.Btn0)
if count >= 2 { // FIXME: dirty setting after-the-fact
actx.Attrs.Press.CountRaw = &count
}
return nil
}