Mark old last_seen devices as "not responding"

Devices that have not received an update since a fixed timeout (24 hrs
for now), based on its last_seen time, will be marked as "not
responding" in the Home app. With this I can identify which devices are
unreachable or dead.

Also needed to upgrade hap with the fix for brutella/hap#30, or the
entire bridge will stop working.
This commit is contained in:
Darell Tan
2023-05-22 22:38:20 +08:00
parent edade53b06
commit 48eabc2342
3 changed files with 17 additions and 8 deletions

View File

@@ -410,6 +410,17 @@ func (br *Bridge) AddDevice(dev *Device, acc *accessory.A, mappings []*ExposeMap
return nil, 0
}
}
m.Characteristic.ValueRequestFunc = func(req *http.Request) (any, int) {
lastSeenSince := time.Since(brdev.LastSeen)
errCode := 0
if lastSeenSince >= Z2M_LAST_SEEN_TIMEOUT {
//log.Printf("dev %s last seen too long ago", name)
errCode = hap.JsonStatusServiceCommunicationFailure
}
return m.Characteristic.Val, errCode
}
}
br.devices[name] = brdev