Skip to content

Commit

Permalink
Fix fof occasional spurious door unlock notifications
Browse files Browse the repository at this point in the history
wait for a status command to be processes to properly set the initial state of
all homekit characteristics.  Also timeout if we don't receive a status in
a reasonable amount of time.  This prevents unintentional state changes if
a home hub reads the state before we initialize everything
Note, secplus1 doesnt have a status command so it will just timeout

This specifically addresses an issue where we get spurious door unlock
notifications, but will also address incorrect door states immediately
after booting.
  • Loading branch information
jgstroud authored and dkerr64 committed Oct 26, 2024
1 parent 8379dad commit f3ee86a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ All notable changes to `homekit-ratgdo` will be documented in this file. This pr
* Bugfix... ensure that network hostname is RFC952 compliant (e.g. no spaces).
* Bugfix... Possible fix to <https://github.com/ratgdo/homekit-ratgdo/issues/215> by modifying HomeKit server malloc() from local to global.
* Bugfix... Possible fix to <https://github.com/ratgdo/homekit-ratgdo/issues/211> and <https://github.com/ratgdo/homekit-ratgdo/issues/223> as we enable IRAM heap.
* Bugfix... Occasional HomeKit notification that garage door is unlocked. Tracked in <https://github.com/ratgdo/homekit-ratgdo/issues/233>

### Known Issues

* Occasional unexplained HomeKit notification that garage door is unlocked. Tracked in <https://github.com/ratgdo/homekit-ratgdo/issues/233>
* Occasional failure to connect to WiFi. Tracked in <https://github.com/ratgdo/homekit-ratgdo/issues/217>

## v1.7.1 (2024-09-23)
Expand Down
2 changes: 2 additions & 0 deletions src/comms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Queue_t pkt_q;
SoftwareSerial sw_serial;

extern struct GarageDoor garage_door;
extern bool status_done;

// For Time-to-close control
Ticker TTCtimer = Ticker();
Expand Down Expand Up @@ -755,6 +756,7 @@ void comms_loop_sec2()
notify_homekit_current_lock();
}

status_done = true;
break;
}

Expand Down
15 changes: 14 additions & 1 deletion src/ratgdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ uint32_t free_heap = 65535;
uint32_t min_heap = 65535;
unsigned long next_heap_check = 0;

bool status_done = false;
unsigned long status_timeout;

/********************************** MAIN LOOP CODE *****************************************/

void setup()
Expand Down Expand Up @@ -92,13 +95,23 @@ void setup()
led.idle();
RINFO("=== RATGDO setup complete ===");
RINFO("=============================");
status_timeout = millis() + 2000;
}

void loop()
{
improv_loop();
comms_loop();
homekit_loop();
// wait for a status command to be processes to properly set the initial state of
// all homekit characteristics. Also timeout if we don't receive a status in
// a reasonable amount of time. This prevents unintentional state changes if
// a home hub reads the state before we initialize everything
// Note, secplus1 doesnt have a status command so it will just timeout
if (status_done) {
homekit_loop();
} else if (millis() > status_timeout) {
status_done = true;
}
service_timer_loop();
web_loop();
loop_id = LOOP_SYSTEM;
Expand Down

0 comments on commit f3ee86a

Please sign in to comment.