Skip to content

Commit

Permalink
Bugfix: panic when a subscription is not reported on yet
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed May 13, 2024
1 parent 8449375 commit 623e163
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rs-matter/src/data_model/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ struct Subscription {

impl Subscription {
pub fn report_due(&self, now: Instant) -> bool {
self.changed
&& self.reported_at + embassy_time::Duration::from_secs(self.min_int_secs as _) <= now
self.changed && self.expired(self.min_int_secs, now)
}

pub fn is_expired(&self, now: Instant) -> bool {
self.reported_at + embassy_time::Duration::from_secs(self.max_int_secs as _) <= now
self.expired(self.max_int_secs, now)
}

fn expired(&self, secs: u16, now: Instant) -> bool {
self.reported_at
.checked_add(embassy_time::Duration::from_secs(secs as _))
.map(|expiry| expiry <= now)
.unwrap_or(false)
}
}

Expand Down

0 comments on commit 623e163

Please sign in to comment.