Skip to content

Commit

Permalink
Tibber: Fix get_prices action not working with aware datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
functionpointer committed Aug 7, 2024
1 parent 6b3c3a9 commit 9c12522
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions homeassistant/components/tibber/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

import logging
import datetime as dt
from datetime import date, datetime
from datetime import datetime
from functools import partial
from typing import Any, Final

Expand Down Expand Up @@ -63,25 +64,24 @@ async def __get_prices(call: ServiceCall, *, hass: HomeAssistant) -> ServiceResp
selected_data = [
price
for price in price_data
if price["start_time"].replace(tzinfo=None) >= start
and price["start_time"].replace(tzinfo=None) < end
if price["start_time"] >= start and price["start_time"] < end
]
tibber_prices[home_nickname] = selected_data

return {"prices": tibber_prices}


def __get_date(date_input: str | None, mode: str | None) -> date | datetime:
def __get_date(date_input: str | None, mode: str | None) -> datetime:
"""Get date."""
if not date_input:
if mode == "end":
increment = dt.timedelta(days=1)
else:
increment = dt.timedelta()
return datetime.fromisoformat(dt_util.now().date().isoformat()) + increment
return dt_util.start_of_local_day() + increment

if value := dt_util.parse_datetime(date_input):
return value
return dt_util.as_local(value)

raise ServiceValidationError(
"Invalid datetime provided.",
Expand Down

0 comments on commit 9c12522

Please sign in to comment.