mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 04:38:20 +00:00
Added receive timestamp for MQTT messages
This commit is contained in:
10
bridge.go
10
bridge.go
@@ -360,7 +360,7 @@ func (br *Bridge) saveZ2MState() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (br *Bridge) handleMqttMessage(_ mqtt.Client, msg mqtt.Message) {
|
func (br *Bridge) handleMqttMessage(_ mqtt.Client, msg mqtt.Message) {
|
||||||
topic, payload := msg.Topic(), msg.Payload()
|
topic, payload, recvTime := msg.Topic(), msg.Payload(), time.Now()
|
||||||
|
|
||||||
// check for topic prefix and remove it
|
// check for topic prefix and remove it
|
||||||
l := len(MQTT_TOPIC_PREFIX)
|
l := len(MQTT_TOPIC_PREFIX)
|
||||||
@@ -421,7 +421,7 @@ func (br *Bridge) handleMqttMessage(_ mqtt.Client, msg mqtt.Message) {
|
|||||||
log.Print("applying deferred updates...")
|
log.Print("applying deferred updates...")
|
||||||
br.pendingUpdates.Range(func(k, v any) bool {
|
br.pendingUpdates.Range(func(k, v any) bool {
|
||||||
devName := k.(string)
|
devName := k.(string)
|
||||||
br.UpdateAccessoryState(devName, v.([]byte))
|
br.UpdateAccessoryState(devName, v.([]byte), recvTime)
|
||||||
return true // continue
|
return true // continue
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -436,7 +436,7 @@ func (br *Bridge) handleMqttMessage(_ mqtt.Client, msg mqtt.Message) {
|
|||||||
br.pendingUpdates.Store(topic, payload)
|
br.pendingUpdates.Store(topic, payload)
|
||||||
}
|
}
|
||||||
} else if !isBridgeTopic {
|
} else if !isBridgeTopic {
|
||||||
br.UpdateAccessoryState(topic, payload)
|
br.UpdateAccessoryState(topic, payload, recvTime)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -655,7 +655,7 @@ func parseLastSeen(ts any) (time.Time, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle MQTT message to update accessory state
|
// Handle MQTT message to update accessory state
|
||||||
func (br *Bridge) UpdateAccessoryState(devName string, payload []byte) {
|
func (br *Bridge) UpdateAccessoryState(devName string, payload []byte, tstamp time.Time) {
|
||||||
dev := br.devices[devName]
|
dev := br.devices[devName]
|
||||||
if dev == nil {
|
if dev == nil {
|
||||||
if br.DebugMode || BRIDGE_DEVMODE {
|
if br.DebugMode || BRIDGE_DEVMODE {
|
||||||
@@ -677,7 +677,7 @@ func (br *Bridge) UpdateAccessoryState(devName string, payload []byte) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSeen := time.Now()
|
lastSeen := tstamp
|
||||||
if lastSeenProp, found := newState["last_seen"]; found {
|
if lastSeenProp, found := newState["last_seen"]; found {
|
||||||
ts, err := parseLastSeen(lastSeenProp)
|
ts, err := parseLastSeen(lastSeenProp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user