Skip to content

Commit f631ec6

Browse files
authored
Option to reset the in-memory Matter data as well (#26)
1 parent cf4a089 commit f631ec6

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

src/persist.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ where
4545
}
4646

4747
/// Reset the persist instance, removing all stored data from the non-volatile storage
48-
/// as well as removing all ACLs, fabrics and Wifi networks from the Matter stack.
48+
/// as well as removing all ACLs, fabrics and wireless networks from the Matter stack.
4949
pub async fn reset(&self) -> Result<(), Error> {
5050
let (mut kv, mut buf) = self.store.get().await;
5151

5252
kv.remove(MatterStackKey::Fabrics as _, &mut buf).await?;
5353
kv.remove(MatterStackKey::BasicInfo as _, &mut buf).await?;
5454
kv.remove(MatterStackKey::Networks as _, &mut buf).await?;
5555

56-
self.networks.reset()?;
56+
self.matter.reset_persist(false);
57+
self.networks.reset(false);
5758

58-
Ok(())
59+
self.matter.reset_transport()
5960
}
6061

6162
/// Load the Matter stack from the non-volatile storage.
@@ -151,7 +152,7 @@ where
151152
/// - `&NetworkContext` - which is used with the `WirelessBle` network.
152153
pub trait NetworkPersist: Sealed {
153154
/// Reset all networks, removing all stored data from the memory
154-
fn reset(&self) -> Result<(), Error>;
155+
fn reset(&self, flag_changed: bool);
155156

156157
/// Load the networks from the provided data BLOB
157158
fn load(&self, data: &[u8]) -> Result<(), Error>;
@@ -181,10 +182,8 @@ where
181182
M: RawMutex,
182183
T: WirelessNetwork,
183184
{
184-
fn reset(&self) -> Result<(), Error> {
185-
WirelessNetworks::reset(self);
186-
187-
Ok(())
185+
fn reset(&self, flag_changed: bool) {
186+
WirelessNetworks::reset(self, flag_changed);
188187
}
189188

190189
fn load(&self, data: &[u8]) -> Result<(), Error> {
@@ -209,9 +208,7 @@ where
209208
/// Used when the Matter stack is configured for Ethernet, as in that case
210209
/// there is no network state that needs to be saved
211210
impl NetworkPersist for () {
212-
fn reset(&self) -> Result<(), Error> {
213-
Ok(())
214-
}
211+
fn reset(&self, _flag_changed: bool) {}
215212

216213
fn load(&self, _data: &[u8]) -> Result<(), Error> {
217214
Ok(())

src/wireless.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,6 @@ where
157157
T: WirelessNetwork,
158158
E: Embedding + 'static,
159159
{
160-
/// Reset the Matter instance to the factory defaults putting it into a
161-
/// Commissionable mode.
162-
pub fn reset(&self) -> Result<(), Error> {
163-
// TODO: Reset fabrics and ACLs
164-
// TODO self.network.btp_gatt_context.reset()?;
165-
// TODO self.network.btp_context.reset();
166-
self.network.networks.reset();
167-
168-
Ok(())
169-
}
170-
171160
async fn run_net_coex<S, N, D, C, G>(
172161
&'static self,
173162
net_stack: S,

0 commit comments

Comments
 (0)