We know at LEAST baseball works. Will have to test hockey at the start of the playoffs in a few days, and football later this year.
201 lines
9.9 KiB
Django/Jinja
201 lines
9.9 KiB
Django/Jinja
{% from 'formatting.jinja' import cleanup %}
|
|
|
|
{% macro sports_str(team,type) %}
|
|
{% if type == 'start' %}
|
|
{% if state_attr(team,'league') in ['NFL','NCAAF'] %}
|
|
Kickoff
|
|
{% elif state_attr(team,'league') == 'MLB' %}
|
|
First pitch
|
|
{% elif state_attr(team,'league') == 'NHL' %}
|
|
Puck drop
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro period_str(team) %}
|
|
{% if state_attr(team,'league') in ['NFL','NCAAF'] %}
|
|
quarter
|
|
{% elif state_attr(team,'league') == 'MLB' %}
|
|
inning
|
|
{% else %}
|
|
period
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_clock(team) %}
|
|
{% macro data() %}
|
|
{% set period_str = period_str(team) %}
|
|
{% set game_clock = state_attr(team,'clock') %}
|
|
{% if state_attr(team,'league') == 'MLB' %}
|
|
{% set inning_parts = game_clock.split(' ') %}
|
|
in the {{ inning_parts[0] ~ ' of the ' ~ inning_parts[1] ~ ' inning' }}
|
|
{% else %}
|
|
{% if ' - ' in game_clock %}
|
|
{% set clock_time, quarter = game_clock.split(' - ') %}
|
|
with {{ clock_time ~ ' remaining in the ' ~ quarter ~ ' ' ~ period_str }}
|
|
{% else %}
|
|
with {{ game_clock ~ ' remaining in the ' ~ period_str }}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
{{ cleanup(data()) }}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_pregame(team) %}
|
|
{% macro data() %}
|
|
{% if state_attr(team,'opponent_name') %}
|
|
{% set opponent_name = state_attr(team, 'opponent_name') %}
|
|
{% if opponent_name.endswith(' St') %}
|
|
{% set opponent_name = opponent_name | replace(' St', ' State') %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ opponent_name }} at {{ state_attr(team,'venue') }}.
|
|
{{ sports_str(team,'start') }} is at {{ state_attr(team,'date') | as_timestamp | timestamp_custom('%I:%M %p') }}.
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
{{ cleanup(data()) }}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_main(team) %}
|
|
{% macro data() %}
|
|
{% if state_attr(team,'opponent_name') %}
|
|
{% set opponent_name = state_attr(team, 'opponent_name') %}
|
|
{% if opponent_name.endswith(' St') %}
|
|
{% set opponent_name = opponent_name | replace(' St', ' State') %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ 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 %}
|
|
{% 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ opponent_name }} with a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }} {{ sports_clock(team) }}.
|
|
{% 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 {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ opponent_name }} with a score of {{ state_attr(team,'team_score') }} to {{ state_attr(team,'opponent_score') }} {{ sports_clock(team) }}.
|
|
{% else %}
|
|
The {{ state_attr(team,'friendly_name') }} are currently losing their game against {% if state_attr(team,'league') != 'NCAAF'%}the{% endif %} {{ opponent_name }} with a score of {{ state_attr(team,'opponent_score') }} to {{ state_attr(team,'team_score') }} {{ sports_clock(team) }}.
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
{{ cleanup(data()) }}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_inhibit(team) %}
|
|
{% if is_state(team,'NOT_FOUND') %}
|
|
true
|
|
{% elif state_attr(team,'kickoff_in') %}
|
|
{{ 'months' in state_attr(team,'kickoff_in') or
|
|
'month' in state_attr(team,'kickoff_in') or
|
|
'weeks' in state_attr(team,'kickoff_in') }}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_today(team) %}
|
|
{% if states(team) != 'NOT_FOUND' %}
|
|
{% set date = state_attr(team,'date') | as_timestamp | timestamp_custom('%m-%d') %}
|
|
{% else %}
|
|
{% set date = 'none' %}
|
|
{% endif %}
|
|
{% if date == now().strftime('%m-%d') %}
|
|
{{ states(team) in ['PRE','IN'] }}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_updates(time) %}
|
|
{% macro data() %}
|
|
{% if time == 'pregame' %}
|
|
{% if is_state('binary_sensor.michigan_wolverines_inhibit','off') %}
|
|
{{ sports_pregame('sensor.michigan_wolverines') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.ohio_state_buckeyes_inhibit','off') %}
|
|
{{ sports_pregame('sensor.ohio_state_buckeyes') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.toledo_rockets_inhibit','off') %}
|
|
{{ sports_pregame('sensor.toledo_rockets') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.minnesota_vikings_inhibit','off') %}
|
|
{{ sports_pregame('sensor.minnesota_vikings') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.san_francisco_49ers_inhibit','off') %}
|
|
{{ sports_pregame('sensor.san_francisco_49ers') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.minnesota_twins_inhibit','off') %}
|
|
{{ sports_pregame('sensor.minnesota_twins') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.cleveland_guardians_inhibit','off') %}
|
|
{{ sports_pregame('sensor.cleveland_guardians') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.los_angeles_dodgers_inhibit','off') %}
|
|
{{ sports_pregame('sensor.los_angeles_dodgers') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.minnesota_wild_inhibit','off') %}
|
|
{{ sports_pregame('sensor.minnesota_wild') }}
|
|
{% endif %}
|
|
{% elif time == 'main' %}
|
|
{% if is_state('binary_sensor.michigan_wolverines_inhibit','off') %}
|
|
{{ sports_main('sensor.michigan_wolverines') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.ohio_state_buckeyes_inhibit','off') %}
|
|
{{ sports_main('sensor.ohio_state_buckeyes') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.toledo_rockets_inhibit','off') %}
|
|
{{ sports_main('sensor.toledo_rockets') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.minnesota_vikings_inhibit','off') %}
|
|
{{ sports_main('sensor.minnesota_vikings') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.san_francisco_49ers_inhibit','off') %}
|
|
{{ sports_main('sensor.san_francisco_49ers') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.minnesota_twins_inhibit','off') %}
|
|
{{ sports_main('sensor.minnesota_twins') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.cleveland_guardians_inhibit','off') %}
|
|
{{ sports_main('sensor.cleveland_guardians') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.los_angeles_dodgers_inhibit','off') %}
|
|
{{ sports_main('sensor.los_angeles_dodgers') }}
|
|
{% endif %}
|
|
{% if is_state('binary_sensor.minnesota_wild_inhibit','off') %}
|
|
{{ sports_main('sensor.minnesota_wild') }}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
{{ cleanup(data()) }}
|
|
{% endmacro %}
|
|
|
|
{% macro sports_datetime(team) %}
|
|
{{ as_timestamp(state_attr(team,'date')) | timestamp_custom('%Y-%m-%d %H:%M:%S') }}
|
|
{% endmacro%}
|