language: sr responses: intents: HassTimerStatus: default: | {% macro normalize_string(sentence) %} {%- set ns = namespace(is_finished=false,is_first=true,current_term = '', in_square_brackets = false, in_round_brackets = false) %} {%- for char in sentence %} {% if not ns.is_finished %} {%- if char == ' ' %} {%- set ns.is_first = true %} {%- endif %} {%- if char == '[' %} {%- set ns.in_square_brackets = true %} {%- elif char == ']' %} {%- set ns.in_square_brackets = false %} {%- elif char == '(' %} {%- set ns.in_round_brackets = true %} {%- elif char == ')' %} {%- set ns.in_round_brackets = false %} {%- elif char == '|' and not ns.in_square_brackets and not ns.in_round_brackets %} {# break is not working #} {%- set ns.is_finished = true %} {%- elif ns.in_round_brackets and ns.is_first %} {%- set ns.current_term = ns.current_term + char %} {%- set ns.is_first = false %} {%- elif not ns.in_square_brackets and not ns.in_round_brackets %} {%- set ns.current_term = ns.current_term + char %} {%- endif %} {%- endif %} {%- endfor %} {{ ns.current_term }} {% endmacro %} {% set num_timers = slots.timers | length %} {% set active_timers = slots.timers | selectattr('is_active') | list %} {% set num_active_timers = active_timers | length %} {% set paused_timers = slots.timers | rejectattr('is_active') | list %} {% set num_paused_timers = paused_timers | length %} {% set next_timer = None %} {% if num_timers == 0: %} Нема тајмера. {% elif num_active_timers == 0: %} {# No active timers #} {% if num_paused_timers == 1: %} {% set next_timer = paused_timers[0] %} Тајмер је паузиран. {% else: %} {{ num_paused_timers }} паузирани тајмери. {% endif %} {% else: %} {# At least one active timer #} {% if num_active_timers == 1: %} {% set next_timer = active_timers[0] %} {% else: %} {# Get active timer that will finish soonest #} {% set sorted_timers = active_timers | sort(attribute='total_seconds_left') %} {% set next_timer = sorted_timers[0] %} {{ num_active_timers }} активних тајмери. {% endif %} {% if num_paused_timers == 1: %} 1 паузирани тајмер. {% elif num_paused_timers > 0: %} {{ num_paused_timers }} паузирани тајмери. {% endif %} {% endif %} {% if next_timer: %} {# At least one active timer #} {% if (next_timer.rounded_hours_left == 1) and (next_timer.rounded_minutes_left > 0): %} 1 сат и {{ next_timer.rounded_minutes_left }} минута {% elif (next_timer.rounded_hours_left == 1): %} 1 сат {% elif (next_timer.rounded_hours_left > 1) and (next_timer.rounded_minutes_left > 0): %} {{ next_timer.rounded_hours_left }} сати и {{ next_timer.rounded_minutes_left }} минута {% elif (next_timer.rounded_hours_left > 1): %} {{ next_timer.rounded_hours_left }} сати {% elif (next_timer.rounded_minutes_left == 1) and (next_timer.rounded_seconds_left > 0): %} 1 минут и {{ next_timer.rounded_seconds_left }} секунди {% elif (next_timer.rounded_minutes_left == 1): %} 1 минут {% elif (next_timer.rounded_minutes_left > 1) and (next_timer.rounded_seconds_left > 0): %} {{ next_timer.rounded_minutes_left }} минута и {{ next_timer.rounded_seconds_left }} секунди {% elif (next_timer.rounded_minutes_left > 1): %} {{ next_timer.rounded_minutes_left }} минута {% elif (next_timer.rounded_seconds_left == 1): %} 1 секунд {% elif (next_timer.rounded_seconds_left > 1): %} {{ next_timer.rounded_seconds_left }} секунди {% endif %} {% if num_timers > 1: %} {# Give some extra information to disambiguate #} преостало на {% if (next_timer.start_hours > 0) and (next_timer.start_minutes > 0): %} {{ next_timer.start_hours }} сат и {{ next_timer.start_minutes }} минута {% elif (next_timer.start_hours > 0): %} {{ next_timer.start_hours }} сат {% elif (next_timer.start_minutes > 0) and (next_timer.start_seconds > 0): %} {{ next_timer.start_minutes }} минутни и {{ next_timer.start_seconds }} секунда {% elif (next_timer.start_minutes > 0): %} {{ next_timer.start_minutes }} минутни {% elif (next_timer.start_seconds > 0): %} {{ next_timer.start_seconds }} секунда {% endif %} тајмеру {% if next_timer.name: %} {{ next_timer.name }} {% elif next_timer.area: %} {% set area_name = normalize_string(next_timer.area) %} у просторији {{ area_name }} {% endif %} {% else: %} преостало. {% endif %} {% endif %}