diff --git a/custom_components/teamtracker/set_cricket.py b/custom_components/teamtracker/set_cricket.py index 9acf8c1..de7aa0b 100644 --- a/custom_components/teamtracker/set_cricket.py +++ b/custom_components/teamtracker/set_cricket.py @@ -12,10 +12,7 @@ async def async_set_cricket_values( ) -> bool: """Set cricket specific values""" - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 - team_index competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/custom_components/teamtracker/set_golf.py b/custom_components/teamtracker/set_golf.py index 2aa583e..2be595d 100644 --- a/custom_components/teamtracker/set_golf.py +++ b/custom_components/teamtracker/set_golf.py @@ -12,10 +12,7 @@ async def async_set_golf_values( ) -> bool: """Set golf specific values""" - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 if team_index == 0 else 0 competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/custom_components/teamtracker/set_hockey.py b/custom_components/teamtracker/set_hockey.py index 1888b86..ef81fc9 100644 --- a/custom_components/teamtracker/set_hockey.py +++ b/custom_components/teamtracker/set_hockey.py @@ -12,10 +12,7 @@ async def async_set_hockey_values( ) -> bool: """Set hockey specific values""" - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 - team_index competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/custom_components/teamtracker/set_mma.py b/custom_components/teamtracker/set_mma.py index 564bfc6..0b25533 100644 --- a/custom_components/teamtracker/set_mma.py +++ b/custom_components/teamtracker/set_mma.py @@ -14,10 +14,7 @@ async def async_set_mma_values( _LOGGER.debug("%s: async_set_mma_values() 1: %s", sensor_name, sensor_name) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 - team_index competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/custom_components/teamtracker/set_racing.py b/custom_components/teamtracker/set_racing.py index a5a7325..3b15d96 100644 --- a/custom_components/teamtracker/set_racing.py +++ b/custom_components/teamtracker/set_racing.py @@ -20,10 +20,7 @@ async def async_set_racing_values( # _LOGGER.debug("%s: async_set_racing_values() 0: %s", sensor_name, new_values) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 if team_index == 0 else 0 competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/custom_components/teamtracker/set_soccer.py b/custom_components/teamtracker/set_soccer.py index fff297e..6e1010f 100644 --- a/custom_components/teamtracker/set_soccer.py +++ b/custom_components/teamtracker/set_soccer.py @@ -15,10 +15,7 @@ async def async_set_soccer_values( teamPP = None oppoPP = None - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 - team_index competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/custom_components/teamtracker/set_tennis.py b/custom_components/teamtracker/set_tennis.py index 3b7799e..b4e198a 100644 --- a/custom_components/teamtracker/set_tennis.py +++ b/custom_components/teamtracker/set_tennis.py @@ -14,10 +14,7 @@ async def async_set_tennis_values( # _LOGGER.debug("%s: async_set_tennis_values() 0: %s %s %s", sensor_name, sensor_name, grouping_index, competition_index) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 - team_index grouping = await async_get_value(event, "groupings", grouping_index) if grouping is None: diff --git a/custom_components/teamtracker/set_values.py b/custom_components/teamtracker/set_values.py index 05bd10d..30a7c28 100644 --- a/custom_components/teamtracker/set_values.py +++ b/custom_components/teamtracker/set_values.py @@ -32,10 +32,7 @@ async def async_set_values( # _LOGGER.debug("%s: async_set_values() 1: %s", sensor_name, sensor_name) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 if team_index == 0 else 0 grouping = await async_get_value(event, "groupings", grouping_index) if grouping is None: competition = await async_get_value(event, "competitions", competition_index) @@ -180,10 +177,7 @@ async def async_set_universal_values( # _LOGGER.debug("%s: async_set_universal_values() 1: %s", sensor_name, sensor_name) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 if team_index == 0 else 0 grouping = await async_get_value(event, "groupings", grouping_index) if grouping is None: competition = await async_get_value(event, "competitions", competition_index) @@ -397,10 +391,7 @@ async def async_set_team_values( # _LOGGER.debug("%s: async_set_team_values() 1: %s", sensor_name, sensor_name) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 if team_index == 0 else 0 grouping = await async_get_value(event, "groupings", grouping_index) if grouping is None: competition = await async_get_value(event, "competitions", competition_index) @@ -479,10 +470,7 @@ async def async_set_in_values( # _LOGGER.debug("%s: async_set_in_values() 1: %s", sensor_name, sensor_name) - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 if team_index == 0 else 0 grouping = await async_get_value(event, "groupings", grouping_index) if grouping is None: diff --git a/custom_components/teamtracker/set_volleyball.py b/custom_components/teamtracker/set_volleyball.py index c5aa952..5efdf3d 100644 --- a/custom_components/teamtracker/set_volleyball.py +++ b/custom_components/teamtracker/set_volleyball.py @@ -12,10 +12,7 @@ async def async_set_volleyball_values( ) -> bool: """Set volleyball specific values""" - if team_index == 0: - oppo_index = 1 - else: - oppo_index = 0 + oppo_index = 1 - team_index competition = await async_get_value(event, "competitions", competition_index) competitor = await async_get_value(competition, "competitors", team_index) opponent = await async_get_value(competition, "competitors", oppo_index) diff --git a/tests/test_error_conditions.py b/tests/test_error_conditions.py new file mode 100644 index 0000000..5042d20 --- /dev/null +++ b/tests/test_error_conditions.py @@ -0,0 +1,44 @@ +"""Test NFL Sensor""" +import logging + +from custom_components.teamtracker.set_cricket import async_set_cricket_values +from custom_components.teamtracker.set_golf import async_set_golf_values +from custom_components.teamtracker.set_hockey import async_set_hockey_values +from custom_components.teamtracker.set_mma import async_set_mma_values +from custom_components.teamtracker.set_racing import async_set_racing_values +from custom_components.teamtracker.set_soccer import async_set_soccer_values +from custom_components.teamtracker.set_tennis import async_set_tennis_values +from custom_components.teamtracker.set_volleyball import async_set_volleyball_values +from custom_components.teamtracker.set_values import async_set_values, async_set_universal_values, async_set_team_values, async_set_in_values + +_LOGGER = logging.getLogger(__name__) + + +async def test_error_conditions(hass): + """ Use file w/ test json and loop through test cases and compare to expected results """ + + rc = await async_set_cricket_values({}, {}, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_golf_values({}, {}, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_hockey_values({}, {}, 0, 0, "sensor_name") + assert rc is False + rc = await async_set_mma_values({}, {}, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_racing_values({}, {}, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_soccer_values({}, {}, 0, 0, "sensor_name") + assert rc is False + rc = await async_set_tennis_values({}, {}, 0, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_volleyball_values({}, {}, 0, 0, "sensor_name") + assert rc is False + + rc = await async_set_values({}, {}, 0, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_universal_values({}, {}, 0, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_team_values({}, {}, 0, 0, 0, "en", "sensor_name") + assert rc is False + rc = await async_set_in_values({}, {}, 0, 0, 0, "sensor_name") + assert rc is False