Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Enhance Calendar Entity to Support Multiple Events on the Same Day #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Wiggen94
Copy link

This pull request improves the wasteplan_trv integration by ensuring that the calendar entity correctly handles and exposes multiple events occurring on the same day. The changes include:

  1. Enhanced Event Handling:

Updated the async_get_events method to ensure all events within the specified date range are captured and returned, not just the next upcoming event.

  1. Correct Event Exposure:

Modified the _handle_coordinator_update method to properly expose the next event (or events) to the Home Assistant UI, ensuring all necessary attributes are correctly displayed.

These changes improve the usability and reliability of the integration, especially in scenarios where multiple events occur on the same day.

@Wiggen94
Copy link
Author

Wiggen94 commented Aug 27, 2024

To add to this I used a template to only expose what happens on next waste day:

{% set events = state_attr('calendar.tommeplan', 'events') %}
{% set today = now().date() %}
{% set ns = namespace(candidate_dates=[], upcoming_events=[]) %}

{# Collect all candidate dates as strings #}
{% for event in events %}
  {% set event_date_str = event.start.strftime('%Y-%m-%d') %}
  {% if event.start.date() >= today %}
    {% set ns.candidate_dates = ns.candidate_dates + [event_date_str] %}
  {% endif %}
{% endfor %}

{# Select the earliest date from candidate dates #}
{% if ns.candidate_dates | length > 0 %}
  {% set next_event_date = ns.candidate_dates | min %}
{% else %}
  {% set next_event_date = None %}
{% endif %}

{# Collect all events for the determined next event date #}
{% if next_event_date is not none %}
  {% for event in events %}
    {% set event_date_str = event.start.strftime('%Y-%m-%d') %}
    {% if event_date_str == next_event_date %}
      {% set ns.upcoming_events = ns.upcoming_events + [event.summary] %}
    {% endif %}
  {% endfor %}
{% endif %}

{# Display the events with a word or phrase between them #}
{% if ns.upcoming_events | length > 0 %}
  {{ ns.upcoming_events | join(' and ') }}
{% else %}
  <p>No upcoming events today or in the future.</p>
{% endif %}

This allowed me to create a nice badge like this:
image

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant