Remove unnecessary repeated definitions of the cleanup macro

This commit is contained in:
2023-07-01 14:08:40 -04:00
parent 1c51c678e5
commit 529b24e310
16 changed files with 152 additions and 315 deletions

View File

@ -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) %}

View File

@ -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 %}

View File

@ -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) %}