pippyn / Home-Assistant-Sensor-Afvalbeheer

Provides Home Assistant sensors for multiple Dutch and Belgium waste collectors
Apache License 2.0
272 stars 85 forks source link

Question about function next upcoming event #464

Closed rgerbranda closed 6 months ago

rgerbranda commented 6 months ago

Hi,

During testing and evaluation of the code, I saw that the following function is called twice at the same time. I was wondering why. I tried to find the initiator.

    def event(self) -> Optional[CalendarEvent]:
        """Return the next upcoming event."""
        _LOGGER.debug('event update') # added for testing purposes
        if len(self.WasteData.collections) > 0:
            waste_item = self.WasteData.collections.get_sorted()[0]
            return CalendarEvent(
                summary=waste_item.waste_type,
                start=waste_item.date.date(),
                end=(waste_item.date + timedelta(days=1)).date(),
            )

Log:

2024-02-15 11:40:38.062 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:40:38.062 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:41:38.063 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:41:38.063 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:42:38.066 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:42:38.066 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:43:38.067 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
2024-02-15 11:43:38.068 DEBUG (MainThread) [custom_components.afvalbeheer.calendar] event update
pippyn commented 6 months ago

Interesting. I'm not sure. I'll have a look

pippyn commented 6 months ago

This must be caused by the Home Assistant Calendar entity code. But I haven't found the culprit yet. Have a look at the code if you're interested: https://github.com/home-assistant/core/blob/dev/homeassistant/components/calendar/__init__.py

rgerbranda commented 6 months ago

I found out why. At first the 'state_attributes' are requested and than the 'state' itself.

file '/usr/src/homeassistant/homeassistant/components/calendar/__init__.py', line 506, code state_attributes file '/usr/src/homeassistant/homeassistant/components/calendar/__init__.py', line 522, code state