Skip to content

Commit 03a8869

Browse files
authored
v0.14.8 Release Candidate (#217)
Add attributes for sport_path, league_path, team_conference_id, opponent_conference_id, and api_url
1 parent 229397a commit 03a8869

37 files changed

+194
-3
lines changed

custom_components/teamtracker/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class TeamTrackerDataUpdateCoordinator(DataUpdateCoordinator):
214214
def __init__(self, hass, config, entry: ConfigEntry=None):
215215
"""Initialize."""
216216
self.name = config[CONF_NAME]
217+
self.api_url = ""
217218
self.league_id = config[CONF_LEAGUE_ID]
218219
self.league_path = config[CONF_LEAGUE_PATH]
219220
self.sport_path = config[CONF_SPORT_PATH]
@@ -499,7 +500,8 @@ async def async_call_api(self, config, hass, lang) -> dict:
499500
data = await r.json()
500501
except:
501502
data = None
502-
503+
self.api_url = url
504+
503505
return data, file_override
504506

505507
async def async_update_values(self, config, hass, data, lang) -> dict:
@@ -515,12 +517,15 @@ async def async_update_values(self, config, hass, data, lang) -> dict:
515517

516518
values = await async_clear_values()
517519
values["sport"] = sport_path
520+
values["sport_path"] = self.sport_path
518521
values["league"] = league_id
522+
values["league_path"] = self.league_path
519523
values["league_logo"] = DEFAULT_LOGO
520524
values["team_abbr"] = team_id
521525
values["state"] = "NOT_FOUND"
522526
values["last_update"] = arrow.now().format(arrow.FORMAT_W3C)
523527
values["private_fast_refresh"] = False
528+
values["api_url"] = self.api_url
524529

525530
if data is None:
526531
values["api_message"] = "API error, no data returned"

custom_components/teamtracker/clear_values.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ async def async_clear_values() -> dict:
88
# Reset values
99
new_values = {
1010
"sport": None,
11+
"sport_path": None,
1112
"league": None,
13+
"league_path": None,
1214
"league_logo": None,
1315
"season": None,
1416
"team_abbr": None,
@@ -28,6 +30,7 @@ async def async_clear_values() -> dict:
2830
"team_id": None,
2931
"team_record": None,
3032
"team_rank": None,
33+
"team_conference_id": None,
3134
"team_homeaway": None,
3235
"team_logo": None,
3336
"team_url": None,
@@ -41,6 +44,7 @@ async def async_clear_values() -> dict:
4144
"opponent_id": None,
4245
"opponent_record": None,
4346
"opponent_rank": None,
47+
"opponent_conference_id": None,
4448
"opponent_homeaway": None,
4549
"opponent_logo": None,
4650
"opponent_url": None,
@@ -68,6 +72,7 @@ async def async_clear_values() -> dict:
6872
"opponent_sets_won": None,
6973
"last_update": None,
7074
"api_message": None,
75+
"api_url": None,
7176
"private_fast_refresh": False,
7277
}
7378

custom_components/teamtracker/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195

196196
# Misc
197197
TEAM_ID = ""
198-
VERSION = "v0.14.7"
198+
VERSION = "v0.14.8"
199199
ISSUE_URL = "https://github.com/vasqued2/ha-teamtracker"
200200
DOMAIN = "teamtracker"
201201
ATTRIBUTION = "Data provided by ESPN"

custom_components/teamtracker/sensor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, config: ConfigType)
195195
self._state = "PRE"
196196

197197
self._sport = None
198+
self._sport_path = None
198199
self._league = None
200+
self._league_path = None
199201
self._league_logo = None
200202
self._season = None
201203
self._team_abbr = None
@@ -217,6 +219,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, config: ConfigType)
217219
self._team_id = None
218220
self._team_record = None
219221
self._team_rank = None
222+
self._team_conference_id = None
220223
self._team_homeaway = None
221224
self._team_logo = None
222225
self._team_url = None
@@ -231,6 +234,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, config: ConfigType)
231234
self._opponent_id = None
232235
self._opponent_record = None
233236
self._opponent_rank = None
237+
self._opponent_conference_id = None
234238
self._opponent_homeaway = None
235239
self._opponent_logo = None
236240
self._opponent_url = None
@@ -263,6 +267,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, config: ConfigType)
263267

264268
self._last_update = None
265269
self._api_message = None
270+
self._api_url = None
266271

267272
@property
268273
def unique_id(self) -> str:
@@ -303,7 +308,9 @@ def extra_state_attributes(self) -> dict[str, Any]:
303308
attrs[ATTR_ATTRIBUTION] = ATTRIBUTION
304309

305310
attrs["sport"] = self.coordinator.data["sport"]
311+
attrs["sport_path"] = self.coordinator.data["sport_path"]
306312
attrs["league"] = self.coordinator.data["league"]
313+
attrs["league_path"] = self.coordinator.data["league_path"]
307314
attrs["league_logo"] = self.coordinator.data["league_logo"]
308315
attrs["season"] = self.coordinator.data["season"]
309316
attrs["team_abbr"] = self.coordinator.data["team_abbr"]
@@ -325,6 +332,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
325332
attrs["team_id"] = self.coordinator.data["team_id"]
326333
attrs["team_record"] = self.coordinator.data["team_record"]
327334
attrs["team_rank"] = self.coordinator.data["team_rank"]
335+
attrs["team_conference_id"] = self.coordinator.data["team_conference_id"]
328336
attrs["team_homeaway"] = self.coordinator.data["team_homeaway"]
329337
attrs["team_logo"] = self.coordinator.data["team_logo"]
330338
attrs["team_url"] = self.coordinator.data["team_url"]
@@ -340,6 +348,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
340348
attrs["opponent_id"] = self.coordinator.data["opponent_id"]
341349
attrs["opponent_record"] = self.coordinator.data["opponent_record"]
342350
attrs["opponent_rank"] = self.coordinator.data["opponent_rank"]
351+
attrs["opponent_conference_id"] = self.coordinator.data["opponent_conference_id"]
343352
attrs["opponent_homeaway"] = self.coordinator.data["opponent_homeaway"]
344353
attrs["opponent_logo"] = self.coordinator.data["opponent_logo"]
345354
attrs["opponent_url"] = self.coordinator.data["opponent_url"]
@@ -379,6 +388,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
379388

380389
attrs["last_update"] = self.coordinator.data["last_update"]
381390
attrs["api_message"] = self.coordinator.data["api_message"]
391+
attrs["api_url"] = self.coordinator.data["api_url"]
382392

383393
return attrs
384394

custom_components/teamtracker/set_values.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ async def async_set_universal_values(
281281
default=await async_get_value(competitor, "roster", "displayName")
282282
),
283283
)
284+
new_values["team_conference_id"] = await async_get_value(
285+
competitor,
286+
"team",
287+
"conferenceId"
288+
)
284289
new_values["opponent_name"] = await async_get_value(
285290
opponent,
286291
"team",
@@ -297,13 +302,18 @@ async def async_set_universal_values(
297302
default=await async_get_value(opponent, "roster", "displayName")
298303
),
299304
)
300-
305+
new_values["opponent_conference_id"] = await async_get_value(
306+
opponent,
307+
"team",
308+
"conferenceId"
309+
)
301310
new_values["team_record"] = await async_get_value(
302311
competitor, "records", 0, "summary"
303312
)
304313
new_values["opponent_record"] = await async_get_value(
305314
opponent, "records", 0, "summary"
306315
)
316+
307317
new_values["team_logo"] = await async_get_value(
308318
competitor,
309319
"team",

tests/test_event.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,11 @@ async def test_event(hass):
6060
contents = await f.read()
6161
expected_results = json.loads(contents)
6262

63+
# Ignore expected values not set in the async_process_event() function
64+
65+
expected_results["api_url"] = None
66+
expected_results["sport_path"] = None
67+
expected_results["league_path"] = None
68+
6369
values["kickoff_in"] = DEFAULT_KICKOFF_IN # set to default value for compare
6470
assert values == expected_results

tests/tt/results/test_tt_all_test01.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"sport": "baseball",
3+
"sport_path": "baseball",
34
"league": "MLB",
5+
"league_path": "mlb",
46
"league_logo": "https://a.espncdn.com/i/teamlogos/leagues/500/mlb.png",
57
"season": "regular-season",
68
"team_abbr": "MIA",
@@ -20,6 +22,7 @@
2022
"team_id": "28",
2123
"team_record": "55-80",
2224
"team_rank": null,
25+
"team_conference_id": null,
2326
"team_homeaway": "away",
2427
"team_logo": "https://a.espncdn.com/i/teamlogos/mlb/500/scoreboard/mia.png",
2528
"team_url": "https://www.espn.com/mlb/team/_/name/mia/miami-marlins",
@@ -36,6 +39,7 @@
3639
"opponent_id": "22",
3740
"opponent_record": "75-61",
3841
"opponent_rank": null,
42+
"opponent_conference_id": null,
3943
"opponent_homeaway": "home",
4044
"opponent_logo": "https://a.espncdn.com/i/teamlogos/mlb/500/scoreboard/phi.png",
4145
"opponent_url": "https://www.espn.com/mlb/team/_/name/phi/philadelphia-phillies",
@@ -66,6 +70,7 @@
6670
"opponent_sets_won": null,
6771
"last_update": "2022-02-02 02:02:02-05:00",
6872
"api_message": null,
73+
"api_url": "http://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard?lang=en&limit=25&groups=9999",
6974
"private_fast_refresh": false,
7075
"state": "PRE"
7176
}

tests/tt/results/test_tt_all_test02.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"sport": "baseball",
3+
"sport_path": "baseball",
34
"league": "MLB",
5+
"league_path": "mlb",
46
"league_logo": "https://a.espncdn.com/i/teamlogos/leagues/500/mlb.png",
57
"season": "regular-season",
68
"team_abbr": "MIL",
@@ -20,6 +22,7 @@
2022
"team_id": "8",
2123
"team_record": "71-65",
2224
"team_rank": null,
25+
"team_conference_id": null,
2326
"team_homeaway": "home",
2427
"team_logo": "https://a.espncdn.com/i/teamlogos/mlb/500/scoreboard/mil.png",
2528
"team_url": "https://www.espn.com/mlb/team/_/name/mil/milwaukee-brewers",
@@ -36,6 +39,7 @@
3639
"opponent_id": "26",
3740
"opponent_record": "65-70",
3841
"opponent_rank": null,
42+
"opponent_conference_id": null,
3943
"opponent_homeaway": "away",
4044
"opponent_logo": "https://a.espncdn.com/i/teamlogos/mlb/500/scoreboard/sf.png",
4145
"opponent_url": "https://www.espn.com/mlb/team/_/name/sf/san-francisco-giants",
@@ -66,6 +70,7 @@
6670
"opponent_sets_won": null,
6771
"last_update": "2022-02-02 02:02:02-05:00",
6872
"api_message": null,
73+
"api_url": "http://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard?lang=en&limit=25&groups=9999",
6974
"private_fast_refresh": true,
7075
"state": "IN"
7176
}

tests/tt/results/test_tt_all_test03.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"sport": "baseball",
3+
"sport_path": "baseball",
34
"league": "MLB",
5+
"league_path": "mlb",
46
"league_logo": "https://a.espncdn.com/i/teamlogos/leagues/500/mlb.png",
57
"season": "regular-season",
68
"team_abbr": "CIN",
@@ -20,6 +22,7 @@
2022
"team_id": "17",
2123
"team_record": "55-80",
2224
"team_rank": null,
25+
"team_conference_id": null,
2326
"team_homeaway": "away",
2427
"team_logo": "https://a.espncdn.com/i/teamlogos/mlb/500/scoreboard/cin.png",
2528
"team_url": "https://www.espn.com/mlb/team/_/name/cin/cincinnati-reds",
@@ -36,6 +39,7 @@
3639
"opponent_id": "16",
3740
"opponent_record": "57-80",
3841
"opponent_rank": null,
42+
"opponent_conference_id": null,
3943
"opponent_homeaway": "home",
4044
"opponent_logo": "https://a.espncdn.com/i/teamlogos/mlb/500/scoreboard/chc.png",
4145
"opponent_url": "https://www.espn.com/mlb/team/_/name/chc/chicago-cubs",
@@ -66,6 +70,7 @@
6670
"opponent_sets_won": null,
6771
"last_update": "2022-02-02 02:02:02-05:00",
6872
"api_message": null,
73+
"api_url": "http://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard?lang=en&limit=25&groups=9999",
6974
"private_fast_refresh": false,
7075
"state": "POST"
7176
}

tests/tt/results/test_tt_all_test04.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"sport": "football",
3+
"sport_path": "football",
34
"league": "NCAAF",
5+
"league_path": "college-football",
46
"league_logo": "https://a.espncdn.com/i/teamlogos/leagues/500/mlb.png",
57
"season": "regular-season",
68
"team_abbr": "BGSU",
@@ -20,6 +22,7 @@
2022
"team_id": "189",
2123
"team_record": "0-1",
2224
"team_rank": null,
25+
"team_conference_id": "15",
2326
"team_homeaway": "home",
2427
"team_logo": "https://a.espncdn.com/i/teamlogos/ncaa/500/189.png",
2528
"team_url": "https://www.espn.com/college-football/team/_/id/189/bowling-green-falcons",
@@ -36,6 +39,7 @@
3639
"opponent_id": "2198",
3740
"opponent_record": "0-1",
3841
"opponent_rank": null,
42+
"opponent_conference_id": "176",
3943
"opponent_homeaway": "away",
4044
"opponent_logo": "https://a.espncdn.com/i/teamlogos/ncaa/500/2198.png",
4145
"opponent_url": "https://www.espn.com/college-football/team/_/id/2198/eastern-kentucky-colonels",
@@ -66,6 +70,7 @@
6670
"opponent_sets_won": null,
6771
"last_update": "2022-02-02 02:02:02-05:00",
6872
"api_message": null,
73+
"api_url": "http://site.api.espn.com/apis/site/v2/sports/football/college-football/scoreboard?lang=en&limit=25&dates=20250417-20250423&groups=9999",
6974
"private_fast_refresh": false,
7075
"state": "PRE"
7176
}

0 commit comments

Comments
 (0)