nitaybz / homebridge-network-presence

Homebridge plugin that provides occupancy sensor for devices presence in your network
MIT License
41 stars 6 forks source link

Fix setDeteceted #26

Open Shoshkin opened 2 years ago

Shoshkin commented 2 years ago

Assuming the following scenario -

  1. Device A is in this.isDetected = 1 state
  2. A disconnects from the network - setDetected is called with isDetected = 0, creating a timer that will trigger in threshold minutes. A is still on this.isDetected = 1.
  3. A connects back to the network before the timer fires, the previous timer is canceled but a new timer begins (since we do not enter the first if condition in setDetected)
  4. the timer fires, setting A's isDetected to 0. the network.js code now assumes that A is connected, it won't fire any new connected/disconnected event for that device

The solution is to make sure that only isDetected=0 creates a timer and that only isDetecetd=1 cancels the timer

wasnertobias commented 1 year ago

@nitaybz Could you please merge this? :)

Would fix issues for me most likely. E.g. I get two disconnect messages in the logs from the same device. No "connect" message im between!

[16/02/2023, 05:27:37] [homebridge-network-presence] [Pixel 5] - disconnected from the network (mac: f8:1a:xx:xx:xx:xx | ip:192.168.178.61 | hostname:Pixel-5.fritz.box) [16/02/2023, 07:22:23] [homebridge-network-presence] [Pixel 5] - disconnected from the network (mac: f8:1a:xx:xx:xx:xx | ip:192.168.178.61 | hostname:Pixel-5.fritz.box)