feat(homecore-api): expose loaded components

This commit is contained in:
ruv
2026-07-27 14:07:06 -04:00
parent ac1fdfb725
commit 273bd449c8
2 changed files with 35 additions and 5 deletions
+1
View File
@@ -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",
+34 -5
View File
@@ -44,6 +44,15 @@ pub struct ApiConfig {
components: Vec<String>,
}
const LOADED_COMPONENTS: &[&str] = &[
"api",
"automation",
"config",
"homecore",
"recorder",
"websocket_api",
];
pub async fn get_config(
headers: HeaderMap,
State(s): State<SharedState>,
@@ -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<SharedState>,
) -> ApiResult<Json<Vec<String>>> {
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)]