fix: harden Washing Machine remaining-time parsing for unavailable states
Treat 'unavailable'/'none'/'-'/'' remaining-time values as not-running and parse with int(0) defaults so a partially invalid sensor value degrades to 0 instead of raising. Bump manifest to 2.14.1.
This commit is contained in:
@@ -553,15 +553,17 @@ variables:
|
|||||||
and run_state not in non_running_state_ids
|
and run_state not in non_running_state_ids
|
||||||
and run_state != preparation_state_id
|
and run_state != preparation_state_id
|
||||||
and run_state != run_state_completion_id
|
and run_state != run_state_completion_id
|
||||||
and remaining not in ['unknown', 'unavailable'] }}
|
and (remaining | string | trim) not in ['unknown', 'unavailable', 'none', '-', ''] }}
|
||||||
|
|
||||||
# Parse remaining time string (hh:mm:ss) to total minutes
|
# Parse remaining time string (hh:mm:ss) to total minutes.
|
||||||
|
# Use int(0) defaults so a partially invalid sensor value (e.g.
|
||||||
|
# 'unavailable:00:00') degrades to 0 instead of raising.
|
||||||
remaining_time_in_minutes: >
|
remaining_time_in_minutes: >
|
||||||
{% if remaining not in ['unknown', 'unavailable', '-'] %}
|
{% set r = remaining | string | trim %}
|
||||||
{% set parts = remaining.split(':') %}
|
{% if r not in ['unknown', 'unavailable', 'none', '-', ''] %}
|
||||||
|
{% set parts = r.split(':') %}
|
||||||
{% if parts | length >= 2 %}
|
{% if parts | length >= 2 %}
|
||||||
{% set total = parts[0]|int * 60 + parts[1]|int %}
|
{{ parts[0] | int(0) * 60 + parts[1] | int(0) }}
|
||||||
{{ total }}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ 0 }}
|
{{ 0 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -571,11 +573,12 @@ variables:
|
|||||||
|
|
||||||
# Calculate estimated end time from remaining time
|
# Calculate estimated end time from remaining time
|
||||||
estimated_end_time: >
|
estimated_end_time: >
|
||||||
{% if remaining not in ['unknown', 'unavailable', '-'] %}
|
{% set r = remaining | string | trim %}
|
||||||
{% set parts = remaining.split(':') %}
|
{% if r not in ['unknown', 'unavailable', 'none', '-', ''] %}
|
||||||
|
{% set parts = r.split(':') %}
|
||||||
{% if parts | length >= 2 %}
|
{% if parts | length >= 2 %}
|
||||||
{% set hours = parts[0] | int %}
|
{% set hours = parts[0] | int(0) %}
|
||||||
{% set minutes = parts[1] | int %}
|
{% set minutes = parts[1] | int(0) %}
|
||||||
{% set end_time = now() + timedelta(hours=hours, minutes=minutes) %}
|
{% set end_time = now() + timedelta(hours=hours, minutes=minutes) %}
|
||||||
{{ end_time.strftime('%H:%M') }}
|
{{ end_time.strftime('%H:%M') }}
|
||||||
{% else %}
|
{% else %}
|
||||||
@@ -739,7 +742,7 @@ action:
|
|||||||
value_template: >
|
value_template: >
|
||||||
{{ not is_running
|
{{ not is_running
|
||||||
and automation_state.get(state_notification_about_start_sent, false)
|
and automation_state.get(state_notification_about_start_sent, false)
|
||||||
and (states(run_state_sensor) in [run_state_completion_id, 'unknown', '-'] or states(remaining_time_sensor) in ['unknown', '-']) }}
|
and (states(run_state_sensor) in [run_state_completion_id, 'unknown', 'unavailable', '-'] or states(remaining_time_sensor) in ['unknown', 'unavailable', '-']) }}
|
||||||
sequence:
|
sequence:
|
||||||
- variables:
|
- variables:
|
||||||
# Calculate energy consumption
|
# Calculate energy consumption
|
||||||
@@ -891,7 +894,7 @@ action:
|
|||||||
|
|
||||||
- variables:
|
- variables:
|
||||||
# Calculate minutes for the template
|
# Calculate minutes for the template
|
||||||
minutes: "{{ remaining.split(':')[1] | int }}"
|
minutes: "{{ remaining.split(':')[1] | int(0) if ':' in (remaining | string) else 0 }}"
|
||||||
# Render the message template with available variables
|
# Render the message template with available variables
|
||||||
message: >
|
message: >
|
||||||
{% set tpl = message_almost_done_template %}
|
{% set tpl = message_almost_done_template %}
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"version": "2.14.0"
|
"version": "2.14.1"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user