This commit is contained in:
Mateusz Gruszczyński committed 2026-09-15 18:47:20 +02:00
1 parent 7ffaba6c7a
commit 3d69e74319
37 files changed
+426 -318

No files matched your search

+11 -6
View File
@@ -44,6 +44,8 @@ struct ZoneInput {
sensor_source: String,
#[serde(default)]
ha_entity_id: Option<String>,
#[serde(default)]
ha_outdoor_entity_id: Option<String>,
#[serde(default = "external_sensor_weight")]
external_sensor_weight: f64,
#[serde(default = "max_sensor_difference")]
@@ -170,11 +172,13 @@ impl ZoneInput {
&& self
.ha_entity_id
.as_deref()
.map(|value| value.trim())
.map(str::trim)
.unwrap_or("")
.is_empty()
{
return Err(AppError::BadRequest("a per-zone Home Assistant entity_id is required for external or combined temperature control".into()));
return Err(AppError::BadRequest(
"a per-zone Home Assistant room temperature entity_id is required for external or combined temperature control".into(),
));
}
Ok(())
}
@@ -205,6 +209,7 @@ impl ZoneInput {
smart_fan: self.smart_fan,
sensor_source: self.sensor_source,
ha_entity_id: self.ha_entity_id.filter(|v| !v.trim().is_empty()),
ha_outdoor_entity_id: self.ha_outdoor_entity_id.filter(|v| !v.trim().is_empty()),
external_sensor_weight: self.external_sensor_weight,
max_sensor_difference: self.max_sensor_difference,
sensor_stale_after_seconds: self.sensor_stale_after_seconds,
@@ -289,6 +294,7 @@ async fn create_zone(
) -> Result<(StatusCode, Json<Zone>), AppError> {
let _configuration_guard = state.lock_configuration_operation().await;
let _reference_guard = state.lock_automation_operation().await;
let settings = state.settings.read().await.clone();
input.validate()?;
if state.db.get_device(&input.device_id)?.is_none() {
return Err(AppError::BadRequest("zone device does not exist".into()));
@@ -299,8 +305,7 @@ async fn create_zone(
// the newly created zone without participating in the zone operation lock.
let _device_guard = state.lock_device_operation(&input.device_id).await;
let mut zone = input.into_zone(Uuid::new_v4().to_string(), Utc::now());
let settings = state.settings.read().await.clone();
canonicalize_zone_ha_entity(&mut zone, &settings.home_assistant);
canonicalize_zone_ha_entities(&mut zone, &settings.home_assistant);
state.db.save_zone(&zone)?;
state.broadcast("zone.created", serde_json::to_value(&zone)?);
state.wake_zone_control();
@@ -313,6 +318,7 @@ async fn update_zone(
) -> Result<Json<Zone>, AppError> {
let _configuration_guard = state.lock_configuration_operation().await;
let _reference_guard = state.lock_automation_operation().await;
let settings = state.settings.read().await.clone();
input.validate()?;
let _zone_guard = state.lock_zone_operation(&id).await;
let mut existing = state
@@ -409,8 +415,7 @@ async fn update_zone(
.await?;
zone.revision = existing.revision.saturating_add(1);
}
let settings = state.settings.read().await.clone();
canonicalize_zone_ha_entity(&mut zone, &settings.home_assistant);
canonicalize_zone_ha_entities(&mut zone, &settings.home_assistant);
let power_off_device = !device_changed && existing.enabled && !zone.enabled;
if power_off_device {
// Full configuration PUT and quick-control disable use the same ownership cleanup.