Skip to content

Commit

Permalink
Release Candidate v0.7.3 (#88)
Browse files Browse the repository at this point in the history
- Fix date range when team not found
- Bypass pytest lingering timer error
  • Loading branch information
vasqued2 authored Apr 6, 2023
1 parent beaa1c0 commit 43515fe
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion custom_components/teamtracker/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

# Misc
TEAM_ID = ""
VERSION = "v0.7.1"
VERSION = "v0.7.3"
ISSUE_URL = "https://github.com/vasqued2/ha-teamtracker"
DOMAIN = "teamtracker"
PLATFORM = "sensor"
Expand Down
24 changes: 16 additions & 8 deletions custom_components/teamtracker/event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Parse throught the API data and find the right event/competition"""

from datetime import date, timedelta
from datetime import datetime
import logging

import arrow
Expand Down Expand Up @@ -30,6 +30,8 @@ async def async_process_event(
)

limit_hit = len(data["events"]) == API_LIMIT
first_date = datetime(9999, 12, 31, 1, 0, 0)
last_date = datetime(1900, 1, 31, 1, 0, 0)

for event in data["events"]:
event_state = "NOT_FOUND"
Expand All @@ -42,6 +44,15 @@ async def async_process_event(
event, "competitions", competition_index
)
team_index = -1

competition_date_str = await async_get_value(
competition, "date", default=(await async_get_value(event, "date"))
)
competition_date = datetime.strptime(competition_date_str, "%Y-%m-%dT%H:%Mz")
if competition_date > last_date:
last_date = competition_date
if competition_date < first_date:
first_date = competition_date
for team_index in range(
0, len(await async_get_value(competition, "competitors", default=[]))
):
Expand Down Expand Up @@ -126,17 +137,14 @@ async def async_process_event(
)

if not found_competitor:
first_date = (date.today() - timedelta(days=1)).strftime("%Y-%m-%dT%H:%MZ")
last_date = (date.today() + timedelta(days=5)).strftime("%Y-%m-%dT%H:%MZ")

if limit_hit:
values["api_message"] = (
"API_LIMIT hit. No competition found for '"
+ team_id
+ "' between "
+ first_date
+ first_date.strftime("%Y-%m-%dT%H:%MZ")
+ " and "
+ last_date
+ last_date.strftime("%Y-%m-%dT%H:%MZ")
)
_LOGGER.debug(
"%s: API_LIMIT hit (%s). No competitor information '%s' returned by API",
Expand All @@ -149,9 +157,9 @@ async def async_process_event(
"No competition scheduled for '"
+ team_id
+ "' between "
+ first_date
+ first_date.strftime("%Y-%m-%dT%H:%MZ")
+ " and "
+ last_date
+ last_date.strftime("%Y-%m-%dT%H:%MZ")
)
_LOGGER.debug(
"%s: No competitor information '%s' returned by API",
Expand Down
22 changes: 11 additions & 11 deletions custom_components/teamtracker/manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"domain": "teamtracker",
"name": "Team Tracker",
"codeowners": ["@vasqued2"],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/vasqued2/ha-teamtracker",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/vasqued2/ha-teamtracker/issues",
"requirements": ["arrow", "aiofiles"],
"version": "0.1"
}
"domain": "teamtracker",
"name": "Team Tracker",
"codeowners": ["@vasqued2"],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/vasqued2/ha-teamtracker",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/vasqued2/ha-teamtracker/issues",
"requirements": ["arrow", "aiofiles"],
"version": "0.1"
}
13 changes: 13 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for init."""
import pytest

from pytest_homeassistant_custom_component.common import MockConfigEntry

Expand All @@ -8,6 +9,17 @@
from tests.const import CONFIG_DATA


@pytest.fixture(autouse=True)
def expected_lingering_timers() -> bool:
"""Temporary ability to bypass test failures due to lingering timers.
Parametrize to True to bypass the pytest failure.
@pytest.mark.parametrize("expected_lingering_timers", [True])
This should be removed when all lingering timers have been cleaned up.
"""
return False


@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_setup_entry(
hass,
):
Expand All @@ -27,6 +39,7 @@ async def test_setup_entry(
assert len(entries) == 1


@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_unload_entry(hass):
"""Test unloading entities."""
entry = MockConfigEntry(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
"""Test NFL Sensor"""

import pytest

from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.teamtracker.const import DOMAIN

from tests.const import CONFIG_DATA


@pytest.fixture(autouse=True)
def expected_lingering_timers() -> bool:
"""Temporary ability to bypass test failures due to lingering timers.
Parametrize to True to bypass the pytest failure.
@pytest.mark.parametrize("expected_lingering_timers", [True])
This should be removed when all lingering timers have been cleaned up.
"""
return False


@pytest.mark.parametrize("expected_lingering_timers", [True])
async def test_sensor(hass, mocker):
""" Make sure sensor gets added """

Expand Down

0 comments on commit 43515fe

Please sign in to comment.