v0.9.7
This commit is contained in:
@@ -43,6 +43,7 @@ async fn update_settings(State(state): State<AppState>, Json(mut input): Json<Ru
|
||||
let compressor_settings_changed = input.compressor_protection_enabled != old.compressor_protection_enabled
|
||||
|| input.compressor_protection_seconds != old.compressor_protection_seconds;
|
||||
normalize_sensor_aliases(&mut input);
|
||||
validate_flow_shared_inputs(&mut input, &state)?;
|
||||
canonicalize_home_assistant_entities(&mut input);
|
||||
validate_night_mode(&mut input)?;
|
||||
input.influxdb.history_threshold_days = input.influxdb.history_threshold_days.clamp(1, 3650);
|
||||
@@ -97,6 +98,39 @@ fn normalize_sensor_aliases(settings: &mut RuntimeSettings) {
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn validate_flow_shared_inputs(settings: &mut RuntimeSettings, state: &AppState) -> Result<(), AppError> {
|
||||
let mut ids = std::collections::HashSet::new();
|
||||
if settings.home_assistant.flow_inputs.len() > 128 {
|
||||
return Err(AppError::BadRequest("too many shared Flow inputs (max 128)".into()));
|
||||
}
|
||||
for item in &mut settings.home_assistant.flow_inputs {
|
||||
item.id = item.id.trim().chars().take(120).collect();
|
||||
item.name = item.name.trim().chars().take(100).collect();
|
||||
item.kind = item.kind.trim().to_string();
|
||||
if item.id.is_empty() || item.name.is_empty() {
|
||||
return Err(AppError::BadRequest("shared Flow input requires id and name".into()));
|
||||
}
|
||||
if !ids.insert(item.id.clone()) {
|
||||
return Err(AppError::BadRequest("shared Flow input IDs must be unique".into()));
|
||||
}
|
||||
if !matches!(item.kind.as_str(),
|
||||
"outdoor_temperature" | "device_temperature" | "zone_temperature" |
|
||||
"ha_state" | "ha_numeric" | "ha_attribute" | "ha_available" |
|
||||
"house_mode" | "device_state" | "zone_state" | "group_state" |
|
||||
"night_mode" | "constant") {
|
||||
return Err(AppError::BadRequest(format!("unsupported shared Flow input kind: {}", item.kind)));
|
||||
}
|
||||
let condition = crate::models::FlowCondition {
|
||||
id: item.id.clone(),
|
||||
kind: item.kind.clone(),
|
||||
config: item.config.clone(),
|
||||
inputs: Vec::new(),
|
||||
};
|
||||
validate_condition(&condition, state)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn canonicalize_home_assistant_entities(settings: &mut RuntimeSettings) {
|
||||
let default_entity = settings.home_assistant.default_entity_id.clone();
|
||||
if let Some(entity_id) = home_assistant::resolve_entity_id(&settings.home_assistant, Some(&default_entity)) {
|
||||
|
||||
Reference in New Issue
Block a user