From 529b24e31030081e3d8f3e2e78255967f8265758 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sat, 1 Jul 2023 14:08:40 -0400 Subject: [PATCH] Remove unnecessary repeated definitions of the cleanup macro --- custom_templates/sports.jinja | 92 ++++++++------- custom_templates/status.jinja | 106 ++++++++++-------- custom_templates/weather.jinja | 6 +- node-red/projects/NerdFlows | 2 +- packages/custom_weather.yaml | 91 +++------------ packages/notify.yaml | 9 +- packages/school.yaml | 13 +-- templates/speech/birthdays.yaml | 16 +-- templates/speech/daily_briefing.yaml | 17 +-- templates/speech/kallen_morning_briefing.yaml | 16 +-- templates/speech/kallen_nightly_briefing.yaml | 17 +-- templates/speech/kallen_school_status.yaml | 16 +-- templates/speech/morning_briefing.yaml | 17 +-- templates/speech/nightly_briefing.yaml | 16 +-- templates/speech/weather_briefing_full.yaml | 17 +-- templates/speech/welcome_home.yaml | 16 +-- 16 files changed, 152 insertions(+), 315 deletions(-) diff --git a/custom_templates/sports.jinja b/custom_templates/sports.jinja index fa09b4e..25a8f5f 100644 --- a/custom_templates/sports.jinja +++ b/custom_templates/sports.jinja @@ -1,53 +1,61 @@ +{% from 'formatting.jinja' import cleanup %} + {% macro sports_pregame(team) %} -{% if is_state(team,'PRE') %} - {% set date = state_attr(team,'date') | as_timestamp | timestamp_custom('%m-%d') %} - {% if date == now().strftime('%m-%d') %} - "The {{ state_attr(team,'friendly_name') }} will be playing today against the {{ state_attr(team,'opponent_name') }} at {{ state_attr(team,'venue') }}. " - "Start time is at {{ state_attr(team,'date') | as_timestamp | timestamp_custom('%I:%M %p') }}. " + {% macro data() %} + {% if is_state(team,'PRE') %} + {% set date = state_attr(team,'date') | as_timestamp | timestamp_custom('%m-%d') %} + {% if date == now().strftime('%m-%d') %} + The {{ state_attr(team,'friendly_name') }} will be playing today against the {{ state_attr(team,'opponent_name') }} at {{ state_attr(team,'venue') }}. + Start time is at {{ state_attr(team,'date') | as_timestamp | timestamp_custom('%I:%M %p') }}. + {% endif %} {% endif %} -{% endif %} + {% endmacro%} +{{ cleanup(data()) }} {% endmacro %} {% macro sports_main(team) %} -{% if is_state(team,'POST') %} - {% set date = state_attr(team,'date') | as_timestamp | timestamp_custom('%m-%d') %} - {% set yday = (as_timestamp(now()) - (24*3600)) | timestamp_custom('%m-%d') %} - {% if date == now().strftime('%m-%d') %} - {% if state_attr(team,'clock') in ['postponed','Postponed'] %} - "The {{ state_attr(team,'friendly_name') }} had their game postponed today, and it will be played at a later date. " - {% elif (state_attr(team,'team_score') | int) == state_attr(team,'opponent_score') | int %} - "The {{ state_attr(team,'friendly_name') }} tied in their game today against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. " - {% elif state_attr(team,'team_winner') == true %} - "The {{ state_attr(team,'friendly_name') }} won their game today against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. " - {% elif state_attr(team,'opponent_winner') == true %} - "The {{ state_attr(team,'friendly_name') }} lost their game today against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }}. " + {% macro data() %} + {% if is_state(team,'POST') %} + {% set date = state_attr(team,'date') | as_timestamp | timestamp_custom('%m-%d') %} + {% set yday = (as_timestamp(now()) - (24*3600)) | timestamp_custom('%m-%d') %} + {% if date == now().strftime('%m-%d') %} + {% if state_attr(team,'clock') in ['postponed','Postponed'] %} + The {{ state_attr(team,'friendly_name') }} had their game postponed today, and it will be played at a later date. + {% elif (state_attr(team,'team_score') | int) == state_attr(team,'opponent_score') | int %} + The {{ state_attr(team,'friendly_name') }} tied in their game today against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. + {% elif state_attr(team,'team_winner') == true %} + The {{ state_attr(team,'friendly_name') }} won their game today against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. + {% elif state_attr(team,'opponent_winner') == true %} + The {{ state_attr(team,'friendly_name') }} lost their game today against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }}. + {% endif %} + {% if state_attr(team,'clock') not in ['postponed','Postponed'] %} + This brings their record to {{ state_attr(team,'team_record') | replace("-"," and ") }} on the season. + {% endif %} + {% elif yday == date %} + {% if state_attr(team,'clock') in ['postponed','Postponed'] %} + The {{ state_attr(team,'friendly_name') }} had their game postponed yesterday, and it will be played at a later date. + {% elif (state_attr(team,'team_score') | int) == state_attr(team,'opponent_score') | int %} + The {{ state_attr(team,'friendly_name') }} tied in their game yesterday against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. + {% elif state_attr(team,'team_winner') == true %} + The {{ state_attr(team,'friendly_name') }} won their game yesterday against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. + {% elif state_attr(team,'opponent_winner') == true %} + The {{ state_attr(team,'friendly_name') }} lost their game yesterday against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }}. + {% endif %} + {% if state_attr(team,'clock') not in ['postponed','Postponed'] %} + This brings their record to {{ state_attr(team,'team_record') | replace("-"," and ") }} on the season. + {% endif %} {% endif %} - {% if state_attr(team,'clock') not in ['postponed','Postponed'] %} - "This brings their record to {{ state_attr(team,'team_record') | replace("-"," and ") }} on the season. " - {% endif %} - {% elif yday == date %} - {% if state_attr(team,'clock') in ['postponed','Postponed'] %} - "The {{ state_attr(team,'friendly_name') }} had their game postponed yesterday, and it will be played at a later date. " - {% elif (state_attr(team,'team_score') | int) == state_attr(team,'opponent_score') | int %} - "The {{ state_attr(team,'friendly_name') }} tied in their game yesterday against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. " - {% elif state_attr(team,'team_winner') == true %} - "The {{ state_attr(team,'friendly_name') }} won their game yesterday against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. " - {% elif state_attr(team,'opponent_winner') == true %} - "The {{ state_attr(team,'friendly_name') }} lost their game yesterday against the {{ state_attr(team,'opponent_name') }} by a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }}. " - {% endif %} - {% if state_attr(team,'clock') not in ['postponed','Postponed'] %} - "This brings their record to {{ state_attr(team,'team_record') | replace("-"," and ") }} on the season. " + {% elif is_state(team,'IN') %} + {% if (state_attr(team,'team_score') | int) == (state_attr(team,'opponent_score') | int) %} + The {{ state_attr(team,'friendly_name') }} are currently tied in their game against the {{ state_attr(team,'opponent_name') }} with a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. + {% elif (state_attr(team,'team_score') | int) > (state_attr(team,'opponent_score') | int) %} + The {{ state_attr(team,'friendly_name') }} are currently winning their game against the {{ state_attr(team,'opponent_name') }} with a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. + {% else %} + The {{ state_attr(team,'friendly_name') }} are currently losing their game against the {{ state_attr(team,'opponent_name') }} with a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }}. {% endif %} {% endif %} -{% elif is_state(team,'IN') %} - {% if (state_attr(team,'team_score') | int) == (state_attr(team,'opponent_score') | int) %} - "The {{ state_attr(team,'friendly_name') }} are currently tied in their game against the {{ state_attr(team,'opponent_name') }} with a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. " - {% elif (state_attr(team,'team_score') | int) > (state_attr(team,'opponent_score') | int) %} - "The {{ state_attr(team,'friendly_name') }} are currently winning their game against the {{ state_attr(team,'opponent_name') }} with a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }}. " - {% else %} - "The {{ state_attr(team,'friendly_name') }} are currently losing their game against the {{ state_attr(team,'opponent_name') }} with a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }}. " - {% endif %} -{% endif %} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} {% macro sports_inhibit(team) %} diff --git a/custom_templates/status.jinja b/custom_templates/status.jinja index 9b5aeee..abaa4ff 100644 --- a/custom_templates/status.jinja +++ b/custom_templates/status.jinja @@ -1,3 +1,4 @@ +{% from 'formatting.jinja' import cleanup %} {% from 'time.jinja' import input_datetime_read, ct, next_twitch_stream, calendar_event_today, time_from_calendar %} {% from 'easy_time.jinja' import count_the_days, custom_time, custom_time_between, clock %} {% from 'lighting.jinja' import lightsOn %} @@ -57,17 +58,20 @@ {% endmacro %} {% macro houseStatusReport(type,method) %} -{% if type == 'climate_devices' %} -{{ climateDevices(type,method) }} -{% elif type == 'airleaks' %} -{{ airLeaks(type,method) }} -{% elif type == 'lights' %} -{{ lightsOn(type,method) }} -{% elif type == 'full' %} -{{ climateDevices(type,method) }} -{{ lightsOn(type,method) }} -{{ airLeaks(type,method) }} -{% endif %} + {% macro data() %} + {% if type == 'climate_devices' %} + {{ climateDevices(type,method) }} + {% elif type == 'airleaks' %} + {{ airLeaks(type,method) }} + {% elif type == 'lights' %} + {{ lightsOn(type,method) }} + {% elif type == 'full' %} + {{ climateDevices(type,method) }} + {{ lightsOn(type,method) }} + {{ airLeaks(type,method) }} + {% endif %} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} {% macro twitchStreamInfo(type,method) %} @@ -147,16 +151,19 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% endmacro %} {% macro tonyStatusReport(type,method) %} -{% if type == 'meds' %} -{{ medReportTony(type,method) }} -{% endif %} -{% if type == 'stream' %} -{{ twitchStreamInfo(type,method) }} -{% endif %} -{% if type == 'full' %} -{{ twitchStreamInfo(type,method) }} -{{ medReportTony(type,method) }} -{% endif %} + {% macro data() %} + {% if type == 'meds' %} + {{ medReportTony(type,method) }} + {% endif %} + {% if type == 'stream' %} + {{ twitchStreamInfo(type,method) }} + {% endif %} + {% if type == 'full' %} + {{ twitchStreamInfo(type,method) }} + {{ medReportTony(type,method) }} + {% endif %} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} {% macro tina_morning_meds(type,method) %} @@ -268,14 +275,17 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% endmacro %} {% macro tinaStatusReport(type,method) %} -{% if type == 'work' %} -{{ workReportTina(type,method) }} -{% elif type == 'meds' %} -{{ medReportTina(type,method) }} -{% elif type == 'full' %} -{{ workReportTina(type,method) }} -{{ medReportTina(type,method) }} -{% endif %} + {% macro data() %} + {% if type == 'work' %} + {{ workReportTina(type,method) }} + {% elif type == 'meds' %} + {{ medReportTina(type,method) }} + {% elif type == 'full' %} + {{ workReportTina(type,method) }} + {{ medReportTina(type,method) }} + {% endif %} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} {% macro kallen_morning_meds(type,method) %} @@ -447,17 +457,20 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% endmacro %} {% macro kallenStatusReport(type,method) %} -{% if type == 'meds' %} -{{ medReportKallen(type,method) }} -{% elif type == 'school' %} -{{ schoolReportKallen(type,method) }} -{% elif type == 'sleep' %} -{{ kallenSleep(type,method)}} -{% elif type == 'full' %} -{{ kallenSleep(type,method) }} -{{ medReportKallen(type,method) }} -{{ schoolReportKallen(type,method) }} -{% endif %} + {% macro data() %} + {% if type == 'meds' %} + {{ medReportKallen(type,method) }} + {% elif type == 'school' %} + {{ schoolReportKallen(type,method) }} + {% elif type == 'sleep' %} + {{ kallenSleep(type,method)}} + {% elif type == 'full' %} + {{ kallenSleep(type,method) }} + {{ medReportKallen(type,method) }} + {{ schoolReportKallen(type,method) }} + {% endif %} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} {% macro emma_sleep(type,method) %} @@ -501,9 +514,12 @@ Tony is currently streaming. The current stream category is {{ game }}. The curr {% endmacro %} {% macro emmaStatusReport(type,method) %} -{% if type == 'sleep' %} -{{ emma_sleep(type,method) }} -{% elif type == 'full' %} -{{ emma_sleep(type,method) }} -{% endif %} + {% macro data() %} + {% if type == 'sleep' %} + {{ emma_sleep(type,method) }} + {% elif type == 'full' %} + {{ emma_sleep(type,method) }} + {% endif %} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} \ No newline at end of file diff --git a/custom_templates/weather.jinja b/custom_templates/weather.jinja index e022a5d..489470f 100644 --- a/custom_templates/weather.jinja +++ b/custom_templates/weather.jinja @@ -1,3 +1,4 @@ +{% from 'formatting.jinja' import cleanup %} {% from 'time.jinja' import ct %} {% set ct = ct() | int %} @@ -82,7 +83,10 @@ {% endmacro %} {% macro weatherReport(type,method,time) %} -{{ weatherInfo(type,method,time) | replace('clear-night','clear') | replace('partlycloudy','partly cloudy') }} + {% macro data() %} + {{ weatherInfo(type,method,time) | replace('clear-night','clear') | replace('partlycloudy','partly cloudy') }} + {% endmacro %} +{{ cleanup(data()) }} {% endmacro %} {% macro tempConvert(temp,unitFrom,unitTo) %} diff --git a/node-red/projects/NerdFlows b/node-red/projects/NerdFlows index c8568f4..4985b28 160000 --- a/node-red/projects/NerdFlows +++ b/node-red/projects/NerdFlows @@ -1 +1 @@ -Subproject commit c8568f46e3b85911c341f33b453a75c7d63e3d1d +Subproject commit 4985b28f0f806dbdb4d2e62e6de5bbc2f780079c diff --git a/packages/custom_weather.yaml b/packages/custom_weather.yaml index 3fb832e..5e662b5 100644 --- a/packages/custom_weather.yaml +++ b/packages/custom_weather.yaml @@ -207,6 +207,7 @@ sensor: unique_id: e5ae9864-70b5-402c-9d2f-c4d6a10085df icon_template: mdi:weather-sunny value_template: >- + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} {{ [ 'Today in Defiance ', @@ -310,18 +311,7 @@ sensor: ] | random }} {{ states('sensor.overnight_lowest_temperature') }} degrees. {%- endmacro -%} - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} tomorrow_forecast: friendly_name: Tomorrows Forecast unique_id: a8ae26b0-ed26-4568-bb2b-f7c72707b009 @@ -350,6 +340,7 @@ sensor: unique_id: 21374ed0-80d1-49ba-817d-3e93eb3865e4 icon_template: mdi:weather-sunny value_template: >- + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} {{ [ 'Tomorrow in Defiance ', @@ -442,23 +433,13 @@ sensor: ] | random }} {{ state_attr('sensor.tomorrow_forecast','overnight_low') }} degrees. {%- endmacro -%} - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} current_conditions: friendly_name: Current Conditions unique_id: 70db7e57-08db-48b2-919b-03b5face37b9 icon_template: mdi:weather-sunny value_template: >- + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} The Weather in Defiance {{ [ @@ -498,23 +479,13 @@ sensor: and {{ states.weather.iron_nerd_weather_station.state }} {% endif %} {%- endmacro -%} - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} current_conditions_detail: friendly_name: Current Conditions Detail unique_id: 2b3687d1-bdd5-4551-8c0a-05b1ff617543 icon_template: mdi:weather-sunny value_template: >- + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} The Weather in Defiance {{ [ @@ -660,18 +631,7 @@ sensor: {{ states('sensor.overnight_lowest_temperature') }} degrees. {% endif %} {%- endmacro -%} - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} outside_pressure: friendly_name: 'Outside Pressure' unique_id: ac2944bb-e9d7-40a3-9707-ef477fd5f309 @@ -725,6 +685,7 @@ sensor: friendly_name: "Clothing Forecast Detail" unique_id: 13065f50-5eef-4afd-830e-2a2c87f47496 value_template: >- + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} {% if is_state('binary_sensor.morning','on') %} Based on the forecasted high temperature, @@ -874,19 +835,7 @@ sensor: "The possibility of frost exists currently. Be prepared. " {% endif %} {%- endmacro -%} - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} # current_inside_humidity: # friendly_name: "Current Inside Humidity" @@ -905,6 +854,7 @@ sensor: friendly_name: Weather Alert String unique_id: 66b5f020-0b5e-48ed-92a2-740d2d708b30 value_template: > + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} {% set alerts = [ states('sensor.weatheralerts_alert_1_most_recent_active_alert'), @@ -925,14 +875,7 @@ sensor: 'None' {% endif %} {%- endmacro -%} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} attribute_templates: active_alerts: "{{ states('sensor.weatheralerts_active_alerts') }}" icon_template: > @@ -945,6 +888,7 @@ sensor: friendly_name: 'Weather Alerts Active - Corrected' unique_id: e2f51da4-2271-4719-8edf-a28f76ac1e3f value_template: > + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} {% set alerts = [ states('sensor.weatheralerts_alert_1_most_recent_active_alert'), @@ -958,14 +902,7 @@ sensor: {% set flood1 = 1 if (flood > 0) else 0 %} {{ (main + flood1) | int }} {%- endmacro -%} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} icon_template: > {% if (states('sensor.weatheralerts_active_alerts') | int ) > 0 %} mdi:alert diff --git a/packages/notify.yaml b/packages/notify.yaml index 98b1adf..7d40363 100644 --- a/packages/notify.yaml +++ b/packages/notify.yaml @@ -1489,6 +1489,7 @@ script: data: who: '{{ who }}' message: >- + {% from 'formatting.jinja' import cleanup %} {% macro greeting() %}

{% if now().strftime('%H')|int < 12%} @@ -1783,14 +1784,6 @@ script: ] | random }} {% endmacro %} - - {# a macro that removes all newline characters, empty spaces, and returns formatted text. Also replaces all Underscores with Spaces #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim | replace("_", " ") }} {% endfor -%} - {%- endmacro -%} - - {# ********************************************* #} {# ******** Start the Speech routines ******** #} {# ********************************************* #} diff --git a/packages/school.yaml b/packages/school.yaml index 5212014..60f76ad 100644 --- a/packages/school.yaml +++ b/packages/school.yaml @@ -177,6 +177,7 @@ sensor: mdi:calendar-end {% endif %} value_template: > + {% from 'formatting.jinja' import cleanup %} {%- macro getReport() -%} {% set week = states('sensor.kallen_lunch_menu_week') %} {% set dow = now().strftime('%A') %} @@ -232,17 +233,7 @@ sensor: No menu for the current day. {% endif %} {%- endmacro -%} - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} + {{- cleanup(getReport()) -}} # - platform: rest diff --git a/templates/speech/birthdays.yaml b/templates/speech/birthdays.yaml index 9c9b5e6..5717d83 100644 --- a/templates/speech/birthdays.yaml +++ b/templates/speech/birthdays.yaml @@ -1,6 +1,7 @@ > {# Birthdays #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %}

{{ [ 'Attention household, I am told that there is a birthday among us!', @@ -27,17 +28,4 @@

{%- endmacro -%} - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/daily_briefing.yaml b/templates/speech/daily_briefing.yaml index e8305ec..f7a1d56 100644 --- a/templates/speech/daily_briefing.yaml +++ b/templates/speech/daily_briefing.yaml @@ -1,6 +1,7 @@ > {# Daily Briefing #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %} {% from 'status.jinja' import houseStatusReport, tonyStatusReport, tinaStatusReport, kallenStatusReport, emmaStatusReport %} {% from 'easy_time.jinja' import count_the_days %} @@ -312,18 +313,4 @@

{%- endmacro -%} - - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/kallen_morning_briefing.yaml b/templates/speech/kallen_morning_briefing.yaml index 479ef10..1941111 100644 --- a/templates/speech/kallen_morning_briefing.yaml +++ b/templates/speech/kallen_morning_briefing.yaml @@ -1,6 +1,7 @@ > {# Kallen Morning Briefing #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'time.jinja' import current_time, current_date_readout, input_datetime_read %} {% from 'speech.jinja' import dadjoke, inspirational_quote %} {% from 'easy_time.jinja' import count_the_days, custom_time %} @@ -191,17 +192,4 @@

{%- endmacro -%} - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/kallen_nightly_briefing.yaml b/templates/speech/kallen_nightly_briefing.yaml index 09e467a..bf43291 100644 --- a/templates/speech/kallen_nightly_briefing.yaml +++ b/templates/speech/kallen_nightly_briefing.yaml @@ -1,6 +1,7 @@ > {# Kallen Nightly Briefing #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'speech.jinja' import dadjoke %} {% from 'easy_time.jinja' import count_the_days, custom_time %}

@@ -116,18 +117,4 @@

{%- endmacro -%} - - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/kallen_school_status.yaml b/templates/speech/kallen_school_status.yaml index 1a26102..dde86fc 100644 --- a/templates/speech/kallen_school_status.yaml +++ b/templates/speech/kallen_school_status.yaml @@ -1,6 +1,7 @@ > {# Kallen School Status #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'time.jinja' import input_datetime_read %}

"Hello Collin, " @@ -27,17 +28,4 @@

{%- endmacro -%} - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/morning_briefing.yaml b/templates/speech/morning_briefing.yaml index a25bea1..99d171b 100644 --- a/templates/speech/morning_briefing.yaml +++ b/templates/speech/morning_briefing.yaml @@ -1,6 +1,7 @@ > {# Morning Briefing #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'speech.jinja' import greeting_nodate, dadjoke, inspirational_quote %} {% from 'status.jinja' import tonyStatusReport, tinaStatusReport, kallenStatusReport, emmaStatusReport %} {% from 'easy_time.jinja' import count_the_days %} @@ -187,18 +188,4 @@

{%- endmacro -%} - - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/nightly_briefing.yaml b/templates/speech/nightly_briefing.yaml index edd7ec5..198a23b 100644 --- a/templates/speech/nightly_briefing.yaml +++ b/templates/speech/nightly_briefing.yaml @@ -1,6 +1,7 @@ > {# Nightly Briefing #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %} {% from 'time.jinja' import input_datetime_read, time_from_calendar, next_twitch_stream %} {% from 'status.jinja' import tonyStatusReport, tinaStatusReport, kallenStatusReport, emmaStatusReport %} @@ -230,17 +231,4 @@

{%- endmacro -%} - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/weather_briefing_full.yaml b/templates/speech/weather_briefing_full.yaml index 04ff65b..f252789 100644 --- a/templates/speech/weather_briefing_full.yaml +++ b/templates/speech/weather_briefing_full.yaml @@ -1,6 +1,7 @@ > {# Weather Briefing #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %}

{% if is_state('input_boolean.tornado_alarm','on') %} @@ -52,18 +53,4 @@

{%- endmacro -%} - - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file diff --git a/templates/speech/welcome_home.yaml b/templates/speech/welcome_home.yaml index b7b10bc..040f7f1 100644 --- a/templates/speech/welcome_home.yaml +++ b/templates/speech/welcome_home.yaml @@ -1,6 +1,7 @@ > {# Welcome Home #} {%- macro getReport() -%} + {% from 'formatting.jinja' import cleanup %} {% from 'speech.jinja' import dadjoke %} {% from 'time.jinja' import input_datetime_read %} {% from 'status.jinja' import emma_sleep %} @@ -174,17 +175,4 @@

{%- endmacro -%} - - {# a macro that removes all newline characters, empty spaces, and returns formatted text #} - {%- macro cleanup(data) -%} - {%- for item in data.split("\n") if item | trim != "" -%} - {{ item | trim }} {% endfor -%} - {%- endmacro -%} - - {# a macro to call all macros :) #} - {%- macro mother_of_all_macros() -%} - {{ getReport() }} - {%- endmacro -%} - - {# Call the macro #} - {{- cleanup(mother_of_all_macros()) -}} \ No newline at end of file + {{- cleanup(getReport()) -}} \ No newline at end of file