From 7a4d15a657f1acb2cbe05d4b9b5d036e8de2ae0a Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 8 Feb 2023 13:33:52 +0100 Subject: [PATCH] Add type hints to integration tests (f-g) (#87700) --- .../components/faa_delays/test_config_flow.py | 11 +- tests/components/fail2ban/test_sensor.py | 19 +-- tests/components/fan/test_device_action.py | 3 +- tests/components/fan/test_init.py | 4 +- tests/components/fan/test_reproduce_state.py | 13 +- tests/components/feedreader/test_init.py | 7 +- tests/components/ffmpeg/test_init.py | 24 ++-- tests/components/fibaro/test_config_flow.py | 23 ++-- tests/components/fido/test_sensor.py | 4 +- .../fireservicerota/test_config_flow.py | 11 +- tests/components/flic/test_binary_sensor.py | 3 +- .../flick_electric/test_config_flow.py | 11 +- tests/components/flipr/test_config_flow.py | 3 +- tests/components/flo/test_config_flow.py | 7 +- tests/components/flume/test_config_flow.py | 9 +- tests/components/flux/test_switch.py | 14 +- tests/components/flux_led/test_config_flow.py | 24 ++-- tests/components/flux_led/test_diagnostics.py | 6 +- tests/components/folder/test_sensor.py | 5 +- tests/components/folder_watcher/test_init.py | 5 +- tests/components/foobot/test_sensor.py | 19 ++- .../forked_daapd/test_config_flow.py | 7 +- tests/components/foscam/test_config_flow.py | 13 +- tests/components/freedns/test_init.py | 8 +- .../components/freedompro/test_config_flow.py | 9 +- tests/components/freedompro/test_init.py | 3 +- tests/components/fronius/test_config_flow.py | 15 ++- tests/components/fronius/test_coordinator.py | 6 +- tests/components/fronius/test_init.py | 15 ++- tests/components/fronius/test_sensor.py | 28 +++- tests/components/frontend/test_init.py | 5 +- tests/components/gdacs/test_config_flow.py | 7 +- tests/components/gdacs/test_geo_location.py | 5 +- tests/components/gdacs/test_sensor.py | 3 +- tests/components/generic/test_camera.py | 8 +- tests/components/generic/test_config_flow.py | 2 +- .../generic_hygrostat/test_humidifier.py | 34 +++-- .../generic_thermostat/test_climate.py | 34 +++-- .../geo_json_events/test_geo_location.py | 7 +- tests/components/geo_location/test_init.py | 5 +- .../geonetnz_quakes/test_config_flow.py | 7 +- .../geonetnz_quakes/test_geo_location.py | 5 +- .../components/geonetnz_quakes/test_sensor.py | 3 +- .../geonetnz_volcano/test_config_flow.py | 7 +- .../geonetnz_volcano/test_sensor.py | 5 +- tests/components/gios/test_config_flow.py | 11 +- tests/components/gios/test_diagnostics.py | 7 +- tests/components/gios/test_init.py | 11 +- tests/components/gios/test_sensor.py | 11 +- tests/components/gios/test_system_health.py | 10 +- .../components/gogogate2/test_config_flow.py | 8 +- .../google_assistant/test_helpers.py | 17 ++- .../components/google_assistant/test_http.py | 17 ++- .../google_assistant/test_logbook.py | 3 +- .../google_assistant/test_report_state.py | 7 +- .../google_assistant/test_smart_home.py | 32 +++-- .../components/google_assistant/test_trait.py | 119 +++++++++-------- tests/components/google_domains/test_init.py | 8 +- .../google_travel_time/test_config_flow.py | 15 ++- .../google_travel_time/test_sensor.py | 14 +- .../components/govee_ble/test_config_flow.py | 24 ++-- tests/components/govee_ble/test_sensor.py | 7 +- tests/components/gree/test_config_flow.py | 5 +- tests/components/gree/test_init.py | 5 +- tests/components/group/test_binary_sensor.py | 7 +- tests/components/group/test_cover.py | 3 +- tests/components/group/test_fan.py | 6 +- tests/components/group/test_init.py | 121 ++++++++++-------- tests/components/group/test_light.py | 27 ++-- tests/components/group/test_lock.py | 14 +- tests/components/group/test_notify.py | 5 +- .../components/group/test_reproduce_state.py | 5 +- tests/components/group/test_switch.py | 17 ++- .../growatt_server/test_config_flow.py | 13 +- tests/components/guardian/test_config_flow.py | 9 +- 75 files changed, 609 insertions(+), 415 deletions(-) diff --git a/tests/components/faa_delays/test_config_flow.py b/tests/components/faa_delays/test_config_flow.py index 8b869d4830e..ce7f86e6060 100644 --- a/tests/components/faa_delays/test_config_flow.py +++ b/tests/components/faa_delays/test_config_flow.py @@ -7,6 +7,7 @@ import faadelays from homeassistant import config_entries, data_entry_flow from homeassistant.components.faa_delays.const import DOMAIN from homeassistant.const import CONF_ID +from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from tests.common import MockConfigEntry @@ -17,7 +18,7 @@ async def mock_valid_airport(self, *args, **kwargs): self.name = "Test airport" -async def test_form(hass): +async def test_form(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( @@ -46,7 +47,7 @@ async def test_form(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_duplicate_error(hass): +async def test_duplicate_error(hass: HomeAssistant) -> None: """Test that we handle a duplicate configuration.""" conf = {CONF_ID: "test"} @@ -60,7 +61,7 @@ async def test_duplicate_error(hass): assert result["reason"] == "already_configured" -async def test_form_invalid_airport(hass): +async def test_form_invalid_airport(hass: HomeAssistant) -> None: """Test we handle invalid airport.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -81,7 +82,7 @@ async def test_form_invalid_airport(hass): assert result2["errors"] == {CONF_ID: "invalid_airport"} -async def test_form_cannot_connect(hass): +async def test_form_cannot_connect(hass: HomeAssistant) -> None: """Test we handle a connection error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -99,7 +100,7 @@ async def test_form_cannot_connect(hass): assert result2["errors"] == {"base": "cannot_connect"} -async def test_form_unexpected_exception(hass): +async def test_form_unexpected_exception(hass: HomeAssistant) -> None: """Test we handle an unexpected exception.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} diff --git a/tests/components/fail2ban/test_sensor.py b/tests/components/fail2ban/test_sensor.py index 0240ffc6d11..5906ac947fe 100644 --- a/tests/components/fail2ban/test_sensor.py +++ b/tests/components/fail2ban/test_sensor.py @@ -7,6 +7,7 @@ from homeassistant.components.fail2ban.sensor import ( BanLogParser, BanSensor, ) +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import assert_setup_component @@ -58,7 +59,7 @@ def fake_log(log_key): @patch("os.path.isfile", Mock(return_value=True)) -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test that sensor can be setup.""" config = {"sensor": {"platform": "fail2ban", "jails": ["jail_one"]}} mock_fh = mock_open() @@ -69,7 +70,7 @@ async def test_setup(hass): @patch("os.path.isfile", Mock(return_value=True)) -async def test_multi_jails(hass): +async def test_multi_jails(hass: HomeAssistant) -> None: """Test that multiple jails can be set up as sensors..""" config = {"sensor": {"platform": "fail2ban", "jails": ["jail_one", "jail_two"]}} mock_fh = mock_open() @@ -79,7 +80,7 @@ async def test_multi_jails(hass): assert_setup_component(2, "sensor") -async def test_single_ban(hass): +async def test_single_ban(hass: HomeAssistant) -> None: """Test that log is parsed correctly for single ban.""" log_parser = BanLogParser("/test/fail2ban.log") sensor = BanSensor("fail2ban", "jail_one", log_parser) @@ -94,7 +95,7 @@ async def test_single_ban(hass): assert sensor.extra_state_attributes[STATE_ALL_BANS] == ["111.111.111.111"] -async def test_ipv6_ban(hass): +async def test_ipv6_ban(hass: HomeAssistant) -> None: """Test that log is parsed correctly for IPV6 bans.""" log_parser = BanLogParser("/test/fail2ban.log") sensor = BanSensor("fail2ban", "jail_one", log_parser) @@ -109,7 +110,7 @@ async def test_ipv6_ban(hass): assert sensor.extra_state_attributes[STATE_ALL_BANS] == ["2607:f0d0:1002:51::4"] -async def test_multiple_ban(hass): +async def test_multiple_ban(hass: HomeAssistant) -> None: """Test that log is parsed correctly for multiple ban.""" log_parser = BanLogParser("/test/fail2ban.log") sensor = BanSensor("fail2ban", "jail_one", log_parser) @@ -130,7 +131,7 @@ async def test_multiple_ban(hass): ] -async def test_unban_all(hass): +async def test_unban_all(hass: HomeAssistant) -> None: """Test that log is parsed correctly when unbanning.""" log_parser = BanLogParser("/test/fail2ban.log") sensor = BanSensor("fail2ban", "jail_one", log_parser) @@ -148,7 +149,7 @@ async def test_unban_all(hass): ] -async def test_unban_one(hass): +async def test_unban_one(hass: HomeAssistant) -> None: """Test that log is parsed correctly when unbanning one ip.""" log_parser = BanLogParser("/test/fail2ban.log") sensor = BanSensor("fail2ban", "jail_one", log_parser) @@ -166,7 +167,7 @@ async def test_unban_one(hass): ] -async def test_multi_jail(hass): +async def test_multi_jail(hass: HomeAssistant) -> None: """Test that log is parsed correctly when using multiple jails.""" log_parser = BanLogParser("/test/fail2ban.log") sensor1 = BanSensor("fail2ban", "jail_one", log_parser) @@ -188,7 +189,7 @@ async def test_multi_jail(hass): assert sensor2.extra_state_attributes[STATE_ALL_BANS] == ["222.222.222.222"] -async def test_ban_active_after_update(hass): +async def test_ban_active_after_update(hass: HomeAssistant) -> None: """Test that ban persists after subsequent update.""" log_parser = BanLogParser("/test/fail2ban.log") sensor = BanSensor("fail2ban", "jail_one", log_parser) diff --git a/tests/components/fan/test_device_action.py b/tests/components/fan/test_device_action.py index 8800e61675e..96269513306 100644 --- a/tests/components/fan/test_device_action.py +++ b/tests/components/fan/test_device_action.py @@ -4,6 +4,7 @@ import pytest import homeassistant.components.automation as automation from homeassistant.components.device_automation import DeviceAutomationType from homeassistant.components.fan import DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_registry import RegistryEntryHider @@ -106,7 +107,7 @@ async def test_get_actions_hidden_auxiliary( assert_lists_same(actions, expected_actions) -async def test_action(hass): +async def test_action(hass: HomeAssistant) -> None: """Test for turn_on and turn_off actions.""" assert await async_setup_component( hass, diff --git a/tests/components/fan/test_init.py b/tests/components/fan/test_init.py index f79036a06ba..f61d5a792d1 100644 --- a/tests/components/fan/test_init.py +++ b/tests/components/fan/test_init.py @@ -1,8 +1,8 @@ """Tests for fan platforms.""" - import pytest from homeassistant.components.fan import FanEntity +from homeassistant.core import HomeAssistant class BaseFan(FanEntity): @@ -36,7 +36,7 @@ def test_fanentity() -> None: fan.turn_off() -async def test_async_fanentity(hass): +async def test_async_fanentity(hass: HomeAssistant) -> None: """Test async fan entity methods.""" fan = BaseFan() fan.hass = hass diff --git a/tests/components/fan/test_reproduce_state.py b/tests/components/fan/test_reproduce_state.py index e33f1005d75..ac0f55f4e16 100644 --- a/tests/components/fan/test_reproduce_state.py +++ b/tests/components/fan/test_reproduce_state.py @@ -1,5 +1,4 @@ """Test reproduce state for Fan.""" - import pytest from homeassistant.components.fan import ( @@ -11,13 +10,15 @@ from homeassistant.components.fan import ( DIRECTION_FORWARD, DIRECTION_REVERSE, ) -from homeassistant.core import State +from homeassistant.core import HomeAssistant, State from homeassistant.helpers.state import async_reproduce_state from tests.common import async_mock_service -async def test_reproducing_states(hass, caplog): +async def test_reproducing_states( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test reproducing Fan states.""" hass.states.async_set("fan.entity_off", "off", {}) hass.states.async_set("fan.entity_on", "on", {}) @@ -245,7 +246,7 @@ async def test_modern_turn_on_percentage_from_different_speed(hass, start_state) assert len(set_preset_mode) == 0 -async def test_modern_turn_on_percentage_from_same_speed(hass): +async def test_modern_turn_on_percentage_from_same_speed(hass: HomeAssistant) -> None: """Test modern fan state reproduction, turning on with the same percentage as in the state.""" hass.states.async_set(MODERN_FAN_ENTITY, "off", MODERN_FAN_OFF_PERCENTAGE15_STATE) @@ -311,7 +312,7 @@ async def test_modern_turn_on_preset_mode_from_different_speed(hass, start_state assert len(set_preset_mode) == 0 -async def test_modern_turn_on_preset_mode_from_same_speed(hass): +async def test_modern_turn_on_preset_mode_from_same_speed(hass: HomeAssistant) -> None: """Test modern fan state reproduction, turning on with the same preset mode as in the state.""" hass.states.async_set( MODERN_FAN_ENTITY, "off", MODERN_FAN_OFF_PPRESET_MODE_AUTO_STATE @@ -457,7 +458,7 @@ async def test_modern_to_percentage(hass, start_state): assert len(set_preset_mode) == 0 -async def test_modern_direction(hass): +async def test_modern_direction(hass: HomeAssistant) -> None: """Test modern fan state reproduction, switching only direction state.""" hass.states.async_set(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE) diff --git a/tests/components/feedreader/test_init.py b/tests/components/feedreader/test_init.py index be5ebb42a6d..92ae43c090a 100644 --- a/tests/components/feedreader/test_init.py +++ b/tests/components/feedreader/test_init.py @@ -13,6 +13,7 @@ from homeassistant.components.feedreader import ( EVENT_FEEDREADER, ) from homeassistant.const import CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_START +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -76,7 +77,7 @@ def fixture_feed_storage(): yield -async def test_setup_one_feed(hass): +async def test_setup_one_feed(hass: HomeAssistant) -> None: """Test the general setup of this component.""" with patch( "homeassistant.components.feedreader.track_time_interval" @@ -87,7 +88,7 @@ async def test_setup_one_feed(hass): track_method.assert_called_once_with(hass, mock.ANY, DEFAULT_SCAN_INTERVAL) -async def test_setup_scan_interval(hass): +async def test_setup_scan_interval(hass: HomeAssistant) -> None: """Test the setup of this component with scan interval.""" with patch( "homeassistant.components.feedreader.track_time_interval" @@ -98,7 +99,7 @@ async def test_setup_scan_interval(hass): track_method.assert_called_once_with(hass, mock.ANY, timedelta(seconds=60)) -async def test_setup_max_entries(hass): +async def test_setup_max_entries(hass: HomeAssistant) -> None: """Test the setup of this component with max entries.""" assert await async_setup_component(hass, feedreader.DOMAIN, VALID_CONFIG_3) await hass.async_block_till_done() diff --git a/tests/components/ffmpeg/test_init.py b/tests/components/ffmpeg/test_init.py index e1730ffdabb..521ac732e5b 100644 --- a/tests/components/ffmpeg/test_init.py +++ b/tests/components/ffmpeg/test_init.py @@ -9,7 +9,7 @@ from homeassistant.components.ffmpeg import ( SERVICE_STOP, ) from homeassistant.const import ATTR_ENTITY_ID -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback from homeassistant.setup import async_setup_component, setup_component from tests.common import assert_setup_component, get_test_home_assistant @@ -99,7 +99,7 @@ class TestFFmpegSetup: assert self.hass.services.has_service(ffmpeg.DOMAIN, "restart") -async def test_setup_component_test_register(hass): +async def test_setup_component_test_register(hass: HomeAssistant) -> None: """Set up ffmpeg component test register.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -112,7 +112,7 @@ async def test_setup_component_test_register(hass): assert hass.bus.async_listen_once.call_count == 2 -async def test_setup_component_test_register_no_startup(hass): +async def test_setup_component_test_register_no_startup(hass: HomeAssistant) -> None: """Set up ffmpeg component test register without startup.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -125,7 +125,7 @@ async def test_setup_component_test_register_no_startup(hass): assert hass.bus.async_listen_once.call_count == 1 -async def test_setup_component_test_service_start(hass): +async def test_setup_component_test_service_start(hass: HomeAssistant) -> None: """Set up ffmpeg component test service start.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -139,7 +139,7 @@ async def test_setup_component_test_service_start(hass): assert ffmpeg_dev.called_start -async def test_setup_component_test_service_stop(hass): +async def test_setup_component_test_service_stop(hass: HomeAssistant) -> None: """Set up ffmpeg component test service stop.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -153,7 +153,7 @@ async def test_setup_component_test_service_stop(hass): assert ffmpeg_dev.called_stop -async def test_setup_component_test_service_restart(hass): +async def test_setup_component_test_service_restart(hass: HomeAssistant) -> None: """Set up ffmpeg component test service restart.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -168,7 +168,9 @@ async def test_setup_component_test_service_restart(hass): assert ffmpeg_dev.called_start -async def test_setup_component_test_service_start_with_entity(hass): +async def test_setup_component_test_service_start_with_entity( + hass: HomeAssistant, +) -> None: """Set up ffmpeg component test service start.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -183,7 +185,7 @@ async def test_setup_component_test_service_start_with_entity(hass): assert ffmpeg_dev.called_entities == ["test.ffmpeg_device"] -async def test_async_get_image_with_width_height(hass): +async def test_async_get_image_with_width_height(hass: HomeAssistant) -> None: """Test fetching an image with a specific width and height.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -200,7 +202,9 @@ async def test_async_get_image_with_width_height(hass): ] -async def test_async_get_image_with_extra_cmd_overlapping_width_height(hass): +async def test_async_get_image_with_extra_cmd_overlapping_width_height( + hass: HomeAssistant, +) -> None: """Test fetching an image with and extra_cmd with width and height and a specific width and height.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) @@ -219,7 +223,7 @@ async def test_async_get_image_with_extra_cmd_overlapping_width_height(hass): ] -async def test_async_get_image_with_extra_cmd_width_height(hass): +async def test_async_get_image_with_extra_cmd_width_height(hass: HomeAssistant) -> None: """Test fetching an image with and extra_cmd and a specific width and height.""" with assert_setup_component(1): await async_setup_component(hass, ffmpeg.DOMAIN, {ffmpeg.DOMAIN: {}}) diff --git a/tests/components/fibaro/test_config_flow.py b/tests/components/fibaro/test_config_flow.py index 080cc3f4458..1e863edbd9a 100644 --- a/tests/components/fibaro/test_config_flow.py +++ b/tests/components/fibaro/test_config_flow.py @@ -9,6 +9,7 @@ from homeassistant.components.fibaro import DOMAIN from homeassistant.components.fibaro.config_flow import _normalize_url from homeassistant.components.fibaro.const import CONF_IMPORT_PLUGINS from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -61,7 +62,7 @@ def fibaro_client_fixture(): yield -async def test_config_flow_user_initiated_success(hass): +async def test_config_flow_user_initiated_success(hass: HomeAssistant) -> None: """Successful flow manually initialized by the user.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -98,7 +99,7 @@ async def test_config_flow_user_initiated_success(hass): } -async def test_config_flow_user_initiated_connect_failure(hass): +async def test_config_flow_user_initiated_connect_failure(hass: HomeAssistant) -> None: """Connect failure in flow manually initialized by the user.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -127,7 +128,7 @@ async def test_config_flow_user_initiated_connect_failure(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_config_flow_user_initiated_auth_failure(hass): +async def test_config_flow_user_initiated_auth_failure(hass: HomeAssistant) -> None: """Authentication failure in flow manually initialized by the user.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -156,7 +157,9 @@ async def test_config_flow_user_initiated_auth_failure(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_config_flow_user_initiated_unknown_failure_1(hass): +async def test_config_flow_user_initiated_unknown_failure_1( + hass: HomeAssistant, +) -> None: """Unknown failure in flow manually initialized by the user.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -185,7 +188,9 @@ async def test_config_flow_user_initiated_unknown_failure_1(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_config_flow_user_initiated_unknown_failure_2(hass): +async def test_config_flow_user_initiated_unknown_failure_2( + hass: HomeAssistant, +) -> None: """Unknown failure in flow manually initialized by the user.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -209,7 +214,7 @@ async def test_config_flow_user_initiated_unknown_failure_2(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_config_flow_import(hass): +async def test_config_flow_import(hass: HomeAssistant) -> None: """Test for importing config from configuration.yaml.""" login_mock = Mock() login_mock.get.return_value = Mock(status=True) @@ -240,7 +245,7 @@ async def test_config_flow_import(hass): } -async def test_reauth_success(hass): +async def test_reauth_success(hass: HomeAssistant) -> None: """Successful reauth flow initialized by the user.""" mock_config = MockConfigEntry( domain=DOMAIN, @@ -283,7 +288,7 @@ async def test_reauth_success(hass): assert result["reason"] == "reauth_successful" -async def test_reauth_connect_failure(hass): +async def test_reauth_connect_failure(hass: HomeAssistant) -> None: """Successful reauth flow initialized by the user.""" mock_config = MockConfigEntry( domain=DOMAIN, @@ -324,7 +329,7 @@ async def test_reauth_connect_failure(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_reauth_auth_failure(hass): +async def test_reauth_auth_failure(hass: HomeAssistant) -> None: """Successful reauth flow initialized by the user.""" mock_config = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/fido/test_sensor.py b/tests/components/fido/test_sensor.py index 13d8515f8f2..d51da841b0a 100644 --- a/tests/components/fido/test_sensor.py +++ b/tests/components/fido/test_sensor.py @@ -3,9 +3,11 @@ import logging from unittest.mock import MagicMock, patch from pyfido.client import PyFidoError +import pytest from homeassistant.bootstrap import async_setup_component from homeassistant.components.fido import sensor as fido +from homeassistant.core import HomeAssistant from tests.common import assert_setup_component @@ -60,7 +62,7 @@ async def test_fido_sensor(event_loop, hass): assert state.state == "100.33" -async def test_error(hass, caplog): +async def test_error(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None: """Test the Fido sensor errors.""" caplog.set_level(logging.ERROR) diff --git a/tests/components/fireservicerota/test_config_flow.py b/tests/components/fireservicerota/test_config_flow.py index a26f8030513..ace0532f1f7 100644 --- a/tests/components/fireservicerota/test_config_flow.py +++ b/tests/components/fireservicerota/test_config_flow.py @@ -6,6 +6,7 @@ from pyfireservicerota import InvalidAuthError from homeassistant import config_entries, data_entry_flow from homeassistant.components.fireservicerota.const import DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -37,7 +38,7 @@ MOCK_TOKEN_INFO = { } -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -46,7 +47,7 @@ async def test_show_form(hass): assert result["step_id"] == "user" -async def test_abort_if_already_setup(hass): +async def test_abort_if_already_setup(hass: HomeAssistant) -> None: """Test abort if already setup.""" entry = MockConfigEntry( domain=DOMAIN, data=MOCK_CONF, unique_id=MOCK_CONF[CONF_USERNAME] @@ -59,7 +60,7 @@ async def test_abort_if_already_setup(hass): assert result["reason"] == "already_configured" -async def test_invalid_credentials(hass): +async def test_invalid_credentials(hass: HomeAssistant) -> None: """Test that invalid credentials throws an error.""" with patch( @@ -72,7 +73,7 @@ async def test_invalid_credentials(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_step_user(hass): +async def test_step_user(hass: HomeAssistant) -> None: """Test the start of the config flow.""" with patch( @@ -108,7 +109,7 @@ async def test_step_user(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_reauth(hass): +async def test_reauth(hass: HomeAssistant) -> None: """Test the start of the config flow.""" entry = MockConfigEntry( domain=DOMAIN, data=MOCK_CONF, unique_id=MOCK_CONF[CONF_USERNAME] diff --git a/tests/components/flic/test_binary_sensor.py b/tests/components/flic/test_binary_sensor.py index 463dbf4a9d7..41d2bf97c8e 100644 --- a/tests/components/flic/test_binary_sensor.py +++ b/tests/components/flic/test_binary_sensor.py @@ -1,6 +1,7 @@ """Tests for Flic button integration.""" from unittest import mock +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component @@ -28,7 +29,7 @@ class _MockFlicClient: self.channel = channel -async def test_button_uid(hass): +async def test_button_uid(hass: HomeAssistant) -> None: """Test UID assignment for Flic buttons.""" address_to_name = { "80:e4:da:78:6e:11": "binary_sensor.flic_80e4da786e11", diff --git a/tests/components/flick_electric/test_config_flow.py b/tests/components/flick_electric/test_config_flow.py index ad6f32c5611..9f212b2a1a9 100644 --- a/tests/components/flick_electric/test_config_flow.py +++ b/tests/components/flick_electric/test_config_flow.py @@ -7,6 +7,7 @@ from pyflick.authentication import AuthException from homeassistant import config_entries, data_entry_flow from homeassistant.components.flick_electric.const import DOMAIN from homeassistant.const import CONF_PASSWORD, CONF_USERNAME +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -21,7 +22,7 @@ async def _flow_submit(hass): ) -async def test_form(hass): +async def test_form(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( @@ -49,7 +50,7 @@ async def test_form(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_form_duplicate_login(hass): +async def test_form_duplicate_login(hass: HomeAssistant) -> None: """Test uniqueness of username.""" entry = MockConfigEntry( domain=DOMAIN, @@ -69,7 +70,7 @@ async def test_form_duplicate_login(hass): assert result["reason"] == "already_configured" -async def test_form_invalid_auth(hass): +async def test_form_invalid_auth(hass: HomeAssistant) -> None: """Test we handle invalid auth.""" with patch( "homeassistant.components.flick_electric.config_flow.SimpleFlickAuth.async_get_access_token", @@ -81,7 +82,7 @@ async def test_form_invalid_auth(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_form_cannot_connect(hass): +async def test_form_cannot_connect(hass: HomeAssistant) -> None: """Test we handle cannot connect error.""" with patch( "homeassistant.components.flick_electric.config_flow.SimpleFlickAuth.async_get_access_token", @@ -93,7 +94,7 @@ async def test_form_cannot_connect(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_form_generic_exception(hass): +async def test_form_generic_exception(hass: HomeAssistant) -> None: """Test we handle cannot connect error.""" with patch( "homeassistant.components.flick_electric.config_flow.SimpleFlickAuth.async_get_access_token", diff --git a/tests/components/flipr/test_config_flow.py b/tests/components/flipr/test_config_flow.py index 484cba2f4f4..68ad938654a 100644 --- a/tests/components/flipr/test_config_flow.py +++ b/tests/components/flipr/test_config_flow.py @@ -7,6 +7,7 @@ from requests.exceptions import HTTPError, Timeout from homeassistant import config_entries, data_entry_flow from homeassistant.components.flipr.const import CONF_FLIPR_ID, DOMAIN from homeassistant.const import CONF_EMAIL, CONF_PASSWORD +from homeassistant.core import HomeAssistant @pytest.fixture(name="mock_setup") @@ -19,7 +20,7 @@ def mock_setups(): yield -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/flo/test_config_flow.py b/tests/components/flo/test_config_flow.py index b7c6e0d4acb..4d93c748710 100644 --- a/tests/components/flo/test_config_flow.py +++ b/tests/components/flo/test_config_flow.py @@ -7,9 +7,12 @@ from unittest.mock import patch from homeassistant import config_entries from homeassistant.components.flo.const import DOMAIN from homeassistant.const import CONTENT_TYPE_JSON +from homeassistant.core import HomeAssistant from .common import TEST_EMAIL_ADDRESS, TEST_PASSWORD, TEST_TOKEN, TEST_USER_ID +from tests.test_util.aiohttp import AiohttpClientMocker + async def test_form(hass, aioclient_mock_fixture): """Test we get the form.""" @@ -34,7 +37,9 @@ async def test_form(hass, aioclient_mock_fixture): assert len(mock_setup_entry.mock_calls) == 1 -async def test_form_cannot_connect(hass, aioclient_mock): +async def test_form_cannot_connect( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test we handle cannot connect error.""" now = round(time.time()) # Mocks a failed login response for flo. diff --git a/tests/components/flume/test_config_flow.py b/tests/components/flume/test_config_flow.py index 4ba7becc147..f5315e07043 100644 --- a/tests/components/flume/test_config_flow.py +++ b/tests/components/flume/test_config_flow.py @@ -11,6 +11,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, ) +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -21,7 +22,7 @@ def _get_mocked_flume_device_list(): return flume_device_list_mock -async def test_form(hass): +async def test_form(hass: HomeAssistant) -> None: """Test we get the form and can setup from user input.""" result = await hass.config_entries.flow.async_init( @@ -64,7 +65,7 @@ async def test_form(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_form_invalid_auth(hass): +async def test_form_invalid_auth(hass: HomeAssistant) -> None: """Test we handle invalid auth.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -91,7 +92,7 @@ async def test_form_invalid_auth(hass): assert result2["errors"] == {"password": "invalid_auth"} -async def test_form_cannot_connect(hass): +async def test_form_cannot_connect(hass: HomeAssistant) -> None: """Test we handle cannot connect error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -117,7 +118,7 @@ async def test_form_cannot_connect(hass): assert result2["errors"] == {"base": "cannot_connect"} -async def test_reauth(hass): +async def test_reauth(hass: HomeAssistant) -> None: """Test we can reauth.""" entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/flux/test_switch.py b/tests/components/flux/test_switch.py index d79b920db5f..2628f34966b 100644 --- a/tests/components/flux/test_switch.py +++ b/tests/components/flux/test_switch.py @@ -12,7 +12,7 @@ from homeassistant.const import ( STATE_ON, SUN_EVENT_SUNRISE, ) -from homeassistant.core import State +from homeassistant.core import HomeAssistant, State from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -30,7 +30,7 @@ def set_utc(hass): hass.config.set_time_zone("UTC") -async def test_valid_config(hass): +async def test_valid_config(hass: HomeAssistant) -> None: """Test configuration.""" assert await async_setup_component( hass, @@ -49,7 +49,7 @@ async def test_valid_config(hass): assert state.state == "off" -async def test_restore_state_last_on(hass): +async def test_restore_state_last_on(hass: HomeAssistant) -> None: """Test restoring state when the last state is on.""" mock_restore_cache(hass, [State("switch.flux", "on")]) @@ -71,7 +71,7 @@ async def test_restore_state_last_on(hass): assert state.state == "on" -async def test_restore_state_last_off(hass): +async def test_restore_state_last_off(hass: HomeAssistant) -> None: """Test restoring state when the last state is off.""" mock_restore_cache(hass, [State("switch.flux", "off")]) @@ -93,7 +93,7 @@ async def test_restore_state_last_off(hass): assert state.state == "off" -async def test_valid_config_with_info(hass): +async def test_valid_config_with_info(hass: HomeAssistant) -> None: """Test configuration.""" assert await async_setup_component( hass, @@ -114,7 +114,7 @@ async def test_valid_config_with_info(hass): await hass.async_block_till_done() -async def test_valid_config_no_name(hass): +async def test_valid_config_no_name(hass: HomeAssistant) -> None: """Test configuration.""" with assert_setup_component(1, "switch"): assert await async_setup_component( @@ -125,7 +125,7 @@ async def test_valid_config_no_name(hass): await hass.async_block_till_done() -async def test_invalid_config_no_lights(hass): +async def test_invalid_config_no_lights(hass: HomeAssistant) -> None: """Test configuration.""" with assert_setup_component(0, "switch"): assert await async_setup_component( diff --git a/tests/components/flux_led/test_config_flow.py b/tests/components/flux_led/test_config_flow.py index 76f83ad62ef..3111ea09d26 100644 --- a/tests/components/flux_led/test_config_flow.py +++ b/tests/components/flux_led/test_config_flow.py @@ -372,7 +372,7 @@ async def test_manual_no_discovery_data(hass: HomeAssistant): } -async def test_discovered_by_discovery_and_dhcp(hass): +async def test_discovered_by_discovery_and_dhcp(hass: HomeAssistant) -> None: """Test we get the form with discovery and abort for dhcp source when we get both.""" with _patch_discovery(), _patch_wifibulb(): @@ -410,7 +410,7 @@ async def test_discovered_by_discovery_and_dhcp(hass): assert result3["reason"] == "already_in_progress" -async def test_discovered_by_discovery(hass): +async def test_discovered_by_discovery(hass: HomeAssistant) -> None: """Test we can setup when discovered from discovery.""" with _patch_discovery(), _patch_wifibulb(): @@ -448,7 +448,7 @@ async def test_discovered_by_discovery(hass): assert mock_async_setup_entry.called -async def test_discovered_by_dhcp_udp_responds(hass): +async def test_discovered_by_dhcp_udp_responds(hass: HomeAssistant) -> None: """Test we can setup when discovered from dhcp but with udp response.""" with _patch_discovery(), _patch_wifibulb(): @@ -484,7 +484,7 @@ async def test_discovered_by_dhcp_udp_responds(hass): assert mock_async_setup_entry.called -async def test_discovered_by_dhcp_no_udp_response(hass): +async def test_discovered_by_dhcp_no_udp_response(hass: HomeAssistant) -> None: """Test we can setup when discovered from dhcp but no udp response.""" with _patch_discovery(no_device=True), _patch_wifibulb(): @@ -514,7 +514,9 @@ async def test_discovered_by_dhcp_no_udp_response(hass): assert mock_async_setup_entry.called -async def test_discovered_by_dhcp_partial_udp_response_fallback_tcp(hass): +async def test_discovered_by_dhcp_partial_udp_response_fallback_tcp( + hass: HomeAssistant, +) -> None: """Test we can setup when discovered from dhcp but part of the udp response is missing.""" with _patch_discovery(no_device=True), _patch_wifibulb(): @@ -545,7 +547,9 @@ async def test_discovered_by_dhcp_partial_udp_response_fallback_tcp(hass): assert mock_async_setup_entry.called -async def test_discovered_by_dhcp_no_udp_response_or_tcp_response(hass): +async def test_discovered_by_dhcp_no_udp_response_or_tcp_response( + hass: HomeAssistant, +) -> None: """Test we can setup when discovered from dhcp but no udp response or tcp response.""" with _patch_discovery(no_device=True), _patch_wifibulb(no_device=True): @@ -584,7 +588,9 @@ async def test_discovered_by_dhcp_or_discovery_adds_missing_unique_id( assert config_entry.unique_id == MAC_ADDRESS -async def test_mac_address_off_by_one_updated_via_discovery(hass): +async def test_mac_address_off_by_one_updated_via_discovery( + hass: HomeAssistant, +) -> None: """Test the mac address is updated when its off by one from integration discovery.""" config_entry = MockConfigEntry( domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS_ONE_OFF @@ -605,7 +611,9 @@ async def test_mac_address_off_by_one_updated_via_discovery(hass): assert config_entry.unique_id == MAC_ADDRESS -async def test_mac_address_off_by_one_not_updated_from_dhcp(hass): +async def test_mac_address_off_by_one_not_updated_from_dhcp( + hass: HomeAssistant, +) -> None: """Test the mac address is NOT updated when its off by one from dhcp discovery.""" config_entry = MockConfigEntry( domain=DOMAIN, data={CONF_HOST: IP_ADDRESS}, unique_id=MAC_ADDRESS_ONE_OFF diff --git a/tests/components/flux_led/test_diagnostics.py b/tests/components/flux_led/test_diagnostics.py index c641d88c8e2..4bc53440632 100644 --- a/tests/components/flux_led/test_diagnostics.py +++ b/tests/components/flux_led/test_diagnostics.py @@ -1,5 +1,6 @@ """Test flux_led diagnostics.""" from homeassistant.components.flux_led.const import DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from . import ( @@ -10,9 +11,12 @@ from . import ( ) from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator -async def test_diagnostics(hass, hass_client): +async def test_diagnostics( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> None: """Test generating diagnostics for a config entry.""" entry = _mock_config_entry_for_bulb(hass) bulb = _mocked_bulb() diff --git a/tests/components/folder/test_sensor.py b/tests/components/folder/test_sensor.py index f2d70b31b8f..c45fe2ae5f5 100644 --- a/tests/components/folder/test_sensor.py +++ b/tests/components/folder/test_sensor.py @@ -2,6 +2,7 @@ import os from homeassistant.components.folder.sensor import CONF_FOLDER_PATHS +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component CWD = os.path.join(os.path.dirname(__file__)) @@ -24,14 +25,14 @@ def remove_test_file(): os.rmdir(TEST_DIR) -async def test_invalid_path(hass): +async def test_invalid_path(hass: HomeAssistant) -> None: """Test that an invalid path is caught.""" config = {"sensor": {"platform": "folder", CONF_FOLDER_PATHS: "invalid_path"}} assert await async_setup_component(hass, "sensor", config) assert len(hass.states.async_entity_ids("sensor")) == 0 -async def test_valid_path(hass): +async def test_valid_path(hass: HomeAssistant) -> None: """Test for a valid path.""" if not os.path.isdir(TEST_DIR): os.mkdir(TEST_DIR) diff --git a/tests/components/folder_watcher/test_init.py b/tests/components/folder_watcher/test_init.py index 0210dd507ca..b09e060725f 100644 --- a/tests/components/folder_watcher/test_init.py +++ b/tests/components/folder_watcher/test_init.py @@ -4,10 +4,11 @@ from types import SimpleNamespace from unittest.mock import Mock, patch from homeassistant.components import folder_watcher +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -async def test_invalid_path_setup(hass): +async def test_invalid_path_setup(hass: HomeAssistant) -> None: """Test that an invalid path is not set up.""" assert not await async_setup_component( hass, @@ -16,7 +17,7 @@ async def test_invalid_path_setup(hass): ) -async def test_valid_path_setup(hass): +async def test_valid_path_setup(hass: HomeAssistant) -> None: """Test that a valid path is setup.""" cwd = os.path.join(os.path.dirname(__file__)) hass.config.allowlist_external_dirs = {cwd} diff --git a/tests/components/foobot/test_sensor.py b/tests/components/foobot/test_sensor.py index 3b02df55bf4..59fcde57a06 100644 --- a/tests/components/foobot/test_sensor.py +++ b/tests/components/foobot/test_sensor.py @@ -1,5 +1,4 @@ """The tests for the Foobot sensor platform.""" - import asyncio from http import HTTPStatus import re @@ -16,10 +15,12 @@ from homeassistant.const import ( PERCENTAGE, UnitOfTemperature, ) +from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady from homeassistant.setup import async_setup_component from tests.common import load_fixture +from tests.test_util.aiohttp import AiohttpClientMocker VALID_CONFIG = { "platform": "foobot", @@ -28,7 +29,9 @@ VALID_CONFIG = { } -async def test_default_setup(hass, aioclient_mock): +async def test_default_setup( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test the default setup.""" aioclient_mock.get( re.compile("api.foobot.io/v2/owner/.*"), @@ -56,7 +59,9 @@ async def test_default_setup(hass, aioclient_mock): assert state.attributes.get("unit_of_measurement") == value[1] -async def test_setup_timeout_error(hass, aioclient_mock): +async def test_setup_timeout_error( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Expected failures caused by a timeout in API response.""" fake_async_add_entities = MagicMock() @@ -67,7 +72,9 @@ async def test_setup_timeout_error(hass, aioclient_mock): await foobot.async_setup_platform(hass, VALID_CONFIG, fake_async_add_entities) -async def test_setup_permanent_error(hass, aioclient_mock): +async def test_setup_permanent_error( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Expected failures caused by permanent errors in API response.""" fake_async_add_entities = MagicMock() @@ -80,7 +87,9 @@ async def test_setup_permanent_error(hass, aioclient_mock): assert result is None -async def test_setup_temporary_error(hass, aioclient_mock): +async def test_setup_temporary_error( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Expected failures caused by temporary errors in API response.""" fake_async_add_entities = MagicMock() diff --git a/tests/components/forked_daapd/test_config_flow.py b/tests/components/forked_daapd/test_config_flow.py index 328f47a0edf..85230d85ebb 100644 --- a/tests/components/forked_daapd/test_config_flow.py +++ b/tests/components/forked_daapd/test_config_flow.py @@ -14,6 +14,7 @@ from homeassistant.components.forked_daapd.const import ( ) from homeassistant.config_entries import SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -52,7 +53,7 @@ def config_entry_fixture(): ) -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER} @@ -131,7 +132,7 @@ async def test_config_flow_no_websocket(hass, config_entry): assert result["type"] == data_entry_flow.FlowResultType.FORM -async def test_config_flow_zeroconf_invalid(hass): +async def test_config_flow_zeroconf_invalid(hass: HomeAssistant) -> None: """Test that an invalid zeroconf entry doesn't work.""" # test with no discovery properties discovery_info = zeroconf.ZeroconfServiceInfo( @@ -195,7 +196,7 @@ async def test_config_flow_zeroconf_invalid(hass): assert result["reason"] == "not_forked_daapd" -async def test_config_flow_zeroconf_valid(hass): +async def test_config_flow_zeroconf_valid(hass: HomeAssistant) -> None: """Test that a valid zeroconf entry works.""" discovery_info = zeroconf.ZeroconfServiceInfo( host="192.168.1.1", diff --git a/tests/components/foscam/test_config_flow.py b/tests/components/foscam/test_config_flow.py index e8bdb6900f2..49bffe491af 100644 --- a/tests/components/foscam/test_config_flow.py +++ b/tests/components/foscam/test_config_flow.py @@ -10,6 +10,7 @@ from libpyfoscam.foscam import ( from homeassistant import config_entries, data_entry_flow from homeassistant.components.foscam import config_flow +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -74,7 +75,7 @@ def setup_mock_foscam_camera(mock_foscam_camera): mock_foscam_camera.side_effect = configure_mock_on_init -async def test_user_valid(hass): +async def test_user_valid(hass: HomeAssistant) -> None: """Test valid config from user input.""" result = await hass.config_entries.flow.async_init( @@ -105,7 +106,7 @@ async def test_user_valid(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_user_invalid_auth(hass): +async def test_user_invalid_auth(hass: HomeAssistant) -> None: """Test we handle invalid auth from user input.""" result = await hass.config_entries.flow.async_init( @@ -133,7 +134,7 @@ async def test_user_invalid_auth(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_user_cannot_connect(hass): +async def test_user_cannot_connect(hass: HomeAssistant) -> None: """Test we handle cannot connect error from user input.""" result = await hass.config_entries.flow.async_init( @@ -161,7 +162,7 @@ async def test_user_cannot_connect(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_user_invalid_response(hass): +async def test_user_invalid_response(hass: HomeAssistant) -> None: """Test we handle invalid response error from user input.""" result = await hass.config_entries.flow.async_init( @@ -191,7 +192,7 @@ async def test_user_invalid_response(hass): assert result["errors"] == {"base": "invalid_response"} -async def test_user_already_configured(hass): +async def test_user_already_configured(hass: HomeAssistant) -> None: """Test we handle already configured from user input.""" entry = MockConfigEntry( @@ -222,7 +223,7 @@ async def test_user_already_configured(hass): assert result["reason"] == "already_configured" -async def test_user_unknown_exception(hass): +async def test_user_unknown_exception(hass: HomeAssistant) -> None: """Test we handle unknown exceptions from user input.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/freedns/test_init.py b/tests/components/freedns/test_init.py index 1a64aa498e2..9163a8faf2d 100644 --- a/tests/components/freedns/test_init.py +++ b/tests/components/freedns/test_init.py @@ -2,10 +2,12 @@ import pytest from homeassistant.components import freedns +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed +from tests.test_util.aiohttp import AiohttpClientMocker ACCESS_TOKEN = "test_token" UPDATE_INTERVAL = freedns.DEFAULT_INTERVAL @@ -35,7 +37,7 @@ def setup_freedns(hass, aioclient_mock): ) -async def test_setup(hass, aioclient_mock): +async def test_setup(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test setup works if update passes.""" params = {} params[ACCESS_TOKEN] = "" @@ -61,7 +63,9 @@ async def test_setup(hass, aioclient_mock): assert aioclient_mock.call_count == 2 -async def test_setup_fails_if_wrong_token(hass, aioclient_mock): +async def test_setup_fails_if_wrong_token( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup fails if first update fails through wrong token.""" params = {} params[ACCESS_TOKEN] = "" diff --git a/tests/components/freedompro/test_config_flow.py b/tests/components/freedompro/test_config_flow.py index c06e37a0333..6fee3694ec7 100644 --- a/tests/components/freedompro/test_config_flow.py +++ b/tests/components/freedompro/test_config_flow.py @@ -5,6 +5,7 @@ from homeassistant import data_entry_flow from homeassistant.components.freedompro.const import DOMAIN from homeassistant.config_entries import SOURCE_USER from homeassistant.const import CONF_API_KEY +from homeassistant.core import HomeAssistant from .const import DEVICES @@ -13,7 +14,7 @@ VALID_CONFIG = { } -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER} @@ -23,7 +24,7 @@ async def test_show_form(hass): assert result["step_id"] == SOURCE_USER -async def test_invalid_auth(hass): +async def test_invalid_auth(hass: HomeAssistant) -> None: """Test that errors are shown when API key is invalid.""" with patch( "homeassistant.components.freedompro.config_flow.get_list", @@ -41,7 +42,7 @@ async def test_invalid_auth(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_connection_error(hass): +async def test_connection_error(hass: HomeAssistant) -> None: """Test that errors are shown when API key is invalid.""" with patch( "homeassistant.components.freedompro.config_flow.get_list", @@ -59,7 +60,7 @@ async def test_connection_error(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_create_entry(hass): +async def test_create_entry(hass: HomeAssistant) -> None: """Test that the user step works.""" with patch( "homeassistant.components.freedompro.config_flow.get_list", diff --git a/tests/components/freedompro/test_init.py b/tests/components/freedompro/test_init.py index 4e9d9ec197d..5669ccf4bef 100644 --- a/tests/components/freedompro/test_init.py +++ b/tests/components/freedompro/test_init.py @@ -4,6 +4,7 @@ from unittest.mock import patch from homeassistant.components.freedompro.const import DOMAIN from homeassistant.config_entries import ConfigEntryState +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -20,7 +21,7 @@ async def test_async_setup_entry(hass, init_integration): assert state is not None -async def test_config_not_ready(hass): +async def test_config_not_ready(hass: HomeAssistant) -> None: """Test for setup failure if connection to Freedompro is missing.""" entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/fronius/test_config_flow.py b/tests/components/fronius/test_config_flow.py index 9c586352052..182cbea04e0 100644 --- a/tests/components/fronius/test_config_flow.py +++ b/tests/components/fronius/test_config_flow.py @@ -14,6 +14,7 @@ from homeassistant.data_entry_flow import FlowResultType from . import mock_responses from tests.common import MockConfigEntry +from tests.test_util.aiohttp import AiohttpClientMocker @pytest.fixture(autouse=True) @@ -206,7 +207,9 @@ async def test_form_already_existing(hass: HomeAssistant) -> None: assert result2["reason"] == "already_configured" -async def test_form_updates_host(hass, aioclient_mock): +async def test_form_updates_host( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test existing entry gets updated.""" old_host = "http://10.1.0.1" new_host = "http://10.1.0.2" @@ -254,7 +257,7 @@ async def test_form_updates_host(hass, aioclient_mock): } -async def test_dhcp(hass, aioclient_mock): +async def test_dhcp(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test starting a flow from discovery.""" with patch( "homeassistant.components.fronius.config_flow.DHCP_REQUEST_DELAY", 0 @@ -279,7 +282,9 @@ async def test_dhcp(hass, aioclient_mock): } -async def test_dhcp_already_configured(hass, aioclient_mock): +async def test_dhcp_already_configured( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test starting a flow from discovery.""" entry = MockConfigEntry( domain=DOMAIN, @@ -298,7 +303,9 @@ async def test_dhcp_already_configured(hass, aioclient_mock): assert result["reason"] == "already_configured" -async def test_dhcp_invalid(hass, aioclient_mock): +async def test_dhcp_invalid( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test starting a flow from discovery.""" with patch( "homeassistant.components.fronius.config_flow.DHCP_REQUEST_DELAY", 0 diff --git a/tests/components/fronius/test_coordinator.py b/tests/components/fronius/test_coordinator.py index a2368975128..6a25cee6ea0 100644 --- a/tests/components/fronius/test_coordinator.py +++ b/tests/components/fronius/test_coordinator.py @@ -6,14 +6,18 @@ from pyfronius import BadStatusError, FroniusError from homeassistant.components.fronius.coordinator import ( FroniusInverterUpdateCoordinator, ) +from homeassistant.core import HomeAssistant from homeassistant.util import dt from . import mock_responses, setup_fronius_integration from tests.common import async_fire_time_changed +from tests.test_util.aiohttp import AiohttpClientMocker -async def test_adaptive_update_interval(hass, aioclient_mock): +async def test_adaptive_update_interval( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test coordinators changing their update interval when inverter not available.""" with patch("pyfronius.Fronius.current_inverter_data") as mock_inverter_data: mock_responses(aioclient_mock) diff --git a/tests/components/fronius/test_init.py b/tests/components/fronius/test_init.py index bfbd631ff37..0e8b405da44 100644 --- a/tests/components/fronius/test_init.py +++ b/tests/components/fronius/test_init.py @@ -5,11 +5,16 @@ from pyfronius import FroniusError from homeassistant.components.fronius.const import DOMAIN from homeassistant.config_entries import ConfigEntryState +from homeassistant.core import HomeAssistant from . import mock_responses, setup_fronius_integration +from tests.test_util.aiohttp import AiohttpClientMocker -async def test_unload_config_entry(hass, aioclient_mock): + +async def test_unload_config_entry( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test that configuration entry supports unloading.""" mock_responses(aioclient_mock) await setup_fronius_integration(hass) @@ -27,7 +32,9 @@ async def test_unload_config_entry(hass, aioclient_mock): assert not hass.data.get(DOMAIN) -async def test_logger_error(hass, aioclient_mock): +async def test_logger_error( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup when logger reports an error.""" # gen24 dataset will raise FroniusError when logger is called mock_responses(aioclient_mock, fixture_set="gen24") @@ -35,7 +42,9 @@ async def test_logger_error(hass, aioclient_mock): assert config_entry.state is ConfigEntryState.SETUP_RETRY -async def test_inverter_error(hass, aioclient_mock): +async def test_inverter_error( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup when inverter_info reports an error.""" mock_responses(aioclient_mock) with patch( diff --git a/tests/components/fronius/test_sensor.py b/tests/components/fronius/test_sensor.py index 3ed1e37505c..6f7b7793882 100644 --- a/tests/components/fronius/test_sensor.py +++ b/tests/components/fronius/test_sensor.py @@ -6,15 +6,19 @@ from homeassistant.components.fronius.coordinator import ( FroniusPowerFlowUpdateCoordinator, ) from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr from homeassistant.util import dt from . import enable_all_entities, mock_responses, setup_fronius_integration from tests.common import async_fire_time_changed +from tests.test_util.aiohttp import AiohttpClientMocker -async def test_symo_inverter(hass, aioclient_mock): +async def test_symo_inverter( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test Fronius Symo inverter entities.""" def assert_state(entity_id, expected_state): @@ -70,7 +74,9 @@ async def test_symo_inverter(hass, aioclient_mock): assert_state("sensor.symo_20_voltage_ac", 227.90) -async def test_symo_logger(hass, aioclient_mock): +async def test_symo_logger( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test Fronius Symo logger entities.""" def assert_state(entity_id, expected_state): @@ -87,7 +93,9 @@ async def test_symo_logger(hass, aioclient_mock): assert_state("sensor.solarnet_grid_import_tariff", 0.15) -async def test_symo_meter(hass, aioclient_mock): +async def test_symo_meter( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test Fronius Symo meter entities.""" def assert_state(entity_id, expected_state): @@ -138,7 +146,9 @@ async def test_symo_meter(hass, aioclient_mock): assert_state("sensor.smart_meter_63a_voltage_ac_phase_3_1", 398) -async def test_symo_power_flow(hass, aioclient_mock): +async def test_symo_power_flow( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test Fronius Symo power flow entities.""" async_fire_time_changed(hass, dt.utcnow()) @@ -181,7 +191,7 @@ async def test_symo_power_flow(hass, aioclient_mock): assert_state("sensor.solarnet_relative_self_consumption", 100) -async def test_gen24(hass, aioclient_mock): +async def test_gen24(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test Fronius Gen24 inverter entities.""" def assert_state(entity_id, expected_state): @@ -254,7 +264,9 @@ async def test_gen24(hass, aioclient_mock): assert_state("sensor.solarnet_energy_total", 1530193.42) -async def test_gen24_storage(hass, aioclient_mock): +async def test_gen24_storage( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test Fronius Gen24 inverter with BYD battery and Ohmpilot entities.""" def assert_state(entity_id, expected_state): @@ -376,7 +388,9 @@ async def test_gen24_storage(hass, aioclient_mock): assert storage.name == "BYD Battery-Box Premium HV" -async def test_primo_s0(hass, aioclient_mock): +async def test_primo_s0( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test Fronius Primo dual inverter with S0 meter entities.""" def assert_state(entity_id, expected_state): diff --git a/tests/components/frontend/test_init.py b/tests/components/frontend/test_init.py index 6bff327d397..79cda1e0094 100644 --- a/tests/components/frontend/test_init.py +++ b/tests/components/frontend/test_init.py @@ -17,6 +17,7 @@ from homeassistant.components.frontend import ( THEMES_STORAGE_KEY, ) from homeassistant.components.websocket_api.const import TYPE_RESULT +from homeassistant.core import HomeAssistant from homeassistant.loader import async_get_integration from homeassistant.setup import async_setup_component from homeassistant.util import dt @@ -496,13 +497,13 @@ async def test_get_translations_for_single_integration(hass, ws_client): assert msg["result"] == {"resources": {"lang": "nl", "integration": ["http"]}} -async def test_auth_load(hass): +async def test_auth_load(hass: HomeAssistant) -> None: """Test auth component loaded by default.""" frontend = await async_get_integration(hass, "frontend") assert "auth" in frontend.dependencies -async def test_onboarding_load(hass): +async def test_onboarding_load(hass: HomeAssistant) -> None: """Test onboarding component loaded by default.""" frontend = await async_get_integration(hass, "frontend") assert "onboarding" in frontend.dependencies diff --git a/tests/components/gdacs/test_config_flow.py b/tests/components/gdacs/test_config_flow.py index a928f5f5810..d169d753b22 100644 --- a/tests/components/gdacs/test_config_flow.py +++ b/tests/components/gdacs/test_config_flow.py @@ -12,6 +12,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_SCAN_INTERVAL, ) +from homeassistant.core import HomeAssistant @pytest.fixture(name="gdacs_setup", autouse=True) @@ -33,7 +34,7 @@ async def test_duplicate_error(hass, config_entry): assert result["reason"] == "already_configured" -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -42,7 +43,7 @@ async def test_show_form(hass): assert result["step_id"] == "user" -async def test_step_import(hass): +async def test_step_import(hass: HomeAssistant) -> None: """Test that the import step works.""" conf = { CONF_LATITUDE: -41.2, @@ -66,7 +67,7 @@ async def test_step_import(hass): } -async def test_step_user(hass): +async def test_step_user(hass: HomeAssistant) -> None: """Test that the user step works.""" hass.config.latitude = -41.2 hass.config.longitude = 174.7 diff --git a/tests/components/gdacs/test_geo_location.py b/tests/components/gdacs/test_geo_location.py index b7678e557b5..fc20ecd406c 100644 --- a/tests/components/gdacs/test_geo_location.py +++ b/tests/components/gdacs/test_geo_location.py @@ -31,6 +31,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, UnitOfLength, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -43,7 +44,7 @@ from tests.common import async_fire_time_changed CONFIG = {gdacs.DOMAIN: {CONF_RADIUS: 200}} -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test the general setup of the integration.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry( @@ -206,7 +207,7 @@ async def test_setup(hass): assert len(entity_registry.entities) == 1 -async def test_setup_imperial(hass): +async def test_setup_imperial(hass: HomeAssistant) -> None: """Test the setup of the integration using imperial unit system.""" hass.config.units = US_CUSTOMARY_SYSTEM # Set up some mock feed entries for this test. diff --git a/tests/components/gdacs/test_sensor.py b/tests/components/gdacs/test_sensor.py index 8aafbcf864e..da318b1a94d 100644 --- a/tests/components/gdacs/test_sensor.py +++ b/tests/components/gdacs/test_sensor.py @@ -19,6 +19,7 @@ from homeassistant.const import ( CONF_RADIUS, EVENT_HOMEASSISTANT_START, ) +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -29,7 +30,7 @@ from tests.common import async_fire_time_changed CONFIG = {gdacs.DOMAIN: {CONF_RADIUS: 200}} -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test the general setup of the integration.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry( diff --git a/tests/components/generic/test_camera.py b/tests/components/generic/test_camera.py index f41f4c4f592..e043b0f84ef 100644 --- a/tests/components/generic/test_camera.py +++ b/tests/components/generic/test_camera.py @@ -24,9 +24,11 @@ from homeassistant.components.stream.const import CONF_RTSP_TRANSPORT from homeassistant.components.websocket_api.const import TYPE_RESULT from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, CONF_VERIFY_SSL +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import AsyncMock, Mock, MockConfigEntry +from tests.typing import ClientSessionGenerator @respx.mock @@ -465,7 +467,9 @@ async def test_timeout_cancelled(hass, hass_client, fakeimgbytes_png, fakeimgbyt assert await resp.read() == fakeimgbytes_png -async def test_no_still_image_url(hass, hass_client): +async def test_no_still_image_url( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> None: """Test that the component can grab images from stream with no still_image_url.""" assert await async_setup_component( hass, @@ -508,7 +512,7 @@ async def test_no_still_image_url(hass, hass_client): assert await resp.read() == b"stream_keyframe_image" -async def test_frame_interval_property(hass): +async def test_frame_interval_property(hass: HomeAssistant) -> None: """Test that the frame interval is calculated and returned correctly.""" await async_setup_component( diff --git a/tests/components/generic/test_config_flow.py b/tests/components/generic/test_config_flow.py index 5dd7fef018a..2ab777f68d4 100644 --- a/tests/components/generic/test_config_flow.py +++ b/tests/components/generic/test_config_flow.py @@ -650,7 +650,7 @@ async def test_options_template_error(hass, fakeimgbytes_png, mock_create_stream assert result7["errors"] == {"stream_source": "malformed_url"} -async def test_slug(hass, caplog): +async def test_slug(hass: HomeAssistant, caplog: pytest.LogCaptureFixture) -> None: """Test that the slug function generates an error in case of invalid template. Other paths in the slug function are already tested by other tests. diff --git a/tests/components/generic_hygrostat/test_humidifier.py b/tests/components/generic_hygrostat/test_humidifier.py index d93fa605397..643bbb35eeb 100644 --- a/tests/components/generic_hygrostat/test_humidifier.py +++ b/tests/components/generic_hygrostat/test_humidifier.py @@ -24,7 +24,13 @@ from homeassistant.const import ( STATE_UNAVAILABLE, ) import homeassistant.core as ha -from homeassistant.core import DOMAIN as HASS_DOMAIN, CoreState, State, callback +from homeassistant.core import ( + DOMAIN as HASS_DOMAIN, + CoreState, + HomeAssistant, + State, + callback, +) from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -43,7 +49,7 @@ MAX_HUMIDITY = 65 TARGET_HUMIDITY = 42 -async def test_setup_missing_conf(hass): +async def test_setup_missing_conf(hass: HomeAssistant) -> None: """Test set up humidity_control with missing config values.""" config = { "platform": "generic_hygrostat", @@ -55,7 +61,7 @@ async def test_setup_missing_conf(hass): await hass.async_block_till_done() -async def test_valid_conf(hass): +async def test_valid_conf(hass: HomeAssistant) -> None: """Test set up generic_hygrostat with valid config values.""" assert await async_setup_component( hass, @@ -215,7 +221,7 @@ async def setup_comp_2(hass): await hass.async_block_till_done() -async def test_unavailable_state(hass): +async def test_unavailable_state(hass: HomeAssistant) -> None: """Test the setting of defaults to unknown.""" await async_setup_component( hass, @@ -242,7 +248,7 @@ async def test_unavailable_state(hass): assert hass.states.get(ENTITY).state == STATE_OFF -async def test_setup_defaults_to_unknown(hass): +async def test_setup_defaults_to_unknown(hass: HomeAssistant) -> None: """Test the setting of defaults to unknown.""" await async_setup_component( hass, @@ -1184,7 +1190,7 @@ async def test_humidity_change_humidifier_trigger_off_long_enough_2(hass, setup_ assert call.data["entity_id"] == ENT_SWITCH -async def test_float_tolerance_values(hass): +async def test_float_tolerance_values(hass: HomeAssistant) -> None: """Test if dehumidifier does not turn on within floating point tolerance.""" assert await async_setup_component( hass, @@ -1210,7 +1216,7 @@ async def test_float_tolerance_values(hass): assert len(calls) == 0 -async def test_float_tolerance_values_2(hass): +async def test_float_tolerance_values_2(hass: HomeAssistant) -> None: """Test if dehumidifier turns off when oudside of floating point tolerance values.""" assert await async_setup_component( hass, @@ -1239,7 +1245,7 @@ async def test_float_tolerance_values_2(hass): assert call.data["entity_id"] == ENT_SWITCH -async def test_custom_setup_params(hass): +async def test_custom_setup_params(hass: HomeAssistant) -> None: """Test the setup with custom parameters.""" _setup_sensor(hass, 45) await hass.async_block_till_done() @@ -1266,7 +1272,7 @@ async def test_custom_setup_params(hass): assert state.attributes.get("humidity") == TARGET_HUMIDITY -async def test_restore_state(hass): +async def test_restore_state(hass: HomeAssistant) -> None: """Ensure states are restored on startup.""" _setup_sensor(hass, 45) await hass.async_block_till_done() @@ -1304,7 +1310,7 @@ async def test_restore_state(hass): assert state.state == STATE_OFF -async def test_restore_state_target_humidity(hass): +async def test_restore_state_target_humidity(hass: HomeAssistant) -> None: """Ensure restore target humidity if available.""" _setup_sensor(hass, 45) await hass.async_block_till_done() @@ -1342,7 +1348,7 @@ async def test_restore_state_target_humidity(hass): assert state.state == STATE_OFF -async def test_restore_state_and_return_to_normal(hass): +async def test_restore_state_and_return_to_normal(hass: HomeAssistant) -> None: """Ensure retain of target humidity for normal mode.""" _setup_sensor(hass, 55) await hass.async_block_till_done() @@ -1399,7 +1405,7 @@ async def test_restore_state_and_return_to_normal(hass): assert state.state == STATE_OFF -async def test_no_restore_state(hass): +async def test_no_restore_state(hass: HomeAssistant) -> None: """Ensure states are restored on startup if they exist. Allows for graceful reboot. @@ -1440,7 +1446,7 @@ async def test_no_restore_state(hass): assert state.state == STATE_OFF -async def test_restore_state_uncoherence_case(hass): +async def test_restore_state_uncoherence_case(hass: HomeAssistant) -> None: """Test restore from a strange state. - Turn the generic hygrostat off @@ -1501,7 +1507,7 @@ def _mock_restore_cache(hass, humidity=40, state=STATE_OFF): ) -async def test_away_fixed_humidity_mode(hass): +async def test_away_fixed_humidity_mode(hass: HomeAssistant) -> None: """Ensure retain of target humidity for normal mode.""" _setup_sensor(hass, 45) await hass.async_block_till_done() diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index d45c0b248ef..158a793529d 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -33,7 +33,13 @@ from homeassistant.const import ( UnitOfTemperature, ) import homeassistant.core as ha -from homeassistant.core import DOMAIN as HASS_DOMAIN, CoreState, State, callback +from homeassistant.core import ( + DOMAIN as HASS_DOMAIN, + CoreState, + HomeAssistant, + State, + callback, +) from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util @@ -62,7 +68,7 @@ HOT_TOLERANCE = 0.5 TARGET_TEMP_STEP = 0.5 -async def test_setup_missing_conf(hass): +async def test_setup_missing_conf(hass: HomeAssistant) -> None: """Test set up heat_control with missing config values.""" config = { "platform": "generic_thermostat", @@ -73,7 +79,7 @@ async def test_setup_missing_conf(hass): await async_setup_component(hass, "climate", {"climate": config}) -async def test_valid_conf(hass): +async def test_valid_conf(hass: HomeAssistant) -> None: """Test set up generic_thermostat with valid config values.""" assert await async_setup_component( hass, @@ -222,7 +228,7 @@ async def setup_comp_2(hass): await hass.async_block_till_done() -async def test_setup_defaults_to_unknown(hass): +async def test_setup_defaults_to_unknown(hass: HomeAssistant) -> None: """Test the setting of defaults to unknown.""" hass.config.units = METRIC_SYSTEM await async_setup_component( @@ -244,7 +250,7 @@ async def test_setup_defaults_to_unknown(hass): assert hass.states.get(ENTITY).state == HVACMode.OFF -async def test_setup_gets_current_temp_from_sensor(hass): +async def test_setup_gets_current_temp_from_sensor(hass: HomeAssistant) -> None: """Test that current temperature is updated on entity addition.""" hass.config.units = METRIC_SYSTEM _setup_sensor(hass, 18) @@ -403,7 +409,7 @@ async def test_sensor_bad_value(hass, setup_comp_2): assert state.attributes.get("current_temperature") == temp -async def test_sensor_unknown(hass): +async def test_sensor_unknown(hass: HomeAssistant) -> None: """Test when target sensor is Unknown.""" hass.states.async_set("sensor.unknown", STATE_UNKNOWN) assert await async_setup_component( @@ -423,7 +429,7 @@ async def test_sensor_unknown(hass): assert state.attributes.get("current_temperature") is None -async def test_sensor_unavailable(hass): +async def test_sensor_unavailable(hass: HomeAssistant) -> None: """Test when target sensor is Unavailable.""" hass.states.async_set("sensor.unavailable", STATE_UNAVAILABLE) assert await async_setup_component( @@ -1209,7 +1215,7 @@ async def test_precision(hass, setup_comp_9): assert state.attributes.get("target_temp_step") == 0.1 -async def test_custom_setup_params(hass): +async def test_custom_setup_params(hass: HomeAssistant) -> None: """Test the setup with custom parameters.""" result = await async_setup_component( hass, @@ -1272,7 +1278,7 @@ async def test_restore_state(hass, hvac_mode): assert state.state == hvac_mode -async def test_no_restore_state(hass): +async def test_no_restore_state(hass: HomeAssistant) -> None: """Ensure states are restored on startup if they exist. Allows for graceful reboot. @@ -1309,7 +1315,7 @@ async def test_no_restore_state(hass): assert state.state == HVACMode.OFF -async def test_initial_hvac_off_force_heater_off(hass): +async def test_initial_hvac_off_force_heater_off(hass: HomeAssistant) -> None: """Ensure that restored state is coherent with real situation. 'initial_hvac_mode: off' will force HVAC status, but we must be sure @@ -1347,7 +1353,7 @@ async def test_initial_hvac_off_force_heater_off(hass): assert call.data["entity_id"] == ENT_SWITCH -async def test_restore_will_turn_off_(hass): +async def test_restore_will_turn_off_(hass: HomeAssistant) -> None: """Ensure that restored state is coherent with real situation. Thermostat status must trigger heater event if temp raises the target . @@ -1395,7 +1401,7 @@ async def test_restore_will_turn_off_(hass): assert hass.states.get(heater_switch).state == STATE_ON -async def test_restore_will_turn_off_when_loaded_second(hass): +async def test_restore_will_turn_off_when_loaded_second(hass: HomeAssistant) -> None: """Ensure that restored state is coherent with real situation. Switch is not available until after component is loaded @@ -1455,7 +1461,7 @@ async def test_restore_will_turn_off_when_loaded_second(hass): assert call.data["entity_id"] == "input_boolean.test" -async def test_restore_state_uncoherence_case(hass): +async def test_restore_state_uncoherence_case(hass: HomeAssistant) -> None: """Test restore from a strange state. - Turn the generic thermostat off @@ -1511,7 +1517,7 @@ def _mock_restore_cache(hass, temperature=20, hvac_mode=HVACMode.OFF): ) -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Test we can reload.""" assert await async_setup_component( diff --git a/tests/components/geo_json_events/test_geo_location.py b/tests/components/geo_json_events/test_geo_location.py index 193c9bfa090..b79c5f15046 100644 --- a/tests/components/geo_json_events/test_geo_location.py +++ b/tests/components/geo_json_events/test_geo_location.py @@ -22,6 +22,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, UnitOfLength, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import DATA_DISPATCHER from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -58,7 +59,7 @@ def _generate_mock_feed_entry(external_id, title, distance_to_home, coordinates) return feed_entry -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test the general setup of the platform.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 15.5, (-31.0, 150.0)) @@ -155,7 +156,7 @@ async def test_setup(hass): assert len(all_states) == 0 -async def test_setup_with_custom_location(hass): +async def test_setup_with_custom_location(hass: HomeAssistant) -> None: """Test the setup with a custom location.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 2000.5, (-31.1, 150.1)) @@ -187,7 +188,7 @@ async def test_setup_with_custom_location(hass): ) -async def test_setup_race_condition(hass): +async def test_setup_race_condition(hass: HomeAssistant) -> None: """Test a particular race condition experienced.""" # 1. Feed returns 1 entry -> Feed manager creates 1 entity. # 2. Feed returns error -> Feed manager removes 1 entity. diff --git a/tests/components/geo_location/test_init.py b/tests/components/geo_location/test_init.py index f2cb5c6b108..0861cd7cba1 100644 --- a/tests/components/geo_location/test_init.py +++ b/tests/components/geo_location/test_init.py @@ -3,16 +3,17 @@ import pytest from homeassistant.components import geo_location from homeassistant.components.geo_location import GeolocationEvent +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component -async def test_setup_component(hass): +async def test_setup_component(hass: HomeAssistant) -> None: """Simple test setup of component.""" result = await async_setup_component(hass, geo_location.DOMAIN, {}) assert result -async def test_event(hass): +async def test_event(hass: HomeAssistant) -> None: """Simple test of the geolocation event class.""" entity = GeolocationEvent() diff --git a/tests/components/geonetnz_quakes/test_config_flow.py b/tests/components/geonetnz_quakes/test_config_flow.py index 4e00f691884..429160547cd 100644 --- a/tests/components/geonetnz_quakes/test_config_flow.py +++ b/tests/components/geonetnz_quakes/test_config_flow.py @@ -15,6 +15,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_UNIT_SYSTEM, ) +from homeassistant.core import HomeAssistant async def test_duplicate_error(hass, config_entry): @@ -29,7 +30,7 @@ async def test_duplicate_error(hass, config_entry): assert result["reason"] == "already_configured" -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -38,7 +39,7 @@ async def test_show_form(hass): assert result["step_id"] == "user" -async def test_step_import(hass): +async def test_step_import(hass: HomeAssistant) -> None: """Test that the import step works.""" conf = { CONF_LATITUDE: -41.2, @@ -69,7 +70,7 @@ async def test_step_import(hass): } -async def test_step_user(hass): +async def test_step_user(hass: HomeAssistant) -> None: """Test that the user step works.""" hass.config.latitude = -41.2 hass.config.longitude = 174.7 diff --git a/tests/components/geonetnz_quakes/test_geo_location.py b/tests/components/geonetnz_quakes/test_geo_location.py index 2f58a7fd095..19c85be0d9d 100644 --- a/tests/components/geonetnz_quakes/test_geo_location.py +++ b/tests/components/geonetnz_quakes/test_geo_location.py @@ -25,6 +25,7 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, UnitOfLength, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -37,7 +38,7 @@ from tests.common import async_fire_time_changed CONFIG = {geonetnz_quakes.DOMAIN: {CONF_RADIUS: 200}} -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test the general setup of the integration.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry( @@ -169,7 +170,7 @@ async def test_setup(hass): assert len(entity_registry.entities) == 1 -async def test_setup_imperial(hass): +async def test_setup_imperial(hass: HomeAssistant) -> None: """Test the setup of the integration using imperial unit system.""" hass.config.units = US_CUSTOMARY_SYSTEM # Set up some mock feed entries for this test. diff --git a/tests/components/geonetnz_quakes/test_sensor.py b/tests/components/geonetnz_quakes/test_sensor.py index 9221c2fe848..253d44ee9ee 100644 --- a/tests/components/geonetnz_quakes/test_sensor.py +++ b/tests/components/geonetnz_quakes/test_sensor.py @@ -20,6 +20,7 @@ from homeassistant.const import ( CONF_RADIUS, EVENT_HOMEASSISTANT_START, ) +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -30,7 +31,7 @@ from tests.common import async_fire_time_changed CONFIG = {geonetnz_quakes.DOMAIN: {CONF_RADIUS: 200}} -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test the general setup of the integration.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry( diff --git a/tests/components/geonetnz_volcano/test_config_flow.py b/tests/components/geonetnz_volcano/test_config_flow.py index a4e1f0587b8..a1c1d4e4fee 100644 --- a/tests/components/geonetnz_volcano/test_config_flow.py +++ b/tests/components/geonetnz_volcano/test_config_flow.py @@ -11,6 +11,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_UNIT_SYSTEM, ) +from homeassistant.core import HomeAssistant async def test_duplicate_error(hass, config_entry): @@ -25,7 +26,7 @@ async def test_duplicate_error(hass, config_entry): assert result["errors"] == {"base": "already_configured"} -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" flow = config_flow.GeonetnzVolcanoFlowHandler() flow.hass = hass @@ -36,7 +37,7 @@ async def test_show_form(hass): assert result["step_id"] == "user" -async def test_step_import(hass): +async def test_step_import(hass: HomeAssistant) -> None: """Test that the import step works.""" conf = { CONF_LATITUDE: -41.2, @@ -66,7 +67,7 @@ async def test_step_import(hass): } -async def test_step_user(hass): +async def test_step_user(hass: HomeAssistant) -> None: """Test that the user step works.""" hass.config.latitude = -41.2 hass.config.longitude = 174.7 diff --git a/tests/components/geonetnz_volcano/test_sensor.py b/tests/components/geonetnz_volcano/test_sensor.py index 9b53cb9cc9b..a237fb2c314 100644 --- a/tests/components/geonetnz_volcano/test_sensor.py +++ b/tests/components/geonetnz_volcano/test_sensor.py @@ -21,6 +21,7 @@ from homeassistant.const import ( CONF_RADIUS, EVENT_HOMEASSISTANT_START, ) +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM @@ -32,7 +33,7 @@ from tests.common import async_fire_time_changed CONFIG = {geonetnz_volcano.DOMAIN: {CONF_RADIUS: 200}} -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test the general setup of the integration.""" # Set up some mock feed entries for this test. mock_entry_1 = _generate_mock_feed_entry( @@ -148,7 +149,7 @@ async def test_setup(hass): ) -async def test_setup_imperial(hass): +async def test_setup_imperial(hass: HomeAssistant) -> None: """Test the setup of the integration using imperial unit system.""" hass.config.units = US_CUSTOMARY_SYSTEM # Set up some mock feed entries for this test. diff --git a/tests/components/gios/test_config_flow.py b/tests/components/gios/test_config_flow.py index 3a0d57ce0d4..3d52c122791 100644 --- a/tests/components/gios/test_config_flow.py +++ b/tests/components/gios/test_config_flow.py @@ -8,6 +8,7 @@ from homeassistant import data_entry_flow from homeassistant.components.gios import config_flow from homeassistant.components.gios.const import CONF_STATION_ID from homeassistant.const import CONF_NAME +from homeassistant.core import HomeAssistant from . import STATIONS @@ -19,7 +20,7 @@ CONFIG = { } -async def test_show_form(hass): +async def test_show_form(hass: HomeAssistant) -> None: """Test that the form is served with no input.""" flow = config_flow.GiosFlowHandler() flow.hass = hass @@ -30,7 +31,7 @@ async def test_show_form(hass): assert result["step_id"] == "user" -async def test_invalid_station_id(hass): +async def test_invalid_station_id(hass: HomeAssistant) -> None: """Test that errors are shown when measuring station ID is invalid.""" with patch( "homeassistant.components.gios.Gios._get_stations", return_value=STATIONS @@ -46,7 +47,7 @@ async def test_invalid_station_id(hass): assert result["errors"] == {CONF_STATION_ID: "wrong_station_id"} -async def test_invalid_sensor_data(hass): +async def test_invalid_sensor_data(hass: HomeAssistant) -> None: """Test that errors are shown when sensor data is invalid.""" with patch( "homeassistant.components.gios.Gios._get_stations", return_value=STATIONS @@ -65,7 +66,7 @@ async def test_invalid_sensor_data(hass): assert result["errors"] == {CONF_STATION_ID: "invalid_sensors_data"} -async def test_cannot_connect(hass): +async def test_cannot_connect(hass: HomeAssistant) -> None: """Test that errors are shown when cannot connect to GIOS server.""" with patch( "homeassistant.components.gios.Gios._async_get", side_effect=ApiError("error") @@ -79,7 +80,7 @@ async def test_cannot_connect(hass): assert result["errors"] == {"base": "cannot_connect"} -async def test_create_entry(hass): +async def test_create_entry(hass: HomeAssistant) -> None: """Test that the user step works.""" with patch( "homeassistant.components.gios.Gios._get_stations", return_value=STATIONS diff --git a/tests/components/gios/test_diagnostics.py b/tests/components/gios/test_diagnostics.py index 2168457f628..0b9560a96e1 100644 --- a/tests/components/gios/test_diagnostics.py +++ b/tests/components/gios/test_diagnostics.py @@ -1,13 +1,18 @@ """Test GIOS diagnostics.""" import json +from homeassistant.core import HomeAssistant + from . import init_integration from tests.common import load_fixture from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator -async def test_entry_diagnostics(hass, hass_client): +async def test_entry_diagnostics( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> None: """Test config entry diagnostics.""" entry = await init_integration(hass) diff --git a/tests/components/gios/test_init.py b/tests/components/gios/test_init.py index f3a628160f0..9a70890798c 100644 --- a/tests/components/gios/test_init.py +++ b/tests/components/gios/test_init.py @@ -6,6 +6,7 @@ from homeassistant.components.air_quality import DOMAIN as AIR_QUALITY_PLATFORM from homeassistant.components.gios.const import DOMAIN from homeassistant.config_entries import ConfigEntryState from homeassistant.const import STATE_UNAVAILABLE +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from . import STATIONS, init_integration @@ -13,7 +14,7 @@ from . import STATIONS, init_integration from tests.common import MockConfigEntry, load_fixture, mock_device_registry -async def test_async_setup_entry(hass): +async def test_async_setup_entry(hass: HomeAssistant) -> None: """Test a successful setup entry.""" await init_integration(hass) @@ -23,7 +24,7 @@ async def test_async_setup_entry(hass): assert state.state == "4" -async def test_config_not_ready(hass): +async def test_config_not_ready(hass: HomeAssistant) -> None: """Test for setup failure if connection to GIOS is missing.""" entry = MockConfigEntry( domain=DOMAIN, @@ -41,7 +42,7 @@ async def test_config_not_ready(hass): assert entry.state is ConfigEntryState.SETUP_RETRY -async def test_unload_entry(hass): +async def test_unload_entry(hass: HomeAssistant) -> None: """Test successful unload of entry.""" entry = await init_integration(hass) @@ -55,7 +56,7 @@ async def test_unload_entry(hass): assert not hass.data.get(DOMAIN) -async def test_migrate_device_and_config_entry(hass): +async def test_migrate_device_and_config_entry(hass: HomeAssistant) -> None: """Test device_info identifiers and config entry migration.""" config_entry = MockConfigEntry( domain=DOMAIN, @@ -98,7 +99,7 @@ async def test_migrate_device_and_config_entry(hass): assert device_entry.id == migrated_device_entry.id -async def test_remove_air_quality_entities(hass): +async def test_remove_air_quality_entities(hass: HomeAssistant) -> None: """Test remove air_quality entities from registry.""" registry = er.async_get(hass) diff --git a/tests/components/gios/test_sensor.py b/tests/components/gios/test_sensor.py index 9f88b247983..9dbdda7d2ee 100644 --- a/tests/components/gios/test_sensor.py +++ b/tests/components/gios/test_sensor.py @@ -25,6 +25,7 @@ from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, STATE_UNAVAILABLE, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.util.dt import utcnow @@ -33,7 +34,7 @@ from . import init_integration from tests.common import async_fire_time_changed, load_fixture -async def test_sensor(hass): +async def test_sensor(hass: HomeAssistant) -> None: """Test states of the sensor.""" await init_integration(hass) registry = er.async_get(hass) @@ -170,7 +171,7 @@ async def test_sensor(hass): assert entry.unique_id == "123-aqi" -async def test_availability(hass): +async def test_availability(hass: HomeAssistant) -> None: """Ensure that we mark the entities unavailable correctly when service causes an error.""" await init_integration(hass) @@ -212,7 +213,7 @@ async def test_availability(hass): assert state.state == STATE_UNAVAILABLE -async def test_invalid_indexes(hass): +async def test_invalid_indexes(hass: HomeAssistant) -> None: """Test states of the sensor when API returns invalid indexes.""" await init_integration(hass, invalid_indexes=True) registry = er.async_get(hass) @@ -334,7 +335,7 @@ async def test_invalid_indexes(hass): assert state is None -async def test_aqi_sensor_availability(hass): +async def test_aqi_sensor_availability(hass: HomeAssistant) -> None: """Ensure that we mark the AQI sensor unavailable correctly when indexes are invalid.""" await init_integration(hass) @@ -359,7 +360,7 @@ async def test_aqi_sensor_availability(hass): assert state.state == STATE_UNAVAILABLE -async def test_unique_id_migration(hass): +async def test_unique_id_migration(hass: HomeAssistant) -> None: """Test states of the unique_id migration.""" registry = er.async_get(hass) diff --git a/tests/components/gios/test_system_health.py b/tests/components/gios/test_system_health.py index c58b8b12b53..11af7bad8f3 100644 --- a/tests/components/gios/test_system_health.py +++ b/tests/components/gios/test_system_health.py @@ -4,12 +4,16 @@ import asyncio from aiohttp import ClientError from homeassistant.components.gios.const import DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import get_system_health_info +from tests.test_util.aiohttp import AiohttpClientMocker -async def test_gios_system_health(hass, aioclient_mock): +async def test_gios_system_health( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test GIOS system health.""" aioclient_mock.get("http://api.gios.gov.pl/", text="") hass.config.components.add(DOMAIN) @@ -24,7 +28,9 @@ async def test_gios_system_health(hass, aioclient_mock): assert info == {"can_reach_server": "ok"} -async def test_gios_system_health_fail(hass, aioclient_mock): +async def test_gios_system_health_fail( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test GIOS system health.""" aioclient_mock.get("http://api.gios.gov.pl/", exc=ClientError) hass.config.components.add(DOMAIN) diff --git a/tests/components/gogogate2/test_config_flow.py b/tests/components/gogogate2/test_config_flow.py index cbe40a2b9cb..b189c99c12d 100644 --- a/tests/components/gogogate2/test_config_flow.py +++ b/tests/components/gogogate2/test_config_flow.py @@ -97,7 +97,7 @@ async def test_auth_fail( assert result["errors"] == {"base": "cannot_connect"} -async def test_form_homekit_unique_id_already_setup(hass): +async def test_form_homekit_unique_id_already_setup(hass: HomeAssistant) -> None: """Test that we abort from homekit if gogogate2 is already setup.""" result = await hass.config_entries.flow.async_init( @@ -144,7 +144,7 @@ async def test_form_homekit_unique_id_already_setup(hass): assert result["type"] == FlowResultType.ABORT -async def test_form_homekit_ip_address_already_setup(hass): +async def test_form_homekit_ip_address_already_setup(hass: HomeAssistant) -> None: """Test that we abort from homekit if gogogate2 is already setup.""" entry = MockConfigEntry( @@ -169,7 +169,7 @@ async def test_form_homekit_ip_address_already_setup(hass): assert result["type"] == FlowResultType.ABORT -async def test_form_homekit_ip_address(hass): +async def test_form_homekit_ip_address(hass: HomeAssistant) -> None: """Test homekit includes the defaults ip address.""" result = await hass.config_entries.flow.async_init( @@ -252,7 +252,7 @@ async def test_discovered_dhcp( } -async def test_discovered_by_homekit_and_dhcp(hass): +async def test_discovered_by_homekit_and_dhcp(hass: HomeAssistant) -> None: """Test we get the form with homekit and abort for dhcp source when we get both.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/google_assistant/test_helpers.py b/tests/components/google_assistant/test_helpers.py index 0dfd98cae25..1ac2c4b63b3 100644 --- a/tests/components/google_assistant/test_helpers.py +++ b/tests/components/google_assistant/test_helpers.py @@ -14,7 +14,7 @@ from homeassistant.components.google_assistant.const import ( STORE_GOOGLE_LOCAL_WEBHOOK_ID, ) from homeassistant.config import async_process_ha_core_config -from homeassistant.core import State +from homeassistant.core import HomeAssistant, State from homeassistant.setup import async_setup_component from homeassistant.util import dt @@ -25,9 +25,10 @@ from tests.common import ( async_fire_time_changed, async_mock_service, ) +from tests.typing import ClientSessionGenerator -async def test_google_entity_sync_serialize_with_local_sdk(hass): +async def test_google_entity_sync_serialize_with_local_sdk(hass: HomeAssistant) -> None: """Test sync serialize attributes of a GoogleEntity.""" hass.states.async_set("light.ceiling_lights", "off") hass.config.api = Mock(port=1234, local_ip="192.168.123.123", use_ssl=False) @@ -71,7 +72,9 @@ async def test_google_entity_sync_serialize_with_local_sdk(hass): assert "customData" not in serialized -async def test_config_local_sdk(hass, hass_client): +async def test_config_local_sdk( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> None: """Test the local SDK.""" command_events = async_capture_events(hass, EVENT_COMMAND_RECEIVED) turn_on_calls = async_mock_service(hass, "light", "turn_on") @@ -146,7 +149,9 @@ async def test_config_local_sdk(hass, hass_client): assert await resp.read() == b"" -async def test_config_local_sdk_if_disabled(hass, hass_client): +async def test_config_local_sdk_if_disabled( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> None: """Test the local SDK.""" assert await async_setup_component(hass, "webhook", {}) @@ -185,7 +190,9 @@ async def test_config_local_sdk_if_disabled(hass, hass_client): assert await resp.read() == b"" -async def test_config_local_sdk_if_ssl_enabled(hass, hass_client): +async def test_config_local_sdk_if_ssl_enabled( + hass: HomeAssistant, hass_client: ClientSessionGenerator +) -> None: """Test the local SDK is not enabled when SSL is enabled.""" assert await async_setup_component(hass, "webhook", {}) hass.config.api.use_ssl = True diff --git a/tests/components/google_assistant/test_http.py b/tests/components/google_assistant/test_http.py index 2cc62b47239..6d1e925a04a 100644 --- a/tests/components/google_assistant/test_http.py +++ b/tests/components/google_assistant/test_http.py @@ -18,10 +18,11 @@ from homeassistant.components.google_assistant.http import ( _get_homegraph_token, ) from homeassistant.const import CLOUD_NEVER_EXPOSED_ENTITIES -from homeassistant.core import State +from homeassistant.core import HomeAssistant, State from homeassistant.setup import async_setup_component from tests.common import async_capture_events, async_mock_service +from tests.test_util.aiohttp import AiohttpClientMocker DUMMY_CONFIG = GOOGLE_ASSISTANT_SCHEMA( { @@ -41,7 +42,7 @@ MOCK_HEADER = { } -async def test_get_jwt(hass): +async def test_get_jwt(hass: HomeAssistant) -> None: """Test signing of key.""" jwt = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkdW1teUBkdW1teS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9ob21lZ3JhcGgiLCJhdWQiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvdG9rZW4iLCJpYXQiOjE1NzEwMTEyMDAsImV4cCI6MTU3MTAxNDgwMH0.akHbMhOflXdIDHVvUVwO0AoJONVOPUdCghN6hAdVz4gxjarrQeGYc_Qn2r84bEvCU7t6EvimKKr0fyupyzBAzfvKULs5mTHO3h2CwSgvOBMv8LnILboJmbO4JcgdnRV7d9G3ktQs7wWSCXJsI5i5jUr1Wfi9zWwxn2ebaAAgrp8" @@ -53,7 +54,9 @@ async def test_get_jwt(hass): assert res == jwt -async def test_get_access_token(hass, aioclient_mock): +async def test_get_access_token( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test the function to get access token.""" jwt = "dummyjwt" @@ -71,7 +74,7 @@ async def test_get_access_token(hass, aioclient_mock): } -async def test_update_access_token(hass): +async def test_update_access_token(hass: HomeAssistant) -> None: """Test the function to update access token when expired.""" jwt = "dummyjwt" @@ -205,7 +208,7 @@ async def test_google_config_local_fulfillment(hass, aioclient_mock, hass_storag assert config.get_local_agent_user_id("INCORRECT") is None -async def test_secure_device_pin_config(hass): +async def test_secure_device_pin_config(hass: HomeAssistant) -> None: """Test the setting of the secure device pin configuration.""" secure_pin = "TEST" secure_config = GOOGLE_ASSISTANT_SCHEMA( @@ -223,7 +226,7 @@ async def test_secure_device_pin_config(hass): assert config.secure_devices_pin == secure_pin -async def test_should_expose(hass): +async def test_should_expose(hass: HomeAssistant) -> None: """Test the google config should expose method.""" config = GoogleConfig(hass, DUMMY_CONFIG) await config.async_initialize() @@ -244,7 +247,7 @@ async def test_should_expose(hass): assert config.should_expose(State(CLOUD_NEVER_EXPOSED_ENTITIES[0], "mock")) is False -async def test_missing_service_account(hass): +async def test_missing_service_account(hass: HomeAssistant) -> None: """Test the google config _async_request_sync_devices.""" incorrect_config = GOOGLE_ASSISTANT_SCHEMA( { diff --git a/tests/components/google_assistant/test_logbook.py b/tests/components/google_assistant/test_logbook.py index 5875d44adc7..58b747a6f07 100644 --- a/tests/components/google_assistant/test_logbook.py +++ b/tests/components/google_assistant/test_logbook.py @@ -6,12 +6,13 @@ from homeassistant.components.google_assistant.const import ( SOURCE_LOCAL, ) from homeassistant.const import ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.components.logbook.common import MockRow, mock_humanify -async def test_humanify_command_received(hass): +async def test_humanify_command_received(hass: HomeAssistant) -> None: """Test humanifying command event.""" hass.config.components.add("recorder") hass.config.components.add("frontend") diff --git a/tests/components/google_assistant/test_report_state.py b/tests/components/google_assistant/test_report_state.py index 37a4ebaa208..3fe2a749fca 100644 --- a/tests/components/google_assistant/test_report_state.py +++ b/tests/components/google_assistant/test_report_state.py @@ -2,7 +2,10 @@ from datetime import timedelta from unittest.mock import AsyncMock, patch +import pytest + from homeassistant.components.google_assistant import error, report_state +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow @@ -11,7 +14,9 @@ from . import BASIC_CONFIG from tests.common import async_fire_time_changed -async def test_report_state(hass, caplog): +async def test_report_state( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test report state works.""" assert await async_setup_component(hass, "switch", {}) hass.states.async_set("light.ceiling", "off") diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index 31984129968..c179228aa6f 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -22,7 +22,7 @@ from homeassistant.components.google_assistant import ( ) from homeassistant.config import async_process_ha_core_config from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, __version__ -from homeassistant.core import EVENT_CALL_SERVICE, State +from homeassistant.core import EVENT_CALL_SERVICE, HomeAssistant, State from homeassistant.helpers import device_registry, entity_platform from homeassistant.setup import async_setup_component @@ -50,7 +50,7 @@ def registries(hass): return ret -async def test_async_handle_message(hass): +async def test_async_handle_message(hass: HomeAssistant) -> None: """Test the async handle message method.""" config = MockConfig( should_expose=lambda state: state.entity_id != "light.not_expose", @@ -345,7 +345,7 @@ async def test_sync_in_area(area_on_device, hass, registries): assert events[0].data == {"request_id": REQ_ID, "source": "cloud"} -async def test_query_message(hass): +async def test_query_message(hass: HomeAssistant) -> None: """Test a sync message.""" light = DemoLight( None, @@ -821,7 +821,7 @@ async def test_execute_times_out(hass, report_state, on, brightness, value): sh.EXECUTE_LIMIT = orig_execute_limit -async def test_raising_error_trait(hass): +async def test_raising_error_trait(hass: HomeAssistant) -> None: """Test raising an error while executing a trait command.""" hass.states.async_set( "climate.bla", @@ -893,7 +893,7 @@ async def test_raising_error_trait(hass): } -async def test_serialize_input_boolean(hass): +async def test_serialize_input_boolean(hass: HomeAssistant) -> None: """Test serializing an input boolean entity.""" state = State("input_boolean.bla", "on") entity = sh.GoogleEntity(hass, BASIC_CONFIG, state) @@ -908,7 +908,7 @@ async def test_serialize_input_boolean(hass): } -async def test_unavailable_state_does_sync(hass): +async def test_unavailable_state_does_sync(hass: HomeAssistant) -> None: """Test that an unavailable entity does sync over.""" light = DemoLight( None, @@ -1185,7 +1185,7 @@ async def test_device_media_player(hass, device_class, google_type): } -async def test_query_disconnect(hass): +async def test_query_disconnect(hass: HomeAssistant) -> None: """Test a disconnect message.""" config = MockConfig(hass=hass) config.async_enable_report_state() @@ -1202,7 +1202,7 @@ async def test_query_disconnect(hass): assert len(mock_disconnect.mock_calls) == 1 -async def test_trait_execute_adding_query_data(hass): +async def test_trait_execute_adding_query_data(hass: HomeAssistant) -> None: """Test a trait execute influencing query data.""" await async_process_ha_core_config( hass, @@ -1270,7 +1270,7 @@ async def test_trait_execute_adding_query_data(hass): } -async def test_identify(hass): +async def test_identify(hass: HomeAssistant) -> None: """Test identify message.""" user_agent_id = "mock-user-id" proxy_device_id = user_agent_id @@ -1338,7 +1338,7 @@ async def test_identify(hass): } -async def test_reachable_devices(hass): +async def test_reachable_devices(hass: HomeAssistant) -> None: """Test REACHABLE_DEVICES intent.""" # Matching passed in device. hass.states.async_set("light.ceiling_lights", "on") @@ -1423,7 +1423,9 @@ async def test_reachable_devices(hass): } -async def test_sync_message_recovery(hass, caplog): +async def test_sync_message_recovery( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test a sync message recovers from bad entities.""" light = DemoLight( None, @@ -1482,7 +1484,9 @@ async def test_sync_message_recovery(hass, caplog): assert "Error serializing light.bad_light" in caplog.text -async def test_query_recover(hass, caplog): +async def test_query_recover( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test that we recover if an entity raises during query.""" hass.states.async_set( @@ -1538,7 +1542,9 @@ async def test_query_recover(hass, caplog): } -async def test_proxy_selected(hass, caplog): +async def test_proxy_selected( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test that we handle proxy selected.""" result = await sh.async_handle_message( diff --git a/tests/components/google_assistant/test_trait.py b/tests/components/google_assistant/test_trait.py index b528dc3e2f8..4233b6f3e5e 100644 --- a/tests/components/google_assistant/test_trait.py +++ b/tests/components/google_assistant/test_trait.py @@ -54,7 +54,12 @@ from homeassistant.const import ( STATE_UNKNOWN, UnitOfTemperature, ) -from homeassistant.core import DOMAIN as HA_DOMAIN, EVENT_CALL_SERVICE, State +from homeassistant.core import ( + DOMAIN as HA_DOMAIN, + EVENT_CALL_SERVICE, + HomeAssistant, + State, +) from homeassistant.util import color from . import BASIC_CONFIG, MockConfig @@ -113,7 +118,7 @@ async def test_brightness_light(hass, supported_color_modes): } -async def test_camera_stream(hass): +async def test_camera_stream(hass: HomeAssistant) -> None: """Test camera stream trait support for camera domain.""" await async_process_ha_core_config( hass, @@ -148,7 +153,7 @@ async def test_camera_stream(hass): } -async def test_onoff_group(hass): +async def test_onoff_group(hass: HomeAssistant) -> None: """Test OnOff trait support for group domain.""" assert helpers.get_google_type(group.DOMAIN, None) is not None assert trait.OnOffTrait.supported(group.DOMAIN, 0, None, None) @@ -174,7 +179,7 @@ async def test_onoff_group(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "group.bla"} -async def test_onoff_input_boolean(hass): +async def test_onoff_input_boolean(hass: HomeAssistant) -> None: """Test OnOff trait support for input_boolean domain.""" assert helpers.get_google_type(input_boolean.DOMAIN, None) is not None assert trait.OnOffTrait.supported(input_boolean.DOMAIN, 0, None, None) @@ -202,7 +207,7 @@ async def test_onoff_input_boolean(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "input_boolean.bla"} -async def test_onoff_switch(hass): +async def test_onoff_switch(hass: HomeAssistant) -> None: """Test OnOff trait support for switch domain.""" assert helpers.get_google_type(switch.DOMAIN, None) is not None assert trait.OnOffTrait.supported(switch.DOMAIN, 0, None, None) @@ -233,7 +238,7 @@ async def test_onoff_switch(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "switch.bla"} -async def test_onoff_fan(hass): +async def test_onoff_fan(hass: HomeAssistant) -> None: """Test OnOff trait support for fan domain.""" assert helpers.get_google_type(fan.DOMAIN, None) is not None assert trait.OnOffTrait.supported(fan.DOMAIN, 0, None, None) @@ -258,7 +263,7 @@ async def test_onoff_fan(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "fan.bla"} -async def test_onoff_light(hass): +async def test_onoff_light(hass: HomeAssistant) -> None: """Test OnOff trait support for light domain.""" assert helpers.get_google_type(light.DOMAIN, None) is not None assert trait.OnOffTrait.supported(light.DOMAIN, 0, None, None) @@ -284,7 +289,7 @@ async def test_onoff_light(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "light.bla"} -async def test_onoff_media_player(hass): +async def test_onoff_media_player(hass: HomeAssistant) -> None: """Test OnOff trait support for media_player domain.""" assert helpers.get_google_type(media_player.DOMAIN, None) is not None assert trait.OnOffTrait.supported(media_player.DOMAIN, 0, None, None) @@ -311,7 +316,7 @@ async def test_onoff_media_player(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "media_player.bla"} -async def test_onoff_humidifier(hass): +async def test_onoff_humidifier(hass: HomeAssistant) -> None: """Test OnOff trait support for humidifier domain.""" assert helpers.get_google_type(humidifier.DOMAIN, None) is not None assert trait.OnOffTrait.supported(humidifier.DOMAIN, 0, None, None) @@ -338,7 +343,7 @@ async def test_onoff_humidifier(hass): assert off_calls[0].data == {ATTR_ENTITY_ID: "humidifier.bla"} -async def test_dock_vacuum(hass): +async def test_dock_vacuum(hass: HomeAssistant) -> None: """Test dock trait support for vacuum domain.""" assert helpers.get_google_type(vacuum.DOMAIN, None) is not None assert trait.DockTrait.supported(vacuum.DOMAIN, 0, None, None) @@ -355,7 +360,7 @@ async def test_dock_vacuum(hass): assert calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"} -async def test_locate_vacuum(hass): +async def test_locate_vacuum(hass: HomeAssistant) -> None: """Test locate trait support for vacuum domain.""" assert helpers.get_google_type(vacuum.DOMAIN, None) is not None assert trait.LocatorTrait.supported( @@ -386,7 +391,7 @@ async def test_locate_vacuum(hass): assert err.value.code == const.ERR_FUNCTION_NOT_SUPPORTED -async def test_energystorage_vacuum(hass): +async def test_energystorage_vacuum(hass: HomeAssistant) -> None: """Test EnergyStorage trait support for vacuum domain.""" assert helpers.get_google_type(vacuum.DOMAIN, None) is not None assert trait.EnergyStorageTrait.supported( @@ -454,7 +459,7 @@ async def test_energystorage_vacuum(hass): assert err.value.code == const.ERR_FUNCTION_NOT_SUPPORTED -async def test_startstop_vacuum(hass): +async def test_startstop_vacuum(hass: HomeAssistant) -> None: """Test startStop trait support for vacuum domain.""" assert helpers.get_google_type(vacuum.DOMAIN, None) is not None assert trait.StartStopTrait.supported(vacuum.DOMAIN, 0, None, None) @@ -494,7 +499,7 @@ async def test_startstop_vacuum(hass): assert unpause_calls[0].data == {ATTR_ENTITY_ID: "vacuum.bla"} -async def test_startstop_cover(hass): +async def test_startstop_cover(hass: HomeAssistant) -> None: """Test startStop trait support for cover domain.""" assert helpers.get_google_type(cover.DOMAIN, None) is not None assert trait.StartStopTrait.supported(cover.DOMAIN, cover.SUPPORT_STOP, None, None) @@ -539,7 +544,7 @@ async def test_startstop_cover(hass): await trt.execute(trait.COMMAND_PAUSEUNPAUSE, BASIC_DATA, {"start": True}, {}) -async def test_startstop_cover_assumed(hass): +async def test_startstop_cover_assumed(hass: HomeAssistant) -> None: """Test startStop trait support for cover domain of assumed state.""" trt = trait.StartStopTrait( hass, @@ -618,7 +623,7 @@ async def test_color_setting_color_light(hass, supported_color_modes): } -async def test_color_setting_temperature_light(hass): +async def test_color_setting_temperature_light(hass: HomeAssistant) -> None: """Test ColorTemperature trait support for light domain.""" assert helpers.get_google_type(light.DOMAIN, None) is not None assert not trait.ColorSettingTrait.supported(light.DOMAIN, 0, None, {}) @@ -672,7 +677,7 @@ async def test_color_setting_temperature_light(hass): } -async def test_color_light_temperature_light_bad_temp(hass): +async def test_color_light_temperature_light_bad_temp(hass: HomeAssistant) -> None: """Test ColorTemperature trait support for light domain.""" assert helpers.get_google_type(light.DOMAIN, None) is not None assert not trait.ColorSettingTrait.supported(light.DOMAIN, 0, None, {}) @@ -697,7 +702,7 @@ async def test_color_light_temperature_light_bad_temp(hass): assert trt.query_attributes() == {} -async def test_light_modes(hass): +async def test_light_modes(hass: HomeAssistant) -> None: """Test Light Mode trait.""" assert helpers.get_google_type(light.DOMAIN, None) is not None assert trait.ModesTrait.supported(light.DOMAIN, light.SUPPORT_EFFECT, None, None) @@ -791,7 +796,7 @@ async def test_scene_button(hass, component): assert calls[0].data == {ATTR_ENTITY_ID: f"{component.DOMAIN}.bla"} -async def test_scene_scene(hass): +async def test_scene_scene(hass: HomeAssistant) -> None: """Test Scene trait support for scene domain.""" assert helpers.get_google_type(scene.DOMAIN, None) is not None assert trait.SceneTrait.supported(scene.DOMAIN, 0, None, None) @@ -807,7 +812,7 @@ async def test_scene_scene(hass): assert calls[0].data == {ATTR_ENTITY_ID: "scene.bla"} -async def test_scene_script(hass): +async def test_scene_script(hass: HomeAssistant) -> None: """Test Scene trait support for script domain.""" assert helpers.get_google_type(script.DOMAIN, None) is not None assert trait.SceneTrait.supported(script.DOMAIN, 0, None, None) @@ -827,7 +832,7 @@ async def test_scene_script(hass): assert calls[0].data == {ATTR_ENTITY_ID: "script.bla"} -async def test_temperature_setting_climate_onoff(hass): +async def test_temperature_setting_climate_onoff(hass: HomeAssistant) -> None: """Test TemperatureSetting trait support for climate domain - range.""" assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) @@ -872,7 +877,7 @@ async def test_temperature_setting_climate_onoff(hass): assert len(calls) == 1 -async def test_temperature_setting_climate_no_modes(hass): +async def test_temperature_setting_climate_no_modes(hass: HomeAssistant) -> None: """Test TemperatureSetting trait support for climate domain not supporting any modes.""" assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) @@ -898,7 +903,7 @@ async def test_temperature_setting_climate_no_modes(hass): } -async def test_temperature_setting_climate_range(hass): +async def test_temperature_setting_climate_range(hass: HomeAssistant) -> None: """Test TemperatureSetting trait support for climate domain - range.""" assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) @@ -980,7 +985,7 @@ async def test_temperature_setting_climate_range(hass): hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS -async def test_temperature_setting_climate_setpoint(hass): +async def test_temperature_setting_climate_setpoint(hass: HomeAssistant) -> None: """Test TemperatureSetting trait support for climate domain - setpoint.""" assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.TemperatureSettingTrait.supported(climate.DOMAIN, 0, None, None) @@ -1034,7 +1039,7 @@ async def test_temperature_setting_climate_setpoint(hass): assert calls[0].data == {ATTR_ENTITY_ID: "climate.bla", ATTR_TEMPERATURE: 19} -async def test_temperature_setting_climate_setpoint_auto(hass): +async def test_temperature_setting_climate_setpoint_auto(hass: HomeAssistant) -> None: """Test TemperatureSetting trait support for climate domain. Setpoint in auto mode. @@ -1084,7 +1089,7 @@ async def test_temperature_setting_climate_setpoint_auto(hass): assert calls[0].data == {ATTR_ENTITY_ID: "climate.bla", ATTR_TEMPERATURE: 19} -async def test_temperature_control(hass): +async def test_temperature_control(hass: HomeAssistant) -> None: """Test TemperatureControl trait support for sensor domain.""" hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS @@ -1107,7 +1112,7 @@ async def test_temperature_control(hass): assert err.value.code == const.ERR_NOT_SUPPORTED -async def test_humidity_setting_humidifier_setpoint(hass): +async def test_humidity_setting_humidifier_setpoint(hass: HomeAssistant) -> None: """Test HumiditySetting trait support for humidifier domain - setpoint.""" assert helpers.get_google_type(humidifier.DOMAIN, None) is not None assert trait.HumiditySettingTrait.supported(humidifier.DOMAIN, 0, None, None) @@ -1143,7 +1148,7 @@ async def test_humidity_setting_humidifier_setpoint(hass): } -async def test_lock_unlock_lock(hass): +async def test_lock_unlock_lock(hass: HomeAssistant) -> None: """Test LockUnlock trait locking support for lock domain.""" assert helpers.get_google_type(lock.DOMAIN, None) is not None assert trait.LockUnlockTrait.supported(lock.DOMAIN, lock.SUPPORT_OPEN, None, None) @@ -1167,7 +1172,7 @@ async def test_lock_unlock_lock(hass): assert calls[0].data == {ATTR_ENTITY_ID: "lock.front_door"} -async def test_lock_unlock_unlocking(hass): +async def test_lock_unlock_unlocking(hass: HomeAssistant) -> None: """Test LockUnlock trait locking support for lock domain.""" assert helpers.get_google_type(lock.DOMAIN, None) is not None assert trait.LockUnlockTrait.supported(lock.DOMAIN, lock.SUPPORT_OPEN, None, None) @@ -1182,7 +1187,7 @@ async def test_lock_unlock_unlocking(hass): assert trt.query_attributes() == {"isLocked": True} -async def test_lock_unlock_lock_jammed(hass): +async def test_lock_unlock_lock_jammed(hass: HomeAssistant) -> None: """Test LockUnlock trait locking support for lock domain that jams.""" assert helpers.get_google_type(lock.DOMAIN, None) is not None assert trait.LockUnlockTrait.supported(lock.DOMAIN, lock.SUPPORT_OPEN, None, None) @@ -1206,7 +1211,7 @@ async def test_lock_unlock_lock_jammed(hass): assert calls[0].data == {ATTR_ENTITY_ID: "lock.front_door"} -async def test_lock_unlock_unlock(hass): +async def test_lock_unlock_unlock(hass: HomeAssistant) -> None: """Test LockUnlock trait unlocking support for lock domain.""" assert helpers.get_google_type(lock.DOMAIN, None) is not None assert trait.LockUnlockTrait.supported(lock.DOMAIN, lock.SUPPORT_OPEN, None, None) @@ -1266,7 +1271,7 @@ async def test_lock_unlock_unlock(hass): assert len(calls) == 2 -async def test_arm_disarm_arm_away(hass): +async def test_arm_disarm_arm_away(hass: HomeAssistant) -> None: """Test ArmDisarm trait Arming support for alarm_control_panel domain.""" assert helpers.get_google_type(alarm_control_panel.DOMAIN, None) is not None assert trait.ArmDisArmTrait.supported(alarm_control_panel.DOMAIN, 0, None, None) @@ -1429,7 +1434,7 @@ async def test_arm_disarm_arm_away(hass): ) -async def test_arm_disarm_disarm(hass): +async def test_arm_disarm_disarm(hass: HomeAssistant) -> None: """Test ArmDisarm trait Disarming support for alarm_control_panel domain.""" assert helpers.get_google_type(alarm_control_panel.DOMAIN, None) is not None assert trait.ArmDisArmTrait.supported(alarm_control_panel.DOMAIN, 0, None, None) @@ -1575,7 +1580,7 @@ async def test_arm_disarm_disarm(hass): assert len(calls) == 2 -async def test_fan_speed(hass): +async def test_fan_speed(hass: HomeAssistant) -> None: """Test FanSpeed trait speed control support for fan domain.""" assert helpers.get_google_type(fan.DOMAIN, None) is not None assert trait.FanSpeedTrait.supported(fan.DOMAIN, fan.SUPPORT_SET_SPEED, None, None) @@ -1613,7 +1618,7 @@ async def test_fan_speed(hass): assert calls[0].data == {"entity_id": "fan.living_room_fan", "percentage": 10} -async def test_fan_speed_without_percentage_step(hass): +async def test_fan_speed_without_percentage_step(hass: HomeAssistant) -> None: """Test FanSpeed trait speed control percentage step for fan domain.""" assert helpers.get_google_type(fan.DOMAIN, None) is not None assert trait.FanSpeedTrait.supported(fan.DOMAIN, fan.SUPPORT_SET_SPEED, None, None) @@ -1799,7 +1804,7 @@ async def test_fan_reverse(hass, direction_state, direction_call): } -async def test_climate_fan_speed(hass): +async def test_climate_fan_speed(hass: HomeAssistant) -> None: """Test FanSpeed trait speed control support for climate domain.""" assert helpers.get_google_type(climate.DOMAIN, None) is not None assert trait.FanSpeedTrait.supported( @@ -1860,7 +1865,7 @@ async def test_climate_fan_speed(hass): } -async def test_inputselector(hass): +async def test_inputselector(hass: HomeAssistant) -> None: """Test input selector trait.""" assert helpers.get_google_type(media_player.DOMAIN, None) is not None assert trait.InputSelectorTrait.supported( @@ -2021,7 +2026,7 @@ async def test_inputselector_nextprev_invalid(hass, sources, source): ) -async def test_modes_input_select(hass): +async def test_modes_input_select(hass: HomeAssistant) -> None: """Test Input Select Mode trait.""" assert helpers.get_google_type(input_select.DOMAIN, None) is not None assert trait.ModesTrait.supported(input_select.DOMAIN, None, None, None) @@ -2097,7 +2102,7 @@ async def test_modes_input_select(hass): assert calls[0].data == {"entity_id": "input_select.bla", "option": "xyz"} -async def test_modes_select(hass): +async def test_modes_select(hass: HomeAssistant) -> None: """Test Select Mode trait.""" assert helpers.get_google_type(select.DOMAIN, None) is not None assert trait.ModesTrait.supported(select.DOMAIN, None, None, None) @@ -2171,7 +2176,7 @@ async def test_modes_select(hass): assert calls[0].data == {"entity_id": "select.bla", "option": "xyz"} -async def test_modes_humidifier(hass): +async def test_modes_humidifier(hass: HomeAssistant) -> None: """Test Humidifier Mode trait.""" assert helpers.get_google_type(humidifier.DOMAIN, None) is not None assert trait.ModesTrait.supported( @@ -2250,7 +2255,7 @@ async def test_modes_humidifier(hass): } -async def test_sound_modes(hass): +async def test_sound_modes(hass: HomeAssistant) -> None: """Test Mode trait.""" assert helpers.get_google_type(media_player.DOMAIN, None) is not None assert trait.ModesTrait.supported( @@ -2327,7 +2332,7 @@ async def test_sound_modes(hass): } -async def test_preset_modes(hass): +async def test_preset_modes(hass: HomeAssistant) -> None: """Test Mode trait for fan preset modes.""" assert helpers.get_google_type(fan.DOMAIN, None) is not None assert trait.ModesTrait.supported(fan.DOMAIN, fan.SUPPORT_PRESET_MODE, None, None) @@ -2396,7 +2401,9 @@ async def test_preset_modes(hass): } -async def test_traits_unknown_domains(hass, caplog): +async def test_traits_unknown_domains( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture +) -> None: """Test Mode trait for unsupported domain.""" trt = trait.ModesTrait( hass, @@ -2418,7 +2425,7 @@ async def test_traits_unknown_domains(hass, caplog): caplog.clear() -async def test_openclose_cover(hass): +async def test_openclose_cover(hass: HomeAssistant) -> None: """Test OpenClose trait support for cover domain.""" assert helpers.get_google_type(cover.DOMAIN, None) is not None assert trait.OpenCloseTrait.supported( @@ -2455,7 +2462,7 @@ async def test_openclose_cover(hass): assert calls_open[0].data == {ATTR_ENTITY_ID: "cover.bla"} -async def test_openclose_cover_unknown_state(hass): +async def test_openclose_cover_unknown_state(hass: HomeAssistant) -> None: """Test OpenClose trait support for cover domain with unknown state.""" assert helpers.get_google_type(cover.DOMAIN, None) is not None assert trait.OpenCloseTrait.supported( @@ -2485,7 +2492,7 @@ async def test_openclose_cover_unknown_state(hass): trt.query_attributes() -async def test_openclose_cover_assumed_state(hass): +async def test_openclose_cover_assumed_state(hass: HomeAssistant) -> None: """Test OpenClose trait support for cover domain.""" assert helpers.get_google_type(cover.DOMAIN, None) is not None assert trait.OpenCloseTrait.supported( @@ -2515,7 +2522,7 @@ async def test_openclose_cover_assumed_state(hass): assert calls[0].data == {ATTR_ENTITY_ID: "cover.bla", cover.ATTR_POSITION: 40} -async def test_openclose_cover_query_only(hass): +async def test_openclose_cover_query_only(hass: HomeAssistant) -> None: """Test OpenClose trait support for cover domain.""" assert helpers.get_google_type(cover.DOMAIN, None) is not None assert trait.OpenCloseTrait.supported(cover.DOMAIN, 0, None, None) @@ -2538,7 +2545,7 @@ async def test_openclose_cover_query_only(hass): assert trt.query_attributes() == {"openPercent": 100} -async def test_openclose_cover_no_position(hass): +async def test_openclose_cover_no_position(hass: HomeAssistant) -> None: """Test OpenClose trait support for cover domain.""" assert helpers.get_google_type(cover.DOMAIN, None) is not None assert trait.OpenCloseTrait.supported( @@ -2699,7 +2706,7 @@ async def test_openclose_binary_sensor(hass, device_class): assert trt.query_attributes() == {"openPercent": 0} -async def test_volume_media_player(hass): +async def test_volume_media_player(hass: HomeAssistant) -> None: """Test volume trait support for media player domain.""" assert helpers.get_google_type(media_player.DOMAIN, None) is not None assert trait.VolumeTrait.supported( @@ -2754,7 +2761,7 @@ async def test_volume_media_player(hass): } -async def test_volume_media_player_relative(hass): +async def test_volume_media_player_relative(hass: HomeAssistant) -> None: """Test volume trait support for relative-volume-only media players.""" assert trait.VolumeTrait.supported( media_player.DOMAIN, @@ -2822,7 +2829,7 @@ async def test_volume_media_player_relative(hass): await trt.execute(trait.COMMAND_MUTE, BASIC_DATA, {"mute": True}, {}) -async def test_media_player_mute(hass): +async def test_media_player_mute(hass: HomeAssistant) -> None: """Test volume trait support for muting.""" assert trait.VolumeTrait.supported( media_player.DOMAIN, @@ -2886,7 +2893,7 @@ async def test_media_player_mute(hass): } -async def test_temperature_control_sensor(hass): +async def test_temperature_control_sensor(hass: HomeAssistant) -> None: """Test TemperatureControl trait support for temperature sensor.""" assert ( helpers.get_google_type(sensor.DOMAIN, sensor.SensorDeviceClass.TEMPERATURE) @@ -2939,7 +2946,7 @@ async def test_temperature_control_sensor_data(hass, unit_in, unit_out, state, a hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS -async def test_humidity_setting_sensor(hass): +async def test_humidity_setting_sensor(hass: HomeAssistant) -> None: """Test HumiditySetting trait support for humidity sensor.""" assert ( helpers.get_google_type(sensor.DOMAIN, sensor.SensorDeviceClass.HUMIDITY) @@ -2977,7 +2984,7 @@ async def test_humidity_setting_sensor_data(hass, state, ambient): assert err.value.code == const.ERR_NOT_SUPPORTED -async def test_transport_control(hass): +async def test_transport_control(hass: HomeAssistant) -> None: """Test the TransportControlTrait.""" assert helpers.get_google_type(media_player.DOMAIN, None) is not None @@ -3143,7 +3150,7 @@ async def test_media_state(hass, state): } -async def test_channel(hass): +async def test_channel(hass: HomeAssistant) -> None: """Test Channel trait support.""" assert helpers.get_google_type(media_player.DOMAIN, None) is not None assert trait.ChannelTrait.supported( @@ -3195,7 +3202,7 @@ async def test_channel(hass): assert len(media_player_calls) == 1 -async def test_sensorstate(hass): +async def test_sensorstate(hass: HomeAssistant) -> None: """Test SensorState trait support for sensor domain.""" sensor_types = { sensor.SensorDeviceClass.AQI: ("AirQuality", "AQI"), diff --git a/tests/components/google_domains/test_init.py b/tests/components/google_domains/test_init.py index 1ebc5cfda80..12f5e509736 100644 --- a/tests/components/google_domains/test_init.py +++ b/tests/components/google_domains/test_init.py @@ -4,10 +4,12 @@ from datetime import timedelta import pytest from homeassistant.components import google_domains +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed +from tests.test_util.aiohttp import AiohttpClientMocker DOMAIN = "test.example.com" USERNAME = "abc123" @@ -36,7 +38,7 @@ def setup_google_domains(hass, aioclient_mock): ) -async def test_setup(hass, aioclient_mock): +async def test_setup(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None: """Test setup works if update passes.""" aioclient_mock.get(UPDATE_URL, params={"hostname": DOMAIN}, text="nochg 0.0.0.0") @@ -59,7 +61,9 @@ async def test_setup(hass, aioclient_mock): assert aioclient_mock.call_count == 2 -async def test_setup_fails_if_update_fails(hass, aioclient_mock): +async def test_setup_fails_if_update_fails( + hass: HomeAssistant, aioclient_mock: AiohttpClientMocker +) -> None: """Test setup fails if first update fails.""" aioclient_mock.get(UPDATE_URL, params={"hostname": DOMAIN}, text="nohost") diff --git a/tests/components/google_travel_time/test_config_flow.py b/tests/components/google_travel_time/test_config_flow.py index 9ddcee5cdac..5f9d7e1413a 100644 --- a/tests/components/google_travel_time/test_config_flow.py +++ b/tests/components/google_travel_time/test_config_flow.py @@ -22,12 +22,13 @@ from homeassistant.components.google_travel_time.const import ( UNITS_IMPERIAL, ) from homeassistant.const import CONF_API_KEY, CONF_MODE, CONF_NAME +from homeassistant.core import HomeAssistant from .const import MOCK_CONFIG @pytest.mark.usefixtures("validate_config_entry", "bypass_setup") -async def test_minimum_fields(hass): +async def test_minimum_fields(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -51,7 +52,7 @@ async def test_minimum_fields(hass): @pytest.mark.usefixtures("invalidate_config_entry") -async def test_invalid_config_entry(hass): +async def test_invalid_config_entry(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -68,7 +69,7 @@ async def test_invalid_config_entry(hass): @pytest.mark.usefixtures("invalid_api_key") -async def test_invalid_api_key(hass): +async def test_invalid_api_key(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -85,7 +86,7 @@ async def test_invalid_api_key(hass): @pytest.mark.usefixtures("transport_error") -async def test_transport_error(hass): +async def test_transport_error(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -102,7 +103,7 @@ async def test_transport_error(hass): @pytest.mark.usefixtures("timeout") -async def test_timeout(hass): +async def test_timeout(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -118,7 +119,7 @@ async def test_timeout(hass): assert result2["errors"] == {"base": "cannot_connect"} -async def test_malformed_api_key(hass): +async def test_malformed_api_key(hass: HomeAssistant) -> None: """Test we get the form.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -257,7 +258,7 @@ async def test_options_flow_departure_time(hass, mock_config): @pytest.mark.usefixtures("validate_config_entry", "bypass_setup") -async def test_dupe(hass): +async def test_dupe(hass: HomeAssistant) -> None: """Test setting up the same entry data twice is OK.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} diff --git a/tests/components/google_travel_time/test_sensor.py b/tests/components/google_travel_time/test_sensor.py index c628137d624..b79856f7ee5 100644 --- a/tests/components/google_travel_time/test_sensor.py +++ b/tests/components/google_travel_time/test_sensor.py @@ -84,7 +84,7 @@ def mock_update_empty_fixture(mock_update): [(MOCK_CONFIG, {})], ) @pytest.mark.usefixtures("mock_update", "mock_config") -async def test_sensor(hass): +async def test_sensor(hass: HomeAssistant) -> None: """Test that sensor works.""" assert hass.states.get("sensor.google_travel_time").state == "27" assert ( @@ -119,7 +119,7 @@ async def test_sensor(hass): [(MOCK_CONFIG, {})], ) @pytest.mark.usefixtures("mock_update_duration", "mock_config") -async def test_sensor_duration(hass): +async def test_sensor_duration(hass: HomeAssistant) -> None: """Test that sensor works with no duration_in_traffic in response.""" assert hass.states.get("sensor.google_travel_time").state == "26" @@ -129,7 +129,7 @@ async def test_sensor_duration(hass): [(MOCK_CONFIG, {})], ) @pytest.mark.usefixtures("mock_update_empty", "mock_config") -async def test_sensor_empty_response(hass): +async def test_sensor_empty_response(hass: HomeAssistant) -> None: """Test that sensor works for an empty response.""" assert hass.states.get("sensor.google_travel_time").state == "unknown" @@ -146,7 +146,7 @@ async def test_sensor_empty_response(hass): ], ) @pytest.mark.usefixtures("mock_update", "mock_config") -async def test_sensor_departure_time(hass): +async def test_sensor_departure_time(hass: HomeAssistant) -> None: """Test that sensor works for departure time.""" assert hass.states.get("sensor.google_travel_time").state == "27" @@ -163,7 +163,7 @@ async def test_sensor_departure_time(hass): ], ) @pytest.mark.usefixtures("mock_update", "mock_config") -async def test_sensor_departure_time_custom_timestamp(hass): +async def test_sensor_departure_time_custom_timestamp(hass: HomeAssistant) -> None: """Test that sensor works for departure time with a custom timestamp.""" assert hass.states.get("sensor.google_travel_time").state == "27" @@ -180,7 +180,7 @@ async def test_sensor_departure_time_custom_timestamp(hass): ], ) @pytest.mark.usefixtures("mock_update", "mock_config") -async def test_sensor_arrival_time(hass): +async def test_sensor_arrival_time(hass: HomeAssistant) -> None: """Test that sensor works for arrival time.""" assert hass.states.get("sensor.google_travel_time").state == "27" @@ -197,7 +197,7 @@ async def test_sensor_arrival_time(hass): ], ) @pytest.mark.usefixtures("mock_update", "mock_config") -async def test_sensor_arrival_time_custom_timestamp(hass): +async def test_sensor_arrival_time_custom_timestamp(hass: HomeAssistant) -> None: """Test that sensor works for arrival time with a custom timestamp.""" assert hass.states.get("sensor.google_travel_time").state == "27" diff --git a/tests/components/govee_ble/test_config_flow.py b/tests/components/govee_ble/test_config_flow.py index 73cbb903f31..fee37a0a886 100644 --- a/tests/components/govee_ble/test_config_flow.py +++ b/tests/components/govee_ble/test_config_flow.py @@ -1,9 +1,9 @@ """Test the Govee config flow.""" - from unittest.mock import patch from homeassistant import config_entries from homeassistant.components.govee_ble.const import DOMAIN +from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType from . import GVH5075_SERVICE_INFO, GVH5177_SERVICE_INFO, NOT_GOVEE_SERVICE_INFO @@ -11,7 +11,7 @@ from . import GVH5075_SERVICE_INFO, GVH5177_SERVICE_INFO, NOT_GOVEE_SERVICE_INFO from tests.common import MockConfigEntry -async def test_async_step_bluetooth_valid_device(hass): +async def test_async_step_bluetooth_valid_device(hass: HomeAssistant) -> None: """Test discovery via bluetooth with a valid device.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -32,7 +32,7 @@ async def test_async_step_bluetooth_valid_device(hass): assert result2["result"].unique_id == "61DE521B-F0BF-9F44-64D4-75BBE1738105" -async def test_async_step_bluetooth_not_govee(hass): +async def test_async_step_bluetooth_not_govee(hass: HomeAssistant) -> None: """Test discovery via bluetooth not govee.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -43,7 +43,7 @@ async def test_async_step_bluetooth_not_govee(hass): assert result["reason"] == "not_supported" -async def test_async_step_user_no_devices_found(hass): +async def test_async_step_user_no_devices_found(hass: HomeAssistant) -> None: """Test setup from service info cache with no devices found.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -53,7 +53,7 @@ async def test_async_step_user_no_devices_found(hass): assert result["reason"] == "no_devices_found" -async def test_async_step_user_with_found_devices(hass): +async def test_async_step_user_with_found_devices(hass: HomeAssistant) -> None: """Test setup from service info cache with devices found.""" with patch( "homeassistant.components.govee_ble.config_flow.async_discovered_service_info", @@ -78,7 +78,7 @@ async def test_async_step_user_with_found_devices(hass): assert result2["result"].unique_id == "4125DDBA-2774-4851-9889-6AADDD4CAC3D" -async def test_async_step_user_device_added_between_steps(hass): +async def test_async_step_user_device_added_between_steps(hass: HomeAssistant) -> None: """Test the device gets added via another flow between steps.""" with patch( "homeassistant.components.govee_ble.config_flow.async_discovered_service_info", @@ -108,7 +108,9 @@ async def test_async_step_user_device_added_between_steps(hass): assert result2["reason"] == "already_configured" -async def test_async_step_user_with_found_devices_already_setup(hass): +async def test_async_step_user_with_found_devices_already_setup( + hass: HomeAssistant, +) -> None: """Test setup from service info cache with devices found.""" entry = MockConfigEntry( domain=DOMAIN, @@ -128,7 +130,7 @@ async def test_async_step_user_with_found_devices_already_setup(hass): assert result["reason"] == "no_devices_found" -async def test_async_step_bluetooth_devices_already_setup(hass): +async def test_async_step_bluetooth_devices_already_setup(hass: HomeAssistant) -> None: """Test we can't start a flow if there is already a config entry.""" entry = MockConfigEntry( domain=DOMAIN, @@ -145,7 +147,7 @@ async def test_async_step_bluetooth_devices_already_setup(hass): assert result["reason"] == "already_configured" -async def test_async_step_bluetooth_already_in_progress(hass): +async def test_async_step_bluetooth_already_in_progress(hass: HomeAssistant) -> None: """Test we can't start a flow for the same device twice.""" result = await hass.config_entries.flow.async_init( DOMAIN, @@ -164,7 +166,9 @@ async def test_async_step_bluetooth_already_in_progress(hass): assert result["reason"] == "already_in_progress" -async def test_async_step_user_takes_precedence_over_discovery(hass): +async def test_async_step_user_takes_precedence_over_discovery( + hass: HomeAssistant, +) -> None: """Test manual setup takes precedence over discovery.""" result = await hass.config_entries.flow.async_init( DOMAIN, diff --git a/tests/components/govee_ble/test_sensor.py b/tests/components/govee_ble/test_sensor.py index b27868c44bf..e9e66ba73e8 100644 --- a/tests/components/govee_ble/test_sensor.py +++ b/tests/components/govee_ble/test_sensor.py @@ -1,6 +1,4 @@ """Test the Govee BLE sensors.""" - - from homeassistant.components.govee_ble.const import DOMAIN from homeassistant.components.sensor import ATTR_STATE_CLASS from homeassistant.const import ( @@ -8,6 +6,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, STATE_UNAVAILABLE, ) +from homeassistant.core import HomeAssistant from . import GVH5075_SERVICE_INFO, GVH5178_SERVICE_INFO_ERROR @@ -15,7 +14,7 @@ from tests.common import MockConfigEntry from tests.components.bluetooth import inject_bluetooth_service_info -async def test_sensors(hass): +async def test_sensors(hass: HomeAssistant) -> None: """Test setting up creates the sensors.""" entry = MockConfigEntry( domain=DOMAIN, @@ -42,7 +41,7 @@ async def test_sensors(hass): await hass.async_block_till_done() -async def test_gvh5178_error(hass): +async def test_gvh5178_error(hass: HomeAssistant) -> None: """Test H5178 Remote in error marks state as unavailable.""" entry = MockConfigEntry( domain=DOMAIN, diff --git a/tests/components/gree/test_config_flow.py b/tests/components/gree/test_config_flow.py index 81a379e8fd8..97820b8928c 100644 --- a/tests/components/gree/test_config_flow.py +++ b/tests/components/gree/test_config_flow.py @@ -3,12 +3,13 @@ from unittest.mock import patch from homeassistant import config_entries, data_entry_flow from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN +from homeassistant.core import HomeAssistant from .common import FakeDiscovery @patch("homeassistant.components.gree.config_flow.DISCOVERY_TIMEOUT", 0) -async def test_creating_entry_sets_up_climate(hass): +async def test_creating_entry_sets_up_climate(hass: HomeAssistant) -> None: """Test setting up Gree creates the climate components.""" with patch( "homeassistant.components.gree.climate.async_setup_entry", return_value=True @@ -34,7 +35,7 @@ async def test_creating_entry_sets_up_climate(hass): @patch("homeassistant.components.gree.config_flow.DISCOVERY_TIMEOUT", 0) -async def test_creating_entry_has_no_devices(hass): +async def test_creating_entry_has_no_devices(hass: HomeAssistant) -> None: """Test setting up Gree creates the climate components.""" with patch( "homeassistant.components.gree.climate.async_setup_entry", return_value=True diff --git a/tests/components/gree/test_init.py b/tests/components/gree/test_init.py index 82b082b03cb..240b60e30d7 100644 --- a/tests/components/gree/test_init.py +++ b/tests/components/gree/test_init.py @@ -3,12 +3,13 @@ from unittest.mock import patch from homeassistant.components.gree.const import DOMAIN as GREE_DOMAIN from homeassistant.config_entries import ConfigEntryState +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry -async def test_setup_simple(hass): +async def test_setup_simple(hass: HomeAssistant) -> None: """Test gree integration is setup.""" entry = MockConfigEntry(domain=GREE_DOMAIN) entry.add_to_hass(hass) @@ -31,7 +32,7 @@ async def test_setup_simple(hass): assert len(hass.config_entries.flow.async_progress()) == 0 -async def test_unload_config_entry(hass): +async def test_unload_config_entry(hass: HomeAssistant) -> None: """Test that the async_unload_entry works.""" # As we have currently no configuration, we just to pass the domain here. entry = MockConfigEntry(domain=GREE_DOMAIN) diff --git a/tests/components/group/test_binary_sensor.py b/tests/components/group/test_binary_sensor.py index fbc19904faa..15198ac7c5b 100644 --- a/tests/components/group/test_binary_sensor.py +++ b/tests/components/group/test_binary_sensor.py @@ -8,11 +8,12 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component -async def test_default_state(hass): +async def test_default_state(hass: HomeAssistant) -> None: """Test binary_sensor group default state.""" hass.states.async_set("binary_sensor.kitchen", "on") hass.states.async_set("binary_sensor.bedroom", "on") @@ -49,7 +50,7 @@ async def test_default_state(hass): assert entry.original_device_class == "presence" -async def test_state_reporting_all(hass): +async def test_state_reporting_all(hass: HomeAssistant) -> None: """Test the state reporting in 'all' mode. The group state is unavailable if all group members are unavailable. @@ -144,7 +145,7 @@ async def test_state_reporting_all(hass): ) -async def test_state_reporting_any(hass): +async def test_state_reporting_any(hass: HomeAssistant) -> None: """Test the state reporting in 'any' mode. The group state is unavailable if all group members are unavailable. diff --git a/tests/components/group/test_cover.py b/tests/components/group/test_cover.py index 57c54c7c502..77205928111 100644 --- a/tests/components/group/test_cover.py +++ b/tests/components/group/test_cover.py @@ -36,6 +36,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -789,7 +790,7 @@ async def test_is_opening_closing(hass, setup_comp): assert hass.states.get(COVER_GROUP).state == STATE_OPENING -async def test_nested_group(hass): +async def test_nested_group(hass: HomeAssistant) -> None: """Test nested cover group.""" await async_setup_component( hass, diff --git a/tests/components/group/test_fan.py b/tests/components/group/test_fan.py index 1717da1d121..c1e1f03335f 100644 --- a/tests/components/group/test_fan.py +++ b/tests/components/group/test_fan.py @@ -34,7 +34,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) -from homeassistant.core import CoreState +from homeassistant.core import CoreState, HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component @@ -392,7 +392,7 @@ async def test_state_missing_entity_id(hass, setup_comp): assert state.state == STATE_OFF -async def test_setup_before_started(hass): +async def test_setup_before_started(hass: HomeAssistant) -> None: """Test we can setup before starting.""" hass.state = CoreState.stopped assert await async_setup_component(hass, DOMAIN, CONFIG_MISSING_FAN) @@ -534,7 +534,7 @@ async def test_service_calls(hass, setup_comp): assert fan_group_state.attributes[ATTR_DIRECTION] == DIRECTION_REVERSE -async def test_nested_group(hass): +async def test_nested_group(hass: HomeAssistant) -> None: """Test nested fan group.""" await async_setup_component( hass, diff --git a/tests/components/group/test_init.py b/tests/components/group/test_init.py index 594a20a8154..ae25491cc16 100644 --- a/tests/components/group/test_init.py +++ b/tests/components/group/test_init.py @@ -1,5 +1,4 @@ """The tests for the Group components.""" - from __future__ import annotations from collections import OrderedDict @@ -31,7 +30,7 @@ from . import common from tests.common import MockConfigEntry, assert_setup_component -async def test_setup_group_with_mixed_groupable_states(hass): +async def test_setup_group_with_mixed_groupable_states(hass: HomeAssistant) -> None: """Try to set up a group with mixed groupable states.""" hass.states.async_set("light.Bowl", STATE_ON) @@ -48,7 +47,7 @@ async def test_setup_group_with_mixed_groupable_states(hass): assert hass.states.get(f"{group.DOMAIN}.person_and_light").state == STATE_ON -async def test_setup_group_with_a_non_existing_state(hass): +async def test_setup_group_with_a_non_existing_state(hass: HomeAssistant) -> None: """Try to set up a group with a non existing state.""" hass.states.async_set("light.Bowl", STATE_ON) @@ -61,7 +60,7 @@ async def test_setup_group_with_a_non_existing_state(hass): assert grp.state == STATE_ON -async def test_setup_group_with_non_groupable_states(hass): +async def test_setup_group_with_non_groupable_states(hass: HomeAssistant) -> None: """Test setup with groups which are not groupable.""" hass.states.async_set("cast.living_room", "Plex") hass.states.async_set("cast.bedroom", "Netflix") @@ -75,14 +74,14 @@ async def test_setup_group_with_non_groupable_states(hass): assert grp.state is None -async def test_setup_empty_group(hass): +async def test_setup_empty_group(hass: HomeAssistant) -> None: """Try to set up an empty group.""" grp = await group.Group.async_create_group(hass, "nothing", []) assert grp.state is None -async def test_monitor_group(hass): +async def test_monitor_group(hass: HomeAssistant) -> None: """Test if the group keeps track of states.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -101,7 +100,7 @@ async def test_monitor_group(hass): assert group_state.attributes.get(group.ATTR_AUTO) -async def test_group_turns_off_if_all_off(hass): +async def test_group_turns_off_if_all_off(hass: HomeAssistant) -> None: """Test if turn off if the last device that was on turns off.""" hass.states.async_set("light.Bowl", STATE_OFF) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -118,7 +117,9 @@ async def test_group_turns_off_if_all_off(hass): assert group_state.state == STATE_OFF -async def test_group_turns_on_if_all_are_off_and_one_turns_on(hass): +async def test_group_turns_on_if_all_are_off_and_one_turns_on( + hass: HomeAssistant, +) -> None: """Test if turn on if all devices were turned off and one turns on.""" hass.states.async_set("light.Bowl", STATE_OFF) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -137,7 +138,9 @@ async def test_group_turns_on_if_all_are_off_and_one_turns_on(hass): assert group_state.state == STATE_ON -async def test_allgroup_stays_off_if_all_are_off_and_one_turns_on(hass): +async def test_allgroup_stays_off_if_all_are_off_and_one_turns_on( + hass: HomeAssistant, +) -> None: """Group with all: true, stay off if one device turns on.""" hass.states.async_set("light.Bowl", STATE_OFF) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -156,7 +159,7 @@ async def test_allgroup_stays_off_if_all_are_off_and_one_turns_on(hass): assert group_state.state == STATE_OFF -async def test_allgroup_turn_on_if_last_turns_on(hass): +async def test_allgroup_turn_on_if_last_turns_on(hass: HomeAssistant) -> None: """Group with all: true, turn on if all devices are on.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -175,7 +178,7 @@ async def test_allgroup_turn_on_if_last_turns_on(hass): assert group_state.state == STATE_ON -async def test_expand_entity_ids(hass): +async def test_expand_entity_ids(hass: HomeAssistant) -> None: """Test expand_entity_ids method.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -191,7 +194,9 @@ async def test_expand_entity_ids(hass): ) -async def test_expand_entity_ids_does_not_return_duplicates(hass): +async def test_expand_entity_ids_does_not_return_duplicates( + hass: HomeAssistant, +) -> None: """Test that expand_entity_ids does not return duplicates.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -211,7 +216,7 @@ async def test_expand_entity_ids_does_not_return_duplicates(hass): ) -async def test_expand_entity_ids_recursive(hass): +async def test_expand_entity_ids_recursive(hass: HomeAssistant) -> None: """Test expand_entity_ids method with a group that contains itself.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -230,12 +235,12 @@ async def test_expand_entity_ids_recursive(hass): ) -async def test_expand_entity_ids_ignores_non_strings(hass): +async def test_expand_entity_ids_ignores_non_strings(hass: HomeAssistant) -> None: """Test that non string elements in lists are ignored.""" assert [] == group.expand_entity_ids(hass, [5, True]) -async def test_get_entity_ids(hass): +async def test_get_entity_ids(hass: HomeAssistant) -> None: """Test get_entity_ids method.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -251,7 +256,7 @@ async def test_get_entity_ids(hass): ) -async def test_get_entity_ids_with_domain_filter(hass): +async def test_get_entity_ids_with_domain_filter(hass: HomeAssistant) -> None: """Test if get_entity_ids works with a domain_filter.""" hass.states.async_set("switch.AC", STATE_OFF) @@ -266,17 +271,19 @@ async def test_get_entity_ids_with_domain_filter(hass): ) -async def test_get_entity_ids_with_non_existing_group_name(hass): +async def test_get_entity_ids_with_non_existing_group_name(hass: HomeAssistant) -> None: """Test get_entity_ids with a non existing group.""" assert [] == group.get_entity_ids(hass, "non_existing") -async def test_get_entity_ids_with_non_group_state(hass): +async def test_get_entity_ids_with_non_group_state(hass: HomeAssistant) -> None: """Test get_entity_ids with a non group state.""" assert [] == group.get_entity_ids(hass, "switch.AC") -async def test_group_being_init_before_first_tracked_state_is_set_to_on(hass): +async def test_group_being_init_before_first_tracked_state_is_set_to_on( + hass: HomeAssistant, +) -> None: """Test if the groups turn on. If no states existed and now a state it is tracking is being added @@ -297,7 +304,9 @@ async def test_group_being_init_before_first_tracked_state_is_set_to_on(hass): assert group_state.state == STATE_ON -async def test_group_being_init_before_first_tracked_state_is_set_to_off(hass): +async def test_group_being_init_before_first_tracked_state_is_set_to_off( + hass: HomeAssistant, +) -> None: """Test if the group turns off. If no states existed and now a state it is tracking is being added @@ -316,7 +325,7 @@ async def test_group_being_init_before_first_tracked_state_is_set_to_off(hass): assert group_state.state == STATE_OFF -async def test_groups_get_unique_names(hass): +async def test_groups_get_unique_names(hass: HomeAssistant) -> None: """Two groups with same name should both have a unique entity id.""" assert await async_setup_component(hass, "group", {}) @@ -327,7 +336,7 @@ async def test_groups_get_unique_names(hass): assert grp1.entity_id != grp2.entity_id -async def test_expand_entity_ids_expands_nested_groups(hass): +async def test_expand_entity_ids_expands_nested_groups(hass: HomeAssistant) -> None: """Test if entity ids epands to nested groups.""" assert await async_setup_component(hass, "group", {}) @@ -350,7 +359,7 @@ async def test_expand_entity_ids_expands_nested_groups(hass): ] == sorted(group.expand_entity_ids(hass, ["group.group_of_groups"])) -async def test_set_assumed_state_based_on_tracked(hass): +async def test_set_assumed_state_based_on_tracked(hass: HomeAssistant) -> None: """Test assumed state.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -377,7 +386,9 @@ async def test_set_assumed_state_based_on_tracked(hass): assert not state.attributes.get(ATTR_ASSUMED_STATE) -async def test_group_updated_after_device_tracker_zone_change(hass): +async def test_group_updated_after_device_tracker_zone_change( + hass: HomeAssistant, +) -> None: """Test group state when device tracker in group changes zone.""" hass.states.async_set("device_tracker.Adam", STATE_HOME) hass.states.async_set("device_tracker.Eve", STATE_NOT_HOME) @@ -395,7 +406,7 @@ async def test_group_updated_after_device_tracker_zone_change(hass): assert hass.states.get(f"{group.DOMAIN}.peeps").state == STATE_NOT_HOME -async def test_is_on(hass): +async def test_is_on(hass: HomeAssistant) -> None: """Test is_on method.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -419,7 +430,7 @@ async def test_is_on(hass): assert not group.is_on(hass, "non.existing") -async def test_reloading_groups(hass): +async def test_reloading_groups(hass: HomeAssistant) -> None: """Test reloading the group config.""" assert await async_setup_component( hass, @@ -471,7 +482,7 @@ async def test_reloading_groups(hass): assert len(hass.data[TRACK_STATE_CHANGE_CALLBACKS]["test.two"]) == 1 -async def test_modify_group(hass): +async def test_modify_group(hass: HomeAssistant) -> None: """Test modifying a group.""" group_conf = OrderedDict() group_conf["modify_group"] = { @@ -497,7 +508,7 @@ async def test_modify_group(hass): assert group_state.attributes.get(ATTR_FRIENDLY_NAME) == "friendly_name" -async def test_setup(hass): +async def test_setup(hass: HomeAssistant) -> None: """Test setup method.""" hass.states.async_set("light.Bowl", STATE_ON) hass.states.async_set("light.Ceiling", STATE_OFF) @@ -540,7 +551,7 @@ async def test_setup(hass): assert group_state.attributes.get(group.ATTR_ORDER) == 0 -async def test_service_group_services(hass): +async def test_service_group_services(hass: HomeAssistant) -> None: """Check if service are available.""" with assert_setup_component(0, "group"): await async_setup_component(hass, "group", {"group": {}}) @@ -606,7 +617,7 @@ async def test_service_group_services_add_remove_entities(hass: HomeAssistant) - # pylint: disable=invalid-name -async def test_service_group_set_group_remove_group(hass): +async def test_service_group_set_group_remove_group(hass: HomeAssistant) -> None: """Check if service are available.""" with assert_setup_component(0, "group"): await async_setup_component(hass, "group", {"group": {}}) @@ -653,7 +664,7 @@ async def test_service_group_set_group_remove_group(hass): assert group_state is None -async def test_group_order(hass): +async def test_group_order(hass: HomeAssistant) -> None: """Test that order gets incremented when creating a new group.""" hass.states.async_set("light.bowl", STATE_ON) @@ -676,7 +687,7 @@ async def test_group_order(hass): assert hass.states.get("group.group_two").attributes["order"] == 2 -async def test_group_order_with_dynamic_creation(hass): +async def test_group_order_with_dynamic_creation(hass: HomeAssistant) -> None: """Test that order gets incremented when creating a new group.""" hass.states.async_set("light.bowl", STATE_ON) @@ -728,7 +739,7 @@ async def test_group_order_with_dynamic_creation(hass): assert hass.states.get("group.new_group2").attributes["order"] == 4 -async def test_group_persons(hass): +async def test_group_persons(hass: HomeAssistant) -> None: """Test group of persons.""" hass.states.async_set("person.one", "Work") hass.states.async_set("person.two", "Work") @@ -749,7 +760,7 @@ async def test_group_persons(hass): assert hass.states.get("group.group_zero").state == "home" -async def test_group_persons_and_device_trackers(hass): +async def test_group_persons_and_device_trackers(hass: HomeAssistant) -> None: """Test group of persons and device_tracker.""" hass.states.async_set("person.one", "Work") hass.states.async_set("person.two", "Work") @@ -774,7 +785,7 @@ async def test_group_persons_and_device_trackers(hass): assert hass.states.get("group.group_zero").state == "home" -async def test_group_mixed_domains_on(hass): +async def test_group_mixed_domains_on(hass: HomeAssistant) -> None: """Test group of mixed domains that is on.""" hass.states.async_set("lock.alexander_garage_exit_door", "unlocked") hass.states.async_set("binary_sensor.alexander_garage_side_door_open", "on") @@ -799,7 +810,7 @@ async def test_group_mixed_domains_on(hass): assert hass.states.get("group.group_zero").state == "on" -async def test_group_mixed_domains_off(hass): +async def test_group_mixed_domains_off(hass: HomeAssistant) -> None: """Test group of mixed domains that is off.""" hass.states.async_set("lock.alexander_garage_exit_door", "locked") hass.states.async_set("binary_sensor.alexander_garage_side_door_open", "off") @@ -852,7 +863,7 @@ async def test_group_locks(hass, states, group_state): assert hass.states.get("group.group_zero").state == group_state -async def test_group_sensors(hass): +async def test_group_sensors(hass: HomeAssistant) -> None: """Test group of sensors.""" hass.states.async_set("sensor.one", "locked") hass.states.async_set("sensor.two", "on") @@ -873,7 +884,7 @@ async def test_group_sensors(hass): assert hass.states.get("group.group_zero").state == "unknown" -async def test_group_climate_mixed(hass): +async def test_group_climate_mixed(hass: HomeAssistant) -> None: """Test group of climate with mixed states.""" hass.states.async_set("climate.one", "off") hass.states.async_set("climate.two", "cool") @@ -894,7 +905,7 @@ async def test_group_climate_mixed(hass): assert hass.states.get("group.group_zero").state == STATE_ON -async def test_group_climate_all_cool(hass): +async def test_group_climate_all_cool(hass: HomeAssistant) -> None: """Test group of climate all set to cool.""" hass.states.async_set("climate.one", "cool") hass.states.async_set("climate.two", "cool") @@ -915,7 +926,7 @@ async def test_group_climate_all_cool(hass): assert hass.states.get("group.group_zero").state == STATE_ON -async def test_group_climate_all_off(hass): +async def test_group_climate_all_off(hass: HomeAssistant) -> None: """Test group of climate all set to off.""" hass.states.async_set("climate.one", "off") hass.states.async_set("climate.two", "off") @@ -936,7 +947,7 @@ async def test_group_climate_all_off(hass): assert hass.states.get("group.group_zero").state == STATE_OFF -async def test_group_alarm(hass): +async def test_group_alarm(hass: HomeAssistant) -> None: """Test group of alarm control panels.""" hass.states.async_set("alarm_control_panel.one", "armed_away") hass.states.async_set("alarm_control_panel.two", "armed_home") @@ -961,7 +972,7 @@ async def test_group_alarm(hass): assert hass.states.get("group.group_zero").state == STATE_ON -async def test_group_alarm_disarmed(hass): +async def test_group_alarm_disarmed(hass: HomeAssistant) -> None: """Test group of alarm control panels disarmed.""" hass.states.async_set("alarm_control_panel.one", "disarmed") hass.states.async_set("alarm_control_panel.two", "disarmed") @@ -984,7 +995,7 @@ async def test_group_alarm_disarmed(hass): assert hass.states.get("group.group_zero").state == STATE_OFF -async def test_group_vacuum_off(hass): +async def test_group_vacuum_off(hass: HomeAssistant) -> None: """Test group of vacuums.""" hass.states.async_set("vacuum.one", "docked") hass.states.async_set("vacuum.two", "off") @@ -1008,7 +1019,7 @@ async def test_group_vacuum_off(hass): assert hass.states.get("group.group_zero").state == STATE_OFF -async def test_group_vacuum_on(hass): +async def test_group_vacuum_on(hass: HomeAssistant) -> None: """Test group of vacuums.""" hass.states.async_set("vacuum.one", "cleaning") hass.states.async_set("vacuum.two", "off") @@ -1029,7 +1040,7 @@ async def test_group_vacuum_on(hass): assert hass.states.get("group.group_zero").state == STATE_ON -async def test_device_tracker_not_home(hass): +async def test_device_tracker_not_home(hass: HomeAssistant) -> None: """Test group of device_tracker not_home.""" hass.states.async_set("device_tracker.one", "not_home") hass.states.async_set("device_tracker.two", "not_home") @@ -1051,7 +1062,7 @@ async def test_device_tracker_not_home(hass): assert hass.states.get("group.group_zero").state == "not_home" -async def test_light_removed(hass): +async def test_light_removed(hass: HomeAssistant) -> None: """Test group of lights when one is removed.""" hass.states.async_set("light.one", "off") hass.states.async_set("light.two", "off") @@ -1076,7 +1087,7 @@ async def test_light_removed(hass): assert hass.states.get("group.group_zero").state == "off" -async def test_switch_removed(hass): +async def test_switch_removed(hass: HomeAssistant) -> None: """Test group of switches when one is removed.""" hass.states.async_set("switch.one", "off") hass.states.async_set("switch.two", "off") @@ -1108,7 +1119,7 @@ async def test_switch_removed(hass): assert hass.states.get("group.group_zero").state == "off" -async def test_lights_added_after_group(hass): +async def test_lights_added_after_group(hass: HomeAssistant) -> None: """Test lights added after group.""" entity_ids = [ @@ -1140,7 +1151,7 @@ async def test_lights_added_after_group(hass): assert hass.states.get("group.living_room_downlights").state == "off" -async def test_lights_added_before_group(hass): +async def test_lights_added_before_group(hass: HomeAssistant) -> None: """Test lights added before group.""" entity_ids = [ @@ -1170,7 +1181,7 @@ async def test_lights_added_before_group(hass): assert hass.states.get("group.living_room_downlights").state == "off" -async def test_cover_added_after_group(hass): +async def test_cover_added_after_group(hass: HomeAssistant) -> None: """Test cover added after group.""" entity_ids = [ @@ -1204,7 +1215,7 @@ async def test_cover_added_after_group(hass): assert hass.states.get("group.shades").state == "closed" -async def test_group_that_references_a_group_of_lights(hass): +async def test_group_that_references_a_group_of_lights(hass: HomeAssistant) -> None: """Group that references a group of lights.""" entity_ids = [ @@ -1238,7 +1249,7 @@ async def test_group_that_references_a_group_of_lights(hass): assert hass.states.get("group.grouped_group").state == "off" -async def test_group_that_references_a_group_of_covers(hass): +async def test_group_that_references_a_group_of_covers(hass: HomeAssistant) -> None: """Group that references a group of covers.""" entity_ids = [ @@ -1274,7 +1285,7 @@ async def test_group_that_references_a_group_of_covers(hass): assert hass.states.get("group.grouped_group").state == "closed" -async def test_group_that_references_two_groups_of_covers(hass): +async def test_group_that_references_two_groups_of_covers(hass: HomeAssistant) -> None: """Group that references a group of covers.""" entity_ids = [ @@ -1314,7 +1325,7 @@ async def test_group_that_references_two_groups_of_covers(hass): assert hass.states.get("group.grouped_group").state == "closed" -async def test_group_that_references_two_types_of_groups(hass): +async def test_group_that_references_two_types_of_groups(hass: HomeAssistant) -> None: """Group that references a group of covers and device_trackers.""" group_1_entity_ids = [ @@ -1358,7 +1369,7 @@ async def test_group_that_references_two_types_of_groups(hass): assert hass.states.get("group.grouped_group").state == "on" -async def test_plant_group(hass): +async def test_plant_group(hass: HomeAssistant) -> None: """Test plant states can be grouped.""" entity_ids = [ diff --git a/tests/components/group/test_light.py b/tests/components/group/test_light.py index 3ba4aaaad81..9d21eebfbf3 100644 --- a/tests/components/group/test_light.py +++ b/tests/components/group/test_light.py @@ -44,13 +44,14 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_default_state(hass): +async def test_default_state(hass: HomeAssistant) -> None: """Test light group default state.""" hass.states.async_set("light.kitchen", "on") await async_setup_component( @@ -87,7 +88,7 @@ async def test_default_state(hass): assert entry.unique_id == "unique_identifier" -async def test_state_reporting_any(hass): +async def test_state_reporting_any(hass: HomeAssistant) -> None: """Test the state reporting in 'any' mode. The group state is unavailable if all group members are unavailable. @@ -175,7 +176,7 @@ async def test_state_reporting_any(hass): assert hass.states.get("light.light_group").state == STATE_UNAVAILABLE -async def test_state_reporting_all(hass): +async def test_state_reporting_all(hass: HomeAssistant) -> None: """Test the state reporting in 'all' mode. The group state is unavailable if all group members are unavailable. @@ -875,7 +876,7 @@ async def test_min_max_mireds(hass, enable_custom_integrations): assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 1234567890 -async def test_effect_list(hass): +async def test_effect_list(hass: HomeAssistant) -> None: """Test effect_list reporting.""" await async_setup_component( hass, @@ -935,7 +936,7 @@ async def test_effect_list(hass): } -async def test_effect(hass): +async def test_effect(hass: HomeAssistant) -> None: """Test effect reporting.""" await async_setup_component( hass, @@ -1178,7 +1179,7 @@ async def test_color_mode2(hass, enable_custom_integrations): assert state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS -async def test_supported_features(hass): +async def test_supported_features(hass: HomeAssistant) -> None: """Test supported features reporting.""" await async_setup_component( hass, @@ -1361,7 +1362,7 @@ async def test_service_calls(hass, enable_custom_integrations, supported_color_m assert state.attributes[ATTR_RGB_COLOR] == (255, 0, 0) -async def test_service_call_effect(hass): +async def test_service_call_effect(hass: HomeAssistant) -> None: """Test service calls.""" await async_setup_component( hass, @@ -1416,7 +1417,7 @@ async def test_service_call_effect(hass): assert state.attributes[ATTR_RGB_COLOR] == (42, 255, 255) -async def test_invalid_service_calls(hass): +async def test_invalid_service_calls(hass: HomeAssistant) -> None: """Test invalid service call arguments get discarded.""" add_entities = MagicMock() await group.async_setup_platform( @@ -1461,7 +1462,7 @@ async def test_invalid_service_calls(hass): ) -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Test the ability to reload lights.""" await async_setup_component( hass, @@ -1504,7 +1505,7 @@ async def test_reload(hass): assert hass.states.get("light.outside_patio_lights_g") is not None -async def test_reload_with_platform_not_setup(hass): +async def test_reload_with_platform_not_setup(hass: HomeAssistant) -> None: """Test the ability to reload lights.""" hass.states.async_set("light.bowl", STATE_ON) await async_setup_component( @@ -1542,7 +1543,9 @@ async def test_reload_with_platform_not_setup(hass): assert hass.states.get("light.outside_patio_lights_g") is not None -async def test_reload_with_base_integration_platform_not_setup(hass): +async def test_reload_with_base_integration_platform_not_setup( + hass: HomeAssistant, +) -> None: """Test the ability to reload lights.""" assert await async_setup_component( hass, @@ -1577,7 +1580,7 @@ async def test_reload_with_base_integration_platform_not_setup(hass): assert hass.states.get("light.outside_patio_lights_g").state == STATE_OFF -async def test_nested_group(hass): +async def test_nested_group(hass: HomeAssistant) -> None: """Test nested light group.""" await async_setup_component( hass, diff --git a/tests/components/group/test_lock.py b/tests/components/group/test_lock.py index 16dc3797daf..b8a1838bca5 100644 --- a/tests/components/group/test_lock.py +++ b/tests/components/group/test_lock.py @@ -31,7 +31,7 @@ from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_default_state(hass): +async def test_default_state(hass: HomeAssistant) -> None: """Test lock group default state.""" hass.states.async_set("lock.front", "locked") await async_setup_component( @@ -61,7 +61,7 @@ async def test_default_state(hass): assert entry.unique_id == "unique_identifier" -async def test_state_reporting(hass): +async def test_state_reporting(hass: HomeAssistant) -> None: """Test the state reporting. The group state is unavailable if all group members are unavailable. @@ -277,7 +277,7 @@ async def test_service_calls_basic(hass: HomeAssistant) -> None: ) -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Test the ability to reload locks.""" await async_setup_component( hass, @@ -318,7 +318,7 @@ async def test_reload(hass): assert hass.states.get("lock.outside_locks_g") is not None -async def test_reload_with_platform_not_setup(hass): +async def test_reload_with_platform_not_setup(hass: HomeAssistant) -> None: """Test the ability to reload locks.""" hass.states.async_set("lock.something", STATE_UNLOCKED) await async_setup_component( @@ -356,7 +356,9 @@ async def test_reload_with_platform_not_setup(hass): assert hass.states.get("lock.outside_locks_g") is not None -async def test_reload_with_base_integration_platform_not_setup(hass): +async def test_reload_with_base_integration_platform_not_setup( + hass: HomeAssistant, +) -> None: """Test the ability to reload locks.""" assert await async_setup_component( hass, @@ -392,7 +394,7 @@ async def test_reload_with_base_integration_platform_not_setup(hass): @patch.object(demo_lock, "LOCK_UNLOCK_DELAY", 0) -async def test_nested_group(hass): +async def test_nested_group(hass: HomeAssistant) -> None: """Test nested lock group.""" await async_setup_component( hass, diff --git a/tests/components/group/test_notify.py b/tests/components/group/test_notify.py index ad0be58dd16..6e4f9b50393 100644 --- a/tests/components/group/test_notify.py +++ b/tests/components/group/test_notify.py @@ -6,12 +6,13 @@ import homeassistant.components.demo.notify as demo from homeassistant.components.group import SERVICE_RELOAD import homeassistant.components.group.notify as group import homeassistant.components.notify as notify +from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_send_message_with_data(hass): +async def test_send_message_with_data(hass: HomeAssistant) -> None: """Test sending a message with to a notify group.""" service1 = demo.DemoNotificationService(hass) service2 = demo.DemoNotificationService(hass) @@ -80,7 +81,7 @@ async def test_send_message_with_data(hass): } -async def test_reload_notify(hass): +async def test_reload_notify(hass: HomeAssistant) -> None: """Verify we can reload the notify service.""" assert await async_setup_component( diff --git a/tests/components/group/test_reproduce_state.py b/tests/components/group/test_reproduce_state.py index bee3883aad2..ea9c6e9d43d 100644 --- a/tests/components/group/test_reproduce_state.py +++ b/tests/components/group/test_reproduce_state.py @@ -1,13 +1,12 @@ """The tests for reproduction of state.""" - from asyncio import Future from unittest.mock import ANY, patch from homeassistant.components.group.reproduce_state import async_reproduce_states -from homeassistant.core import Context, State +from homeassistant.core import Context, HomeAssistant, State -async def test_reproduce_group(hass): +async def test_reproduce_group(hass: HomeAssistant) -> None: """Test reproduce_state with group.""" context = Context() diff --git a/tests/components/group/test_switch.py b/tests/components/group/test_switch.py index 9a8da274a0a..91ba5dd7ecd 100644 --- a/tests/components/group/test_switch.py +++ b/tests/components/group/test_switch.py @@ -18,13 +18,14 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from homeassistant.setup import async_setup_component from tests.common import get_fixture_path -async def test_default_state(hass): +async def test_default_state(hass: HomeAssistant) -> None: """Test switch group default state.""" hass.states.async_set("switch.tv", "on") await async_setup_component( @@ -55,7 +56,7 @@ async def test_default_state(hass): assert entry.unique_id == "unique_identifier" -async def test_state_reporting(hass): +async def test_state_reporting(hass: HomeAssistant) -> None: """Test the state reporting in 'any' mode. The group state is unavailable if all group members are unavailable. @@ -143,7 +144,7 @@ async def test_state_reporting(hass): assert hass.states.get("switch.switch_group").state == STATE_UNAVAILABLE -async def test_state_reporting_all(hass): +async def test_state_reporting_all(hass: HomeAssistant) -> None: """Test the state reporting in 'all' mode. The group state is unavailable if all group members are unavailable. @@ -284,7 +285,7 @@ async def test_service_calls(hass, enable_custom_integrations): assert hass.states.get("switch.decorative_lights").state == STATE_OFF -async def test_reload(hass): +async def test_reload(hass: HomeAssistant) -> None: """Test the ability to reload switches.""" await async_setup_component( hass, @@ -326,7 +327,7 @@ async def test_reload(hass): assert hass.states.get("switch.outside_switches_g") is not None -async def test_reload_with_platform_not_setup(hass): +async def test_reload_with_platform_not_setup(hass: HomeAssistant) -> None: """Test the ability to reload switches.""" hass.states.async_set("switch.something", STATE_ON) await async_setup_component( @@ -364,7 +365,9 @@ async def test_reload_with_platform_not_setup(hass): assert hass.states.get("switch.outside_switches_g") is not None -async def test_reload_with_base_integration_platform_not_setup(hass): +async def test_reload_with_base_integration_platform_not_setup( + hass: HomeAssistant, +) -> None: """Test the ability to reload switches.""" assert await async_setup_component( hass, @@ -399,7 +402,7 @@ async def test_reload_with_base_integration_platform_not_setup(hass): assert hass.states.get("switch.outside_switches_g").state == STATE_OFF -async def test_nested_group(hass): +async def test_nested_group(hass: HomeAssistant) -> None: """Test nested switch group.""" await async_setup_component( hass, diff --git a/tests/components/growatt_server/test_config_flow.py b/tests/components/growatt_server/test_config_flow.py index f4e499a3eda..8455495165a 100644 --- a/tests/components/growatt_server/test_config_flow.py +++ b/tests/components/growatt_server/test_config_flow.py @@ -10,6 +10,7 @@ from homeassistant.components.growatt_server.const import ( LOGIN_INVALID_AUTH_CODE, ) from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -44,7 +45,7 @@ GROWATT_PLANT_LIST_RESPONSE = { GROWATT_LOGIN_RESPONSE = {"user": {"id": 123456}, "userLevel": 1, "success": True} -async def test_show_authenticate_form(hass): +async def test_show_authenticate_form(hass: HomeAssistant) -> None: """Test that the setup form is served.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -54,7 +55,7 @@ async def test_show_authenticate_form(hass): assert result["step_id"] == "user" -async def test_incorrect_login(hass): +async def test_incorrect_login(hass: HomeAssistant) -> None: """Test that it shows the appropriate error when an incorrect username/password/server is entered.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -73,7 +74,7 @@ async def test_incorrect_login(hass): assert result["errors"] == {"base": "invalid_auth"} -async def test_no_plants_on_account(hass): +async def test_no_plants_on_account(hass: HomeAssistant) -> None: """Test registering an integration and finishing flow with an entered plant_id.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -93,7 +94,7 @@ async def test_no_plants_on_account(hass): assert result["reason"] == "no_plants" -async def test_multiple_plant_ids(hass): +async def test_multiple_plant_ids(hass: HomeAssistant) -> None: """Test registering an integration and finishing flow with an entered plant_id.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -125,7 +126,7 @@ async def test_multiple_plant_ids(hass): assert result["data"][CONF_PLANT_ID] == "123456" -async def test_one_plant_on_account(hass): +async def test_one_plant_on_account(hass: HomeAssistant) -> None: """Test registering an integration and finishing flow with an entered plant_id.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -150,7 +151,7 @@ async def test_one_plant_on_account(hass): assert result["data"][CONF_PLANT_ID] == "123456" -async def test_existing_plant_configured(hass): +async def test_existing_plant_configured(hass: HomeAssistant) -> None: """Test entering an existing plant_id.""" entry = MockConfigEntry(domain=DOMAIN, unique_id="123456") entry.add_to_hass(hass) diff --git a/tests/components/guardian/test_config_flow.py b/tests/components/guardian/test_config_flow.py index 92b9ab6fdea..0b144df8cf7 100644 --- a/tests/components/guardian/test_config_flow.py +++ b/tests/components/guardian/test_config_flow.py @@ -12,6 +12,7 @@ from homeassistant.components.guardian.config_flow import ( ) from homeassistant.config_entries import SOURCE_DHCP, SOURCE_USER, SOURCE_ZEROCONF from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT +from homeassistant.core import HomeAssistant from tests.common import MockConfigEntry @@ -100,7 +101,7 @@ async def test_step_zeroconf(hass, setup_guardian): } -async def test_step_zeroconf_already_in_progress(hass): +async def test_step_zeroconf_already_in_progress(hass: HomeAssistant) -> None: """Test the zeroconf step aborting because it's already in progress.""" zeroconf_data = zeroconf.ZeroconfServiceInfo( host="192.168.1.100", @@ -151,7 +152,7 @@ async def test_step_dhcp(hass, setup_guardian): } -async def test_step_dhcp_already_in_progress(hass): +async def test_step_dhcp_already_in_progress(hass: HomeAssistant) -> None: """Test the zeroconf step aborting because it's already in progress.""" dhcp_data = dhcp.DhcpServiceInfo( ip="192.168.1.100", @@ -172,7 +173,7 @@ async def test_step_dhcp_already_in_progress(hass): assert result["reason"] == "already_in_progress" -async def test_step_dhcp_already_setup_match_mac(hass): +async def test_step_dhcp_already_setup_match_mac(hass: HomeAssistant) -> None: """Test we abort if the device is already setup with matching unique id and discovered via DHCP.""" entry = MockConfigEntry( domain=DOMAIN, data={CONF_IP_ADDRESS: "1.2.3.4"}, unique_id="guardian_ABCD" @@ -192,7 +193,7 @@ async def test_step_dhcp_already_setup_match_mac(hass): assert result["reason"] == "already_configured" -async def test_step_dhcp_already_setup_match_ip(hass): +async def test_step_dhcp_already_setup_match_ip(hass: HomeAssistant) -> None: """Test we abort if the device is already setup with matching ip and discovered via DHCP.""" entry = MockConfigEntry( domain=DOMAIN,