| 1 | language: hr |
| 2 | responses: |
| 3 | intents: |
| 4 | HassTimerStatus: |
| 5 | default: | |
| 6 | {% macro normalize_string(sentence) %} |
| 7 | {%- set ns = namespace(is_finished=false,is_first=true,current_term = '', in_square_brackets = false, in_round_brackets = false) %} |
| 8 | {%- for char in sentence %} |
| 9 | {% if not ns.is_finished %} |
| 10 | {%- if char == ' ' %} |
| 11 | {%- set ns.is_first = true %} |
| 12 | {%- endif %} |
| 13 | {%- if char == '[' %} |
| 14 | {%- set ns.in_square_brackets = true %} |
| 15 | {%- elif char == ']' %} |
| 16 | {%- set ns.in_square_brackets = false %} |
| 17 | {%- elif char == '(' %} |
| 18 | {%- set ns.in_round_brackets = true %} |
| 19 | {%- elif char == ')' %} |
| 20 | {%- set ns.in_round_brackets = false %} |
| 21 | {%- elif char == '|' and not ns.in_square_brackets and not ns.in_round_brackets %} |
| 22 | {# break is not working #} |
| 23 | {%- set ns.is_finished = true %} |
| 24 | {%- elif ns.in_round_brackets and ns.is_first %} |
| 25 | {%- set ns.current_term = ns.current_term + char %} |
| 26 | {%- set ns.is_first = false %} |
| 27 | {%- elif not ns.in_square_brackets and not ns.in_round_brackets %} |
| 28 | {%- set ns.current_term = ns.current_term + char %} |
| 29 | {%- endif %} |
| 30 | {%- endif %} |
| 31 | {%- endfor %} |
| 32 | {{ ns.current_term }} |
| 33 | {% endmacro %} |
| 34 | {% set num_timers = slots.timers | length %} |
| 35 | {% set active_timers = slots.timers | selectattr('is_active') | list %} |
| 36 | {% set num_active_timers = active_timers | length %} |
| 37 | {% set paused_timers = slots.timers | rejectattr('is_active') | list %} |
| 38 | {% set num_paused_timers = paused_timers | length %} |
| 39 | {% set next_timer = None %} |
| 40 | |
| 41 | {% if num_timers == 0: %} |
| 42 | Nema timera. |
| 43 | {% elif num_active_timers == 0: %} |
| 44 | {# Nema aktivnih timera #} |
| 45 | {% if num_paused_timers == 1: %} |
| 46 | {% set next_timer = paused_timers[0] %} |
| 47 | Timer je pauziran. |
| 48 | {% else: %} |
| 49 | {{ num_paused_timers }} pauziranih timera. |
| 50 | {% endif %} |
| 51 | {% else: %} |
| 52 | {# Najmanje jedan aktivan timer #} |
| 53 | {% if num_active_timers == 1: %} |
| 54 | {% set next_timer = active_timers[0] %} |
| 55 | {% else: %} |
| 56 | {# Dohvati aktivan timer koji završava najranije #} |
| 57 | {% set sorted_timers = active_timers | sort(attribute='total_seconds_left') %} |
| 58 | {% set next_timer = sorted_timers[0] %} |
| 59 | Broj aktivnih timera: {{ num_active_timers }}. |
| 60 | {% endif %} |
| 61 | |
| 62 | {% if num_paused_timers > 0: %} |
| 63 | Broj pauziranih timera: {{ num_paused_timers }}. |
| 64 | {% endif %} |
| 65 | {% endif %} |
| 66 | |
| 67 | {% if next_timer: %} |
| 68 | {# Najmanje jedan aktivan timer #} |
| 69 | Preostalo je |
| 70 | {% if (next_timer.rounded_hours_left == 1) and (next_timer.rounded_minutes_left > 0): %} |
| 71 | 1 sat i {{ next_timer.rounded_minutes_left }} minuta |
| 72 | {% elif (next_timer.rounded_hours_left == 1): %} |
| 73 | 1 sat |
| 74 | {% elif (next_timer.rounded_hours_left > 1) and (next_timer.rounded_minutes_left > 0): %} |
| 75 | {{ next_timer.rounded_hours_left }} sata i {{ next_timer.rounded_minutes_left }} minuta |
| 76 | {% elif (next_timer.rounded_hours_left > 1): %} |
| 77 | {{ next_timer.rounded_hours_left }} sata |
| 78 | {% elif (next_timer.rounded_minutes_left == 1) and (next_timer.rounded_seconds_left > 0): %} |
| 79 | 1 minuta i {{ next_timer.rounded_seconds_left }} sekundi |
| 80 | {% elif (next_timer.rounded_minutes_left == 1): %} |
| 81 | 1 minuta |
| 82 | {% elif (next_timer.rounded_minutes_left > 1) and (next_timer.rounded_seconds_left > 0): %} |
| 83 | {{ next_timer.rounded_minutes_left }} minuta i {{ next_timer.rounded_seconds_left }} sekundi |
| 84 | {% elif (next_timer.rounded_minutes_left > 1): %} |
| 85 | {{ next_timer.rounded_minutes_left }} minuta |
| 86 | {% elif (next_timer.rounded_seconds_left == 1): %} |
| 87 | 1 sekunda |
| 88 | {% elif (next_timer.rounded_seconds_left > 1): %} |
| 89 | {{ next_timer.rounded_seconds_left }} sekundi |
| 90 | {% endif %} |
| 91 | |
| 92 | {% if num_timers > 1: %} |
| 93 | {# Dodatne informacije za razlikovanje #} |
| 94 | od |
| 95 | {% if (next_timer.start_hours > 0) and (next_timer.start_minutes > 0): %} |
| 96 | {{ next_timer.start_hours }} sat i {{ next_timer.start_minutes }} minuta |
| 97 | {% elif (next_timer.start_hours > 0): %} |
| 98 | {{ next_timer.start_hours }} sat |
| 99 | {% elif (next_timer.start_minutes > 0) and (next_timer.start_seconds > 0): %} |
| 100 | {{ next_timer.start_minutes }} minuta i {{ next_timer.start_seconds }} sekunda |
| 101 | {% elif (next_timer.start_minutes > 0): %} |
| 102 | {{ next_timer.start_minutes }} minuta |
| 103 | {% elif (next_timer.start_seconds > 0): %} |
| 104 | {{ next_timer.start_seconds }} sekunda |
| 105 | {% endif %} |
| 106 | na timeru |
| 107 | {% if next_timer.name: %} |
| 108 | {{ next_timer.name }} |
| 109 | {% elif next_timer.area: %} |
| 110 | |
| 111 | {% set area_name = normalize_string(next_timer.area) %} |
| 112 | |
| 113 | u prostoriji |
| 114 | {{ area_name }} |
| 115 | |
| 116 | {% endif %} |
| 117 | |
| 118 | {% endif %} |
| 119 | {% endif %} |