From 1fba10eb984adc74d170398f42e8c4bd2d5fd188 Mon Sep 17 00:00:00 2001 From: "Willem-Jan L. van Rootselaar" Date: Sat, 31 Aug 2024 21:23:18 +0200 Subject: [PATCH] update climate tests set current_temperature to None in test case. Is this the correct way for testing? --- tests/components/bsblan/conftest.py | 8 ++++++++ tests/components/bsblan/test_climate.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/components/bsblan/conftest.py b/tests/components/bsblan/conftest.py index c0aa40adbf2c21..331d7881a53f97 100644 --- a/tests/components/bsblan/conftest.py +++ b/tests/components/bsblan/conftest.py @@ -56,6 +56,14 @@ def mock_bsblan(request: pytest.FixtureRequest) -> Generator[MagicMock, None, No bsblan.static_values.return_value = StaticState.from_json( load_fixture(request.param, DOMAIN) ) + + # Add a method to update the current_temperature dynamically + def set_current_temperature(value): + state = bsblan.state.return_value + state.current_temperature.value = value + + bsblan.set_current_temperature = set_current_temperature + yield bsblan diff --git a/tests/components/bsblan/test_climate.py b/tests/components/bsblan/test_climate.py index 0c9524413e6a7c..cc738c06d4dd09 100644 --- a/tests/components/bsblan/test_climate.py +++ b/tests/components/bsblan/test_climate.py @@ -24,3 +24,15 @@ async def test_climate_entity( await setup_with_selected_platforms(hass, mock_config_entry, [Platform.CLIMATE]) await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) + + # Spoof the current_temperature value to "---" + mock_bsblan.set_current_temperature("---") + + # Update the state in Home Assistant + await hass.helpers.entity_component.async_update_entity("climate.bsb_lan") + + # Get the state of the climate entity + state = hass.states.get("climate.bsb_lan") + + # Assert that the current_temperature attribute is None + assert state.attributes["current_temperature"] is None