diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index a8ea18770d94c..894c2b15e475d 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -482,18 +482,19 @@ async def get( if start_time > now: return self.json([]) - end_time = request.query.get("end_time") - if end_time: - end_time = dt_util.parse_datetime(end_time) + end_time_str = request.query.get("end_time") + if end_time_str: + end_time = dt_util.parse_datetime(end_time_str) if end_time: end_time = dt_util.as_utc(end_time) else: return self.json_message("Invalid end_time", HTTP_BAD_REQUEST) else: end_time = start_time + one_day - entity_ids = request.query.get("filter_entity_id") - if entity_ids: - entity_ids = entity_ids.lower().split(",") + entity_ids_str = request.query.get("filter_entity_id") + entity_ids = None + if entity_ids_str: + entity_ids = entity_ids_str.lower().split(",") include_start_time_state = "skip_initial_state" not in request.query significant_changes_only = ( request.query.get("significant_changes_only", "1") != "0" diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index e33492c21a8f0..fe995222c679b 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -118,13 +118,14 @@ async def async_aiohttp_proxy_stream( hass: HomeAssistantType, request: web.BaseRequest, stream: aiohttp.StreamReader, - content_type: str, + content_type: Optional[str], buffer_size: int = 102400, timeout: int = 10, ) -> web.StreamResponse: """Stream a stream to aiohttp web response.""" response = web.StreamResponse() - response.content_type = content_type + if content_type is not None: + response.content_type = content_type await response.prepare(request) try: diff --git a/tests/components/accuweather/test_config_flow.py b/tests/components/accuweather/test_config_flow.py index 2d4769204ac4c..89159d7c1bfe3 100644 --- a/tests/components/accuweather/test_config_flow.py +++ b/tests/components/accuweather/test_config_flow.py @@ -159,6 +159,8 @@ async def test_options_flow(hass): return_value=json.loads( load_fixture("accuweather/current_conditions_data.json") ), + ), patch( + "accuweather.AccuWeather.async_get_forecast" ): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() @@ -174,3 +176,7 @@ async def test_options_flow(hass): assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert config_entry.options == {CONF_FORECAST: True} + + await hass.async_block_till_done() + assert await hass.config_entries.async_unload(config_entry.entry_id) + await hass.async_block_till_done() diff --git a/tests/components/airvisual/test_config_flow.py b/tests/components/airvisual/test_config_flow.py index 1939023155007..100ac748e3e2f 100644 --- a/tests/components/airvisual/test_config_flow.py +++ b/tests/components/airvisual/test_config_flow.py @@ -69,7 +69,7 @@ async def test_invalid_identifier(hass): } with patch( - "pyairvisual.air_quality.AirQuality", + "pyairvisual.air_quality.AirQuality.nearest_city", side_effect=InvalidKeyError, ): result = await hass.config_entries.flow.async_init( diff --git a/tests/components/onboarding/test_views.py b/tests/components/onboarding/test_views.py index a1b857a52ceb0..a4826c003286c 100644 --- a/tests/components/onboarding/test_views.py +++ b/tests/components/onboarding/test_views.py @@ -86,6 +86,8 @@ async def test_onboarding_progress(hass, hass_storage, aiohttp_client): mock_storage(hass_storage, {"done": ["hello"]}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() + client = await aiohttp_client(hass.http.app) with patch.object(views, "STEPS", ["hello", "world"]): @@ -104,6 +106,7 @@ async def test_onboarding_user_already_done(hass, hass_storage, aiohttp_client): with patch.object(onboarding, "STEPS", ["hello", "world"]): assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await aiohttp_client(hass.http.app) @@ -125,6 +128,7 @@ async def test_onboarding_user(hass, hass_storage, aiohttp_client): """Test creating a new user.""" assert await async_setup_component(hass, "person", {}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await aiohttp_client(hass.http.app) @@ -185,6 +189,7 @@ async def test_onboarding_user_invalid_name(hass, hass_storage, aiohttp_client): mock_storage(hass_storage, {"done": []}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await aiohttp_client(hass.http.app) @@ -206,6 +211,7 @@ async def test_onboarding_user_race(hass, hass_storage, aiohttp_client): mock_storage(hass_storage, {"done": ["hello"]}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await aiohttp_client(hass.http.app) @@ -240,6 +246,7 @@ async def test_onboarding_integration(hass, hass_storage, hass_client): mock_storage(hass_storage, {"done": [const.STEP_USER]}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await hass_client() @@ -282,6 +289,7 @@ async def test_onboarding_integration_invalid_redirect_uri( mock_storage(hass_storage, {"done": [const.STEP_USER]}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await hass_client() @@ -305,6 +313,7 @@ async def test_onboarding_integration_requires_auth(hass, hass_storage, aiohttp_ mock_storage(hass_storage, {"done": [const.STEP_USER]}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await aiohttp_client(hass.http.app) @@ -320,6 +329,7 @@ async def test_onboarding_core_sets_up_met(hass, hass_storage, hass_client): mock_storage(hass_storage, {"done": [const.STEP_USER]}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await hass_client() @@ -339,6 +349,7 @@ async def test_onboarding_core_sets_up_rpi_power( await async_setup_component(hass, "persistent_notification", {}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await hass_client() @@ -363,6 +374,7 @@ async def test_onboarding_core_no_rpi_power( await async_setup_component(hass, "persistent_notification", {}) assert await async_setup_component(hass, "onboarding", {}) + await hass.async_block_till_done() client = await hass_client() diff --git a/tests/components/ovo_energy/test_config_flow.py b/tests/components/ovo_energy/test_config_flow.py index 5800648876417..5719293357232 100644 --- a/tests/components/ovo_energy/test_config_flow.py +++ b/tests/components/ovo_energy/test_config_flow.py @@ -79,6 +79,12 @@ async def test_full_flow_implementation(hass: HomeAssistant) -> None: with patch( "homeassistant.components.ovo_energy.config_flow.OVOEnergy.authenticate", return_value=True, + ), patch( + "homeassistant.components.ovo_energy.async_setup", + return_value=True, + ), patch( + "homeassistant.components.ovo_energy.async_setup_entry", + return_value=True, ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], diff --git a/tests/components/sharkiq/test_vacuum.py b/tests/components/sharkiq/test_vacuum.py index 3b40011b8e630..e7255070eec09 100644 --- a/tests/components/sharkiq/test_vacuum.py +++ b/tests/components/sharkiq/test_vacuum.py @@ -220,6 +220,7 @@ async def test_locate(hass): (RuntimeError, False), ], ) +@patch("sharkiqpy.ayla_api.AylaApi", MockAyla) async def test_coordinator_updates( hass: HomeAssistant, side_effect: Optional[Exception], success: bool ) -> None: diff --git a/tests/test_util/aiohttp.py b/tests/test_util/aiohttp.py index 71358cdd9737b..fde1cb6ca2e5a 100644 --- a/tests/test_util/aiohttp.py +++ b/tests/test_util/aiohttp.py @@ -19,7 +19,7 @@ def mock_stream(data): """Mock a stream with data.""" protocol = mock.Mock(_reading_paused=False) - stream = StreamReader(protocol) + stream = StreamReader(protocol, limit=2 ** 16) stream.feed_data(data) stream.feed_eof() return stream