Skip to content

Commit

Permalink
Remove flaky climacell test (home-assistant#47080)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored Feb 26, 2021
1 parent dfbb653 commit 56673f7
Showing 1 changed file with 1 addition and 45 deletions.
46 changes: 1 addition & 45 deletions tests/components/climacell/test_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tests for Climacell init."""
from datetime import timedelta
import logging
from unittest.mock import patch

import pytest

Expand All @@ -12,11 +10,10 @@
from homeassistant.components.climacell.const import DOMAIN
from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN
from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import dt as dt_util

from .const import MIN_CONFIG

from tests.common import MockConfigEntry, async_fire_time_changed
from tests.common import MockConfigEntry

_LOGGER = logging.getLogger(__name__)

Expand All @@ -39,44 +36,3 @@ async def test_load_and_unload(
assert await hass.config_entries.async_remove(config_entry.entry_id)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 0


async def test_update_interval(
hass: HomeAssistantType,
climacell_config_entry_update: pytest.fixture,
) -> None:
"""Test that update_interval changes based on number of entries."""
now = dt_util.utcnow()
async_fire_time_changed(hass, now)
config = _get_config_schema(hass)(MIN_CONFIG)
for i in range(1, 3):
config_entry = MockConfigEntry(
domain=DOMAIN, data=config, unique_id=_get_unique_id(hass, config) + str(i)
)
config_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

with patch("homeassistant.components.climacell.ClimaCell.realtime") as mock_api:
# First entry refresh will happen in 7 minutes due to original update interval.
# Next refresh for this entry will happen at 20 minutes due to the update interval
# change.
mock_api.return_value = {}
async_fire_time_changed(hass, now + timedelta(minutes=7))
await hass.async_block_till_done()
assert mock_api.call_count == 1

# Second entry refresh will happen in 13 minutes due to the update interval set
# when it was set up. Next refresh for this entry will happen at 26 minutes due to the
# update interval change.
mock_api.reset_mock()
async_fire_time_changed(hass, now + timedelta(minutes=13))
await hass.async_block_till_done()
assert not mock_api.call_count == 1

# 19 minutes should be after the first update for each config entry and before the
# second update for the first config entry
mock_api.reset_mock()
async_fire_time_changed(hass, now + timedelta(minutes=19))
await hass.async_block_till_done()
assert not mock_api.call_count == 0

0 comments on commit 56673f7

Please sign in to comment.