diff --git a/v2/crates/homecore-api/src/app.rs b/v2/crates/homecore-api/src/app.rs index 814d22ea..e7d094e7 100644 --- a/v2/crates/homecore-api/src/app.rs +++ b/v2/crates/homecore-api/src/app.rs @@ -27,6 +27,7 @@ pub fn router(state: SharedState) -> Router { Router::new() .route("/api/", get(rest::api_root)) .route("/api/config", get(rest::get_config)) + .route("/api/components", get(rest::get_components)) .route("/api/states", get(rest::get_states)) .route( "/api/states/:entity_id", diff --git a/v2/crates/homecore-api/src/rest.rs b/v2/crates/homecore-api/src/rest.rs index 7e9fa451..89b5b190 100644 --- a/v2/crates/homecore-api/src/rest.rs +++ b/v2/crates/homecore-api/src/rest.rs @@ -44,6 +44,15 @@ pub struct ApiConfig { components: Vec, } +const LOADED_COMPONENTS: &[&str] = &[ + "api", + "automation", + "config", + "homecore", + "recorder", + "websocket_api", +]; + pub async fn get_config( headers: HeaderMap, State(s): State, @@ -53,10 +62,26 @@ pub async fn get_config( location_name: s.location_name().to_string(), version: s.version().to_string(), state: "RUNNING", - components: vec![], + components: LOADED_COMPONENTS + .iter() + .map(|component| (*component).to_owned()) + .collect(), })) } +pub async fn get_components( + headers: HeaderMap, + State(s): State, +) -> ApiResult>> { + let _ = BearerAuth::from_headers(&headers, s.tokens()).await?; + Ok(Json( + LOADED_COMPONENTS + .iter() + .map(|component| (*component).to_owned()) + .collect(), + )) +} + #[derive(Serialize)] pub struct StateView { pub entity_id: String, @@ -280,10 +305,14 @@ pub async fn fire_event( } else { body }; - s.homecore() - .bus() - .fire_domain(homecore::DomainEvent::new(event_type, data, Context::new())); - Ok(Json(serde_json::json!({"message": "Event fired."}))) + s.homecore().bus().fire_domain(homecore::DomainEvent::new( + event_type.clone(), + data, + Context::new(), + )); + Ok(Json( + serde_json::json!({"message": format!("Event {event_type} fired.")}), + )) } #[derive(Deserialize)]