v0.14.4
This commit is contained in:
+17
-13
@@ -80,7 +80,6 @@ fn home_assistant_settings(settings: &RuntimeSettings) -> HomeAssistantSettingsV
|
||||
HomeAssistantSettingsView {
|
||||
url: settings.home_assistant.url.clone(),
|
||||
token_configured: !settings.home_assistant.token.trim().is_empty(),
|
||||
default_entity_id: settings.home_assistant.default_entity_id.clone(),
|
||||
outdoor_entity_id: settings.home_assistant.outdoor_entity_id.clone(),
|
||||
sensor_stale_after_seconds: settings.home_assistant.sensor_stale_after_seconds,
|
||||
allow_invalid_tls: settings.home_assistant.allow_invalid_tls,
|
||||
@@ -618,10 +617,6 @@ fn validate_flow_shared_inputs(
|
||||
}
|
||||
|
||||
fn canonicalize_home_assistant_entities(settings: &mut HomeAssistantSettings) {
|
||||
let default_entity = settings.default_entity_id.clone();
|
||||
if let Some(entity_id) = home_assistant::resolve_entity_id(settings, Some(&default_entity)) {
|
||||
settings.default_entity_id = entity_id;
|
||||
}
|
||||
let outdoor_entity = settings.outdoor_entity_id.clone();
|
||||
if !outdoor_entity.trim().is_empty() {
|
||||
if let Some(entity_id) = home_assistant::resolve_entity_id(settings, Some(&outdoor_entity))
|
||||
@@ -645,11 +640,20 @@ fn validate_home_assistant_url(settings: &HomeAssistantSettings) -> Result<(), A
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn canonicalize_zone_ha_entity(zone: &mut Zone, settings: &HomeAssistantSettings) {
|
||||
let Some(configured) = zone.ha_entity_id.clone() else {
|
||||
return;
|
||||
fn canonicalize_zone_ha_entities(zone: &mut Zone, settings: &HomeAssistantSettings) {
|
||||
let room = zone.ha_entity_id.clone().unwrap_or_default();
|
||||
zone.ha_entity_id = if room.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
home_assistant::resolve_entity_id(settings, Some(room.trim()))
|
||||
};
|
||||
|
||||
let outdoor = zone.ha_outdoor_entity_id.clone().unwrap_or_default();
|
||||
zone.ha_outdoor_entity_id = if outdoor.trim().is_empty() {
|
||||
None
|
||||
} else {
|
||||
home_assistant::resolve_entity_id(settings, Some(outdoor.trim()))
|
||||
};
|
||||
zone.ha_entity_id = home_assistant::resolve_entity_id(settings, Some(&configured));
|
||||
}
|
||||
|
||||
async fn canonicalize_saved_zone_entities(
|
||||
@@ -673,9 +677,10 @@ async fn canonicalize_saved_zone_entities(
|
||||
let Some(mut zone) = state.db.get_zone(&zone_id)? else {
|
||||
continue;
|
||||
};
|
||||
let previous = zone.ha_entity_id.clone();
|
||||
canonicalize_zone_ha_entity(&mut zone, settings);
|
||||
if zone.ha_entity_id != previous {
|
||||
let previous_room = zone.ha_entity_id.clone();
|
||||
let previous_outdoor = zone.ha_outdoor_entity_id.clone();
|
||||
canonicalize_zone_ha_entities(&mut zone, settings);
|
||||
if zone.ha_entity_id != previous_room || zone.ha_outdoor_entity_id != previous_outdoor {
|
||||
zone.updated_at = Utc::now();
|
||||
state.db.save_zone(&zone)?;
|
||||
state.broadcast("zone.updated", serde_json::to_value(&zone)?);
|
||||
@@ -691,7 +696,6 @@ fn apply_home_assistant_update(
|
||||
let mut next = HomeAssistantSettings {
|
||||
url: input.url,
|
||||
token: current.token.clone(),
|
||||
default_entity_id: input.default_entity_id,
|
||||
outdoor_entity_id: input.outdoor_entity_id,
|
||||
sensor_stale_after_seconds: input.sensor_stale_after_seconds.clamp(30, 86_400),
|
||||
allow_invalid_tls: input.allow_invalid_tls,
|
||||
|
||||
Reference in New Issue
Block a user