Skip to content

Sensor Update Fails with IndexError #27

@ABeard89

Description

@ABeard89

I set up my feeding times using Home Assistant Automations because I need finer control over the feeding times than the PetSafe app lets me (it only lets me set feeding times on 15-minute increments (XX:00, XX:15, XX:30, and XX:45)).

Because I am using Automations for meal times, I don't have any meal times set up in the PetSafe app. The Integration seems to make the assumption that at least one meal time will be configured, which is flooding my log file with IndexError messages.

2025-06-21 11:11:30.106 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.next_feeding fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 956, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1304, in async_device_update
    await self.async_update()
  File "/config/custom_components/petsafe/SensorEntities.py", line 244, in async_update
    self._attr_native_value = self._get_next_feeding_time(schedules)
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/config/custom_components/petsafe/SensorEntities.py", line 266, in _get_next_feeding_time
    return dt_util.as_local(sorted_feeding_times[0] + datetime.timedelta(days=1))
                            ~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions