From fb8c6e1b1ba1958a941649132b36953514800d33 Mon Sep 17 00:00:00 2001 From: seydx Date: Sun, 26 Oct 2025 22:21:56 +0100 Subject: [PATCH] Update comments --- pkg/tuya/mqtt.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/tuya/mqtt.go b/pkg/tuya/mqtt.go index 79a30102..cf36e09c 100644 --- a/pkg/tuya/mqtt.go +++ b/pkg/tuya/mqtt.go @@ -79,12 +79,18 @@ type DisconnectFrame struct { Mode string `json:"mode"` } -// {"protocol":4,"t":1761487814,"data":{"dps":{"152":"0","160":1,"170":false}}} -type DPSMessage struct { - Protocol int `json:"protocol"` - T int `json:"t"` +type MqttLowPowerMessage struct { + Protocol int `json:"protocol"` + T int `json:"t"` + S int `json:"s,omitempty"` + Type string `json:"type,omitempty"` Data struct { - Dps map[string]interface{} `json:"dps"` + DevID string `json:"devId,omitempty"` + Online bool `json:"online,omitempty"` + LastOnlineChangeTime int64 `json:"lastOnlineChangeTime,omitempty"` + GwID string `json:"gwId,omitempty"` + Cmd string `json:"cmd,omitempty"` + Dps map[string]interface{} `json:"dps,omitempty"` } `json:"data"` } @@ -277,12 +283,13 @@ func (c *TuyaMqttClient) onMessage(client mqtt.Client, msg mqtt.Message) { } func (c *TuyaMqttClient) onLowPowerMessage(client mqtt.Client, msg mqtt.Message) { - var message DPSMessage + var message MqttLowPowerMessage if err := json.Unmarshal(msg.Payload(), &message); err != nil { return } - // Check if protocol is 4 and dps[149] is true (motion detection = camera ready) + // Check if protocol is 4 and dps[149] is true + // https://developer.tuya.com/en/docs/iot-device-dev/doorbell_solution?id=Kayamyivh15ox#title-2-Battery if message.Protocol == 4 { if val, ok := message.Data.Dps["149"]; ok { if ready, ok := val.(bool); ok && ready { @@ -290,7 +297,7 @@ func (c *TuyaMqttClient) onLowPowerMessage(client mqtt.Client, msg mqtt.Message) // However, we don't wait for this signal (like ismartlife.me doesn't either). // The camera starts responding immediately after WakeUp() is called, // so we proceed with the connection without blocking. - // This waiter is kept for potential future use or debugging. + // This waiter is kept for potential future use. c.wakeupWaiter.Done(nil) } }