Skip to content

Error adding entities for domain sensor with platform flagdays_dk #4

Open
@tsvane

Description

@tsvane

I am trying to add birthdays from Anniversaries integration but i end up with an error when HA is initializing flagdays_dk.

TypeError: can't compare offset-naive and offset-aware datetimes

Am i doing something wrong or is this an unsupported configuration?

configuration.yaml

flagdays_dk:
  flagdays:
    - sensor.birthday_tobias_fodselsdag
  attribute_names:
    - next_date

The sensor data from Anniversaries integration has the following format

attribution: Sensor data calculated by Anniversaries Integration
years_at_anniversary: 37
current_years: 36
date: '1986-07-01T00:00:00+02:00'
next_date: '2023-07-01T00:00:00+02:00'
weeks_remaining: 11
unit_of_measurement: dage
icon: mdi:cake-variant
friendly_name: Tobias

When restarting HA i get the following error from flagdays_dk integration

Logger: homeassistant.components.sensor
Source: custom_components/flagdays_dk/sensor.py:103
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 21:00:21 (2 occurrences)
Last logged: 21:00:21

Error adding entities for domain sensor with platform flagdays_dk
Error while setting up flagdays_dk platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 731, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 823, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 568, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 632, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 574, in _stringify_state
    if (state := self.state) is None:
  File "/config/custom_components/flagdays_dk/sensor.py", line 103, in state
    and self.nextFlagday.halfMast > dt_now
TypeError: can't compare offset-naive and offset-aware datetimes

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