This commit is contained in:
Mateusz Gruszczyński
2026-09-17 08:52:02 +02:00
parent ff4f2b60e7
commit b7846c3b9f
87 changed files with 3783 additions and 1418 deletions
+9 -10
View File
@@ -38,7 +38,9 @@ fn device_group_energy_snapshot(
EnergySourcePreference::GreeCloud => Some("gree_cloud"),
EnergySourcePreference::HomeAssistant => Some("home_assistant"),
EnergySourcePreference::Auto if group.energy_device_id.is_some() => Some("gree_cloud"),
EnergySourcePreference::Auto if group.ha_energy_entity_id.is_some() => Some("home_assistant"),
EnergySourcePreference::Auto if group.ha_energy_entity_id.is_some() => {
Some("home_assistant")
}
EnergySourcePreference::Auto => None,
};
@@ -108,10 +110,7 @@ struct BootstrapResponse {
system: SystemInfoResponse,
}
async fn health(
State(state): State<AppState>,
request: Request,
) -> Result<Json<Value>, AppError> {
async fn health(State(state): State<AppState>, request: Request) -> Result<Json<Value>, AppError> {
if home_assistant::supervisor_token_detected() {
let trusted_supervisor = request
.extensions()
@@ -176,11 +175,13 @@ async fn build_bootstrap(state: &AppState) -> Result<BootstrapResponse, AppError
}
fn build_system_info(state: &AppState, devices: &[Device]) -> SystemInfoResponse {
let (received_frames_total, received_frames_by_device) = state.providers.local().client().received_frame_stats();
let (received_frames_total, received_frames_by_device) =
state.providers.local().client().received_frame_stats();
SystemInfoResponse {
version: env!("CARGO_PKG_VERSION"),
uptime_seconds: state.started.elapsed().as_secs(),
auth_required: !state.config.app_token.trim().is_empty() || home_assistant::supervisor_token_detected(),
auth_required: !state.config.app_token.trim().is_empty()
|| home_assistant::supervisor_token_detected(),
control_ready: state.initial_device_sync_complete.load(Ordering::Acquire),
database: state.config.database.display().to_string(),
device_count: devices.len(),
@@ -203,9 +204,7 @@ fn build_system_info(state: &AppState, devices: &[Device]) -> SystemInfoResponse
}
}
async fn system_info(
State(state): State<AppState>,
) -> Result<Json<SystemInfoResponse>, AppError> {
async fn system_info(State(state): State<AppState>) -> Result<Json<SystemInfoResponse>, AppError> {
let devices = state.db.list_devices()?;
Ok(Json(build_system_info(&state, &devices)))
}