edge_core/adapter.rs
1//! Service adapter trait. Each concrete adapter (Roon, Hue, ...) implements
2//! this to accept intents and publish state updates.
3
4use async_trait::async_trait;
5use tokio::sync::broadcast;
6
7use super::intent::Intent;
8
9/// State update from an external service. The edge-agent forwards these
10/// over WebSocket to the config-server for fan-out to the Web UI, and
11/// can also drive local device feedback (LED glyphs, etc.).
12#[derive(Debug, Clone)]
13pub struct StateUpdate {
14 pub service_type: String,
15 pub target: String,
16 pub property: String,
17 pub output_id: Option<String>,
18 pub value: serde_json::Value,
19}
20
21#[async_trait]
22pub trait ServiceAdapter: Send + Sync {
23 /// Stable identifier used to match against `Mapping.service_type`.
24 fn service_type(&self) -> &'static str;
25
26 /// Send an intent to a specific target (zone_id, group_id, ...).
27 async fn send_intent(&self, target: &str, intent: &Intent) -> anyhow::Result<()>;
28
29 /// Subscribe to state updates from this adapter.
30 fn subscribe_state(&self) -> broadcast::Receiver<StateUpdate>;
31}