Skip to content

Commit

Permalink
Fix DST related test failure (#452)
Browse files Browse the repository at this point in the history
* Fix DST related test failure.

* Try the conversion from the HA local time instead.

* Save value of localized TZ.
  • Loading branch information
dermotduffy authored Mar 25, 2023
1 parent a388dd5 commit d78a346
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 2 additions & 3 deletions custom_components/frigate/media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,8 @@ def get_integration_proxy_path(self, timezone: str) -> str:
and self.hour is not None
):
year, month, day = self.year_month_day.split("-")
# Take the selected time in users local time
# and find the offset to utc, convert to UTC
# then request the vod for that time.
# Take the selected time in users local time and find the offset to
# UTC, convert to UTC then request the vod for that time.
start_date: dt.datetime = dt.datetime(
int(year),
int(month),
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ good-names = [
# locally-disabled - it spams too much
# duplicate-code - unavoidable
# cyclic-import - doesn't test if both import on load
# abstract-class-little-used - prevents from setting right foundation
# unused-argument - generic callbacks and setup methods create a lot of warnings
# too-many-* - are not enforced for the sake of readability
# too-few-* - same as too-many-*
Expand All @@ -67,7 +66,6 @@ good-names = [
# wrong-import-order - isort guards this
disable = [
"format",
"abstract-class-little-used",
"abstract-method",
"cyclic-import",
"duplicate-code",
Expand Down
13 changes: 12 additions & 1 deletion tests/test_media_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from unittest.mock import AsyncMock, Mock, call, patch

import pytest
import pytz

from custom_components.frigate.api import FrigateApiClient, FrigateApiClientError
from custom_components.frigate.const import (
Expand All @@ -33,6 +34,7 @@
from homeassistant.components.media_source.models import PlayMedia
from homeassistant.const import CONF_URL
from homeassistant.core import HomeAssistant
from homeassistant.helpers import system_info

from . import (
TEST_CONFIG,
Expand Down Expand Up @@ -642,9 +644,18 @@ async def test_async_resolve_media(
"/recordings/front_door/2021-05-30/15/46.08.mp4"
),
)

# Convert from HA local timezone to UTC.
info = await system_info.async_get_system_info(hass)
date = datetime.datetime(2021, 5, 30, 15, 46, 8)
date = pytz.timezone(info.get("timezone", "utc")).localize(date)
date = date.astimezone(pytz.utc)

assert media == PlayMedia(
url=(
f"/api/frigate/{TEST_FRIGATE_INSTANCE_ID}/vod/2021-05/30/23/front_door/utc/index.m3u8"
f"/api/frigate/{TEST_FRIGATE_INSTANCE_ID}/vod/"
+ date.strftime("%Y-%m/%d/%H")
+ "/front_door/utc/index.m3u8"
),
mime_type="application/x-mpegURL",
)
Expand Down

0 comments on commit d78a346

Please sign in to comment.