diff --git a/tests/components/ista_ecotrend/snapshots/test_util.ambr b/tests/components/ista_ecotrend/snapshots/test_util.ambr index 9536c5336db..9069cb617e3 100644 --- a/tests/components/ista_ecotrend/snapshots/test_util.ambr +++ b/tests/components/ista_ecotrend/snapshots/test_util.ambr @@ -1,5 +1,5 @@ # serializer version: 1 -# name: test_get_statistics +# name: test_get_statistics[heating-None] list([ dict({ 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), @@ -11,19 +11,7 @@ }), ]) # --- -# name: test_get_statistics.1 - list([ - dict({ - 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), - 'value': 113.0, - }), - dict({ - 'date': datetime.datetime(2024, 5, 31, 0, 0, tzinfo=datetime.timezone.utc), - 'value': 38.0, - }), - ]) -# --- -# name: test_get_statistics.2 +# name: test_get_statistics[heating-costs] list([ dict({ 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), @@ -35,7 +23,19 @@ }), ]) # --- -# name: test_get_statistics.3 +# name: test_get_statistics[heating-energy] + list([ + dict({ + 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), + 'value': 113.0, + }), + dict({ + 'date': datetime.datetime(2024, 5, 31, 0, 0, tzinfo=datetime.timezone.utc), + 'value': 38.0, + }), + ]) +# --- +# name: test_get_statistics[warmwater-None] list([ dict({ 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), @@ -47,7 +47,19 @@ }), ]) # --- -# name: test_get_statistics.4 +# name: test_get_statistics[warmwater-costs] + list([ + dict({ + 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), + 'value': 7, + }), + dict({ + 'date': datetime.datetime(2024, 5, 31, 0, 0, tzinfo=datetime.timezone.utc), + 'value': 7, + }), + ]) +# --- +# name: test_get_statistics[warmwater-energy] list([ dict({ 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), @@ -59,19 +71,7 @@ }), ]) # --- -# name: test_get_statistics.5 - list([ - dict({ - 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), - 'value': 7, - }), - dict({ - 'date': datetime.datetime(2024, 5, 31, 0, 0, tzinfo=datetime.timezone.utc), - 'value': 7, - }), - ]) -# --- -# name: test_get_statistics.6 +# name: test_get_statistics[water-None] list([ dict({ 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), @@ -83,11 +83,7 @@ }), ]) # --- -# name: test_get_statistics.7 - list([ - ]) -# --- -# name: test_get_statistics.8 +# name: test_get_statistics[water-costs] list([ dict({ 'date': datetime.datetime(2024, 4, 30, 0, 0, tzinfo=datetime.timezone.utc), @@ -99,39 +95,43 @@ }), ]) # --- -# name: test_get_values_by_type +# name: test_get_statistics[water-energy] + list([ + ]) +# --- +# name: test_get_values_by_type[heating] dict({ 'additionalValue': '38,0', 'type': 'heating', 'value': '35', }) # --- -# name: test_get_values_by_type.1 +# name: test_get_values_by_type[heating].1 + dict({ + 'type': 'heating', + 'value': 21, + }) +# --- +# name: test_get_values_by_type[warmwater] dict({ 'additionalValue': '57,0', 'type': 'warmwater', 'value': '1,0', }) # --- -# name: test_get_values_by_type.2 - dict({ - 'type': 'water', - 'value': '5,0', - }) -# --- -# name: test_get_values_by_type.3 - dict({ - 'type': 'heating', - 'value': 21, - }) -# --- -# name: test_get_values_by_type.4 +# name: test_get_values_by_type[warmwater].1 dict({ 'type': 'warmwater', 'value': 7, }) # --- -# name: test_get_values_by_type.5 +# name: test_get_values_by_type[water] + dict({ + 'type': 'water', + 'value': '5,0', + }) +# --- +# name: test_get_values_by_type[water].1 dict({ 'type': 'water', 'value': 3, diff --git a/tests/components/ista_ecotrend/test_util.py b/tests/components/ista_ecotrend/test_util.py index 616abdea8d6..f518a40b4b1 100644 --- a/tests/components/ista_ecotrend/test_util.py +++ b/tests/components/ista_ecotrend/test_util.py @@ -1,5 +1,6 @@ """Tests for the ista EcoTrend utility functions.""" +import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.components.ista_ecotrend.util import ( @@ -34,7 +35,17 @@ def test_last_day_of_month(snapshot: SnapshotAssertion) -> None: assert last_day_of_month(month=month + 1, year=2024) == snapshot -def test_get_values_by_type(snapshot: SnapshotAssertion) -> None: +@pytest.mark.parametrize( + "consumption_type", + [ + IstaConsumptionType.HEATING, + IstaConsumptionType.HOT_WATER, + IstaConsumptionType.WATER, + ], +) +def test_get_values_by_type( + snapshot: SnapshotAssertion, consumption_type: IstaConsumptionType +) -> None: """Test get_values_by_type function.""" consumptions = { "readings": [ @@ -55,9 +66,7 @@ def test_get_values_by_type(snapshot: SnapshotAssertion) -> None: ], } - assert get_values_by_type(consumptions, IstaConsumptionType.HEATING) == snapshot - assert get_values_by_type(consumptions, IstaConsumptionType.HOT_WATER) == snapshot - assert get_values_by_type(consumptions, IstaConsumptionType.WATER) == snapshot + assert get_values_by_type(consumptions, consumption_type) == snapshot costs = { "costsByEnergyType": [ @@ -76,71 +85,58 @@ def test_get_values_by_type(snapshot: SnapshotAssertion) -> None: ], } - assert get_values_by_type(costs, IstaConsumptionType.HEATING) == snapshot - assert get_values_by_type(costs, IstaConsumptionType.HOT_WATER) == snapshot - assert get_values_by_type(costs, IstaConsumptionType.WATER) == snapshot + assert get_values_by_type(costs, consumption_type) == snapshot - assert get_values_by_type({}, IstaConsumptionType.HEATING) == {} - assert get_values_by_type({"readings": []}, IstaConsumptionType.HEATING) == {} + assert get_values_by_type({}, consumption_type) == {} + assert get_values_by_type({"readings": []}, consumption_type) == {} -def test_get_native_value() -> None: +@pytest.mark.parametrize( + ("consumption_type", "value_type", "expected_value"), + [ + (IstaConsumptionType.HEATING, None, 35), + (IstaConsumptionType.HOT_WATER, None, 1.0), + (IstaConsumptionType.WATER, None, 5.0), + (IstaConsumptionType.HEATING, IstaValueType.COSTS, 21), + (IstaConsumptionType.HOT_WATER, IstaValueType.COSTS, 7), + (IstaConsumptionType.WATER, IstaValueType.COSTS, 3), + (IstaConsumptionType.HEATING, IstaValueType.ENERGY, 38.0), + (IstaConsumptionType.HOT_WATER, IstaValueType.ENERGY, 57.0), + ], +) +def test_get_native_value( + consumption_type: IstaConsumptionType, + value_type: IstaValueType | None, + expected_value: float, +) -> None: """Test getting native value for sensor states.""" test_data = get_consumption_data("26e93f1a-c828-11ea-87d0-0242ac130003") - assert get_native_value(test_data, IstaConsumptionType.HEATING) == 35 - assert get_native_value(test_data, IstaConsumptionType.HOT_WATER) == 1.0 - assert get_native_value(test_data, IstaConsumptionType.WATER) == 5.0 - - assert ( - get_native_value(test_data, IstaConsumptionType.HEATING, IstaValueType.COSTS) - == 21 - ) - assert ( - get_native_value(test_data, IstaConsumptionType.HOT_WATER, IstaValueType.COSTS) - == 7 - ) - assert ( - get_native_value(test_data, IstaConsumptionType.WATER, IstaValueType.COSTS) == 3 - ) - - assert ( - get_native_value(test_data, IstaConsumptionType.HEATING, IstaValueType.ENERGY) - == 38.0 - ) - assert ( - get_native_value(test_data, IstaConsumptionType.HOT_WATER, IstaValueType.ENERGY) - == 57.0 - ) + assert get_native_value(test_data, consumption_type, value_type) == expected_value no_data = {"consumptions": None, "costs": None} - assert get_native_value(no_data, IstaConsumptionType.HEATING) is None - assert ( - get_native_value(no_data, IstaConsumptionType.HEATING, IstaValueType.COSTS) - is None - ) + assert get_native_value(no_data, consumption_type, value_type) is None -def test_get_statistics(snapshot: SnapshotAssertion) -> None: +@pytest.mark.parametrize( + "value_type", + [None, IstaValueType.ENERGY, IstaValueType.COSTS], +) +@pytest.mark.parametrize( + "consumption_type", + [ + IstaConsumptionType.HEATING, + IstaConsumptionType.HOT_WATER, + IstaConsumptionType.WATER, + ], +) +def test_get_statistics( + snapshot: SnapshotAssertion, + value_type: IstaValueType | None, + consumption_type: IstaConsumptionType, +) -> None: """Test get_statistics function.""" test_data = get_consumption_data("26e93f1a-c828-11ea-87d0-0242ac130003") - for consumption_type in IstaConsumptionType: - assert get_statistics(test_data, consumption_type) == snapshot - assert get_statistics({"consumptions": None}, consumption_type) is None - assert ( - get_statistics(test_data, consumption_type, IstaValueType.ENERGY) - == snapshot - ) - assert ( - get_statistics( - {"consumptions": None}, consumption_type, IstaValueType.ENERGY - ) - is None - ) - assert ( - get_statistics(test_data, consumption_type, IstaValueType.COSTS) == snapshot - ) - assert ( - get_statistics({"costs": None}, consumption_type, IstaValueType.COSTS) - is None - ) + assert get_statistics(test_data, consumption_type, value_type) == snapshot + + assert get_statistics({"consumptions": None}, consumption_type, value_type) is None