Skip to content

Commit

Permalink
update climate tests
Browse files Browse the repository at this point in the history
set current_temperature to None in test case. Is this the correct way for testing?
  • Loading branch information
liudger committed Aug 31, 2024
1 parent 01482f7 commit 1fba10e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/components/bsblan/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 12 additions & 0 deletions tests/components/bsblan/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1fba10e

Please sign in to comment.