mirror of
https://github.com/ruvnet/RuView
synced 2026-07-28 18:21:42 +00:00
feat(homecore-api): expose loaded components
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user