Skip to content

0.3.0 Track A: DataModelHandler reads cache (water-leak endpoint)#34

Merged
avrabe merged 1 commit into
mainfrom
0.3.0/datamodel-pull
May 28, 2026
Merged

0.3.0 Track A: DataModelHandler reads cache (water-leak endpoint)#34
avrabe merged 1 commit into
mainfrom
0.3.0/datamodel-pull

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 28, 2026

Summary

Closes the push/pull loop. A commissioned Matter controller can now read BooleanState::StateValue on a Water Leak Detector endpoint and get the value the wohl dispatcher pushed into the cache (slice 5). This is the pull side the architecture critic flagged in PR #29 — rs-matter polls our DataModelHandler; we serve from the AttributeCache.

End-to-end (feature on): RsMatterBridge::start_commissioning() spawns the thread sharing the cache → a sensor's water-leak alert flows through publish_alert into the cache → a controller subscribed to the water-leak endpoint sees StateValue=true.

What's in this PR

File Change
src/commissioning.rs CacheBooleanState implements rs-matter's generated boolean_state::ClusterHandler; state_value reads the cache (factored into a pure, unit-testable current_state()). DEV_TYPE_WATER_LEAK_DETECTOR (DTL 0x0043) defined locally — this rs-matter rev ships no sensor device-type constants. NODE gains the water-leak endpoint; bridge_handler chains its descriptor + BooleanState handlers. start/run_matter thread the Arc<AttributeCache>. 4 new unit tests.
src/rs_matter.rs start_commissioning() passes Arc::clone(&self.cache) so the cache publish_* writes is the one the handler reads.

Oracles green on 1.87.0

cargo +1.87.0 fmt -p wohl-matter-bridge --check               OK
cargo +1.87.0 clippy ... --features rs-matter-backend -D warnings  OK
cargo +1.87.0 test -p wohl-matter-bridge --lib                34/34 (feature off)
cargo +1.87.0 test ... --features rs-matter-backend --lib     47/47 (feature on; +4)
cargo kani -p wohl-alert                                      4/4 harnesses
spar analyze (StarterHome.Deployed)                           0 errors
rivet validate                                                PASS

What's NOT in this PR (next slice)

  • Single endpoint, single cluster — one Water Leak Detector (ep 1), BooleanState only. The full Matter Bridge topology (aggregator + dynamically-registered bridged endpoints per wohl zone/contact/circuit, across Temperature / Power / Concentration clusters) is next. Those handlers follow the same shape; measurement clusters return Nullable<T>.
  • Identity endpoint mapping — wohl id == Matter ep id for this demo. The general allocation policy is DESIGN.md §7.1.
  • No aggregator / Bridged cluster — single standalone device, not yet the aggregator+bridged-node topology of SWARCH-WOHL-006. Lands with the multi-endpoint slice.
  • Still rs-matter test DAC / vendor 0xFFF1.

Verified line: untouched

Zero edits to crates/wohl-{leak,temp,air,door,power,alert,ota,fw-door-bench}/, proofs/verus/, or fuzz/. Kani 4/4 on wohl-alert.

Test plan

  • CI green across all 14 jobs.
  • After merge: multi-endpoint bridge topology (aggregator + per-sensor bridged endpoints, all cluster types).

🤖 Generated with Claude Code

A commissioned Matter controller can now read BooleanState::StateValue
on a Water Leak Detector endpoint and get the value the wohl dispatcher
pushed into the cache. This closes the push/pull loop the architecture
critic flagged: publish_* (slice 5) writes the cache; this slice's
DataModelHandler reads it when rs-matter polls.

What's in this slice

  src/commissioning.rs
    - `CacheBooleanState` implements the rs-matter generated
      `boolean_state::ClusterHandler` trait. Its `state_value` reads
      `AttributeKey::new(wohl_endpoint_id, 0x0045, 0x0000)` from the
      shared `Arc<AttributeCache>`; returns false (no leak) when the
      cache has no entry yet — the safe default for a leak detector.
      The read body is factored into a pure `current_state()` helper
      so it's unit-testable without mocking rs-matter's ReadContext.
    - `DEV_TYPE_WATER_LEAK_DETECTOR` (DTL 0x0043) defined locally —
      this rs-matter rev ships no sensor device-type constants
      (`DeviceType { dtype, drev }` is a plain pub struct, so we
      define the ones we need). The mandatory server cluster for
      this device type is BooleanState per DESIGN.md §2.
    - NODE gains a Water Leak Detector endpoint (ep 1) exposing the
      descriptor + BooleanState clusters, alongside the root endpoint.
    - `bridge_handler(rand, cache)` (was `commissioning_only_handler`)
      chains the endpoint's descriptor handler + the cache-backed
      BooleanState handler via `EpClMatcher`.
    - `start` / `run_matter` thread the `Arc<AttributeCache>` through
      to the handler builder.
    - 4 unit tests on `current_state()`: empty cache → false, leak
      published → true, per-endpoint isolation, and the device-type id.

  src/rs_matter.rs
    - `start_commissioning()` passes `Arc::clone(&self.cache)` into
      the commissioning thread, so the same cache that `publish_*`
      writes is the one the handler reads.

End-to-end (feature on): construct RsMatterBridge → start_commissioning
spawns the thread with the cache → a sensor's water-leak alert flows
through publish_alert into the cache → a controller subscribed to the
water-leak endpoint sees StateValue=true.

What's NOT in this slice

  - **Single endpoint, single cluster.** Only one Water Leak Detector
    endpoint (ep 1), BooleanState only. The full Matter Bridge
    topology (aggregator + dynamically-registered bridged endpoints,
    one per wohl zone/contact/circuit, across all cluster types:
    Temperature / Power / Concentration) is the next slice. Those
    handlers follow the same shape — each generated cluster has its
    own typed ClusterHandler trait (measurement clusters return
    Nullable<T>).
  - **Identity endpoint mapping.** wohl endpoint id == Matter
    endpoint id for this demo (ep 1). The general wohl-zone →
    Matter-endpoint allocation policy is DESIGN.md §7.1, formalised
    in the multi-endpoint slice.
  - **No aggregator / Bridged cluster.** This is a single
    standalone device, not yet the aggregator+bridged-node topology
    SWARCH-WOHL-006 describes. That topology + the BridgedHandler
    land with the multi-endpoint slice.
  - Still the rs-matter test DAC / vendor 0xFFF1.

Oracles green on 1.87.0

  cargo +1.87.0 fmt -p wohl-matter-bridge --check               OK
  cargo +1.87.0 clippy ... --features rs-matter-backend
    -- -D warnings                                              OK
  cargo +1.87.0 test -p wohl-matter-bridge --lib                34/34 (feature off)
  cargo +1.87.0 test ... --features rs-matter-backend --lib     47/47 (feature on; +4)
  cargo kani -p wohl-alert                                      4/4 harnesses
  spar analyze (StarterHome.Deployed)                           0 errors
  rivet validate                                                PASS

Verified line: untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit a0207ce into main May 28, 2026
14 checks passed
@avrabe avrabe deleted the 0.3.0/datamodel-pull branch May 28, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant