home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.13k stars 29.8k forks source link

Tibber can't compare offset-naive and offset-aware datetimes #123288

Open functionpointer opened 1 month ago

functionpointer commented 1 month ago

The problem

The tibber.get_prices service fails when called with aware datetimes

What version of Home Assistant Core has the issue?

dev branch (9717a867a77c5416d8d)

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

tibber

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tibber/

Diagnostics information

No response

Example YAML snippet

template:
  - trigger:
     - platform: time_pattern
       minutes: /1
    action:
      - service: tibber.get_prices
        data:
          start: "{{ today_at(0) }}"
          end: "{{ today_at('23:59:59')+timedelta(days=1) }}"
        response_variable: my_spot_prices
    sensor:
      - name: Tibber Spot Prices
        unique_id: tibber_spot_prices
        state: "{{ now().isoformat() }}"
        attributes:
          price: "{{ my_spot_prices }}"

Anything in the logs that might be useful for us?

2024-08-07 14:02:00.258 ERROR (MainThread) [homeassistant.helpers.script.trigger_update_coordinator] Trigger Update Coordinator: Error executing script. Unexpected error for call_service at pos 1: can't compare offset-naive and offset-aware datetimes
Traceback (most recent call last):
  File "/home/user/git/home-assistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/home/user/git/home-assistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/git/home-assistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/home/user/git/home-assistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/home/user/git/home-assistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/git/home-assistant/homeassistant/components/tibber/services.py", line 66, in __get_prices
    if price["start_time"].replace(tzinfo=None) >= start
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @danielhiversen, mind taking a look at this issue as it has been labeled with an integration (tibber) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tibber` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tibber` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tibber documentation tibber source (message by IssueLinks)

functionpointer commented 1 month ago

Could this be caused by a change of the tibber api?

The mock data in tests/components/tibber/test_services does not contain utc offsets, while real data from the API clearly does.