This commit is contained in:
Mateusz Gruszczyński
2026-09-16 11:09:38 +02:00
parent 0437ef7b6f
commit 0d73844f23
17 changed files with 147 additions and 54 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ async fn export_configuration(
fn validate_configuration_header(export: &ConfigurationExport) -> Result<(), AppError> {
if export.format_version != 3 {
return Err(AppError::BadRequest("unsupported configuration export version; version 3 is required by GREE Controller 0.14.8".into()));
return Err(AppError::BadRequest("unsupported configuration export version; version 3 is required by GREE Controller 0.14.10".into()));
}
if export.settings.control_strategy != "setpoint" {
return Err(AppError::BadRequest(
+23
View File
@@ -19,6 +19,29 @@ mod tests {
assert_eq!(effective_sensor_stale_after_seconds(120_000, 600), 86_400);
}
#[test]
fn ha_sensor_log_message_identifies_sensor_and_zone() {
let message = home_assistant_sensor_log_message(
"Home Assistant sensor is stale: 3607s old (limit 3600s)",
Some("sensor.igor_temperature"),
"Igor",
);
assert_eq!(
message,
"Home Assistant sensor sensor.igor_temperature, zone Igor is stale: 3607s old (limit 3600s)"
);
let message = home_assistant_sensor_log_message(
"Home Assistant state is not a number",
Some("sensor.jan_temperature"),
"Jan",
);
assert_eq!(
message,
"Home Assistant state is not a number [sensor: sensor.jan_temperature, zone Jan]"
);
}
#[test]
fn control_plan_semantic_equality_ignores_only_generation_timestamp() {
let generated_at = Utc.with_ymd_and_hms(2026, 9, 4, 8, 0, 0).unwrap();
+31 -1
View File
@@ -176,6 +176,27 @@ async fn read_cycle_room_sensors(
.collect()
}
fn home_assistant_sensor_log_message(
error: &str,
entity_id: Option<&str>,
zone_name: &str,
) -> String {
let entity_id = entity_id.map(str::trim).filter(|value| !value.is_empty());
let zone_name = zone_name.trim();
let context = match (entity_id, zone_name.is_empty()) {
(Some(entity_id), false) => format!("{entity_id}, zone {zone_name}"),
(Some(entity_id), true) => entity_id.to_string(),
(None, false) => format!("zone {zone_name}"),
(None, true) => return error.to_string(),
};
if let Some(detail) = error.strip_prefix("Home Assistant sensor is stale:") {
format!("Home Assistant sensor {context} is stale:{detail}")
} else {
format!("{error} [sensor: {context}]")
}
}
fn refresh_zone_temperature(
state: &AppState,
settings: &RuntimeSettings,
@@ -216,12 +237,21 @@ fn refresh_zone_temperature(
} else {
"ha.sensor_error"
};
let entity_id = resolved_entity
.as_deref()
.or(zone.ha_entity_id.as_deref());
let message = home_assistant_sensor_log_message(
&err,
entity_id,
&zone.name,
);
state.log(
"warn",
kind,
&err,
&message,
json!({
"zone_id": zone.id,
"zone_name": zone.name,
"configured_entity_id": zone.ha_entity_id.as_deref(),
"resolved_entity_id": resolved_entity,
}),