From c4c623ea996cefef6b4653bdf9f2e0544f7201e3 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 8 Jul 2024 12:54:18 +0200 Subject: [PATCH] Improve type hints in kulersky tests (#121510) --- tests/components/kulersky/test_light.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/components/kulersky/test_light.py b/tests/components/kulersky/test_light.py index 90f40d327e4..a2245e721c5 100644 --- a/tests/components/kulersky/test_light.py +++ b/tests/components/kulersky/test_light.py @@ -1,5 +1,6 @@ """Test the Kuler Sky lights.""" +from collections.abc import AsyncGenerator from unittest.mock import MagicMock, patch import pykulersky @@ -37,13 +38,15 @@ from tests.common import MockConfigEntry, async_fire_time_changed @pytest.fixture -async def mock_entry(hass): +async def mock_entry() -> MockConfigEntry: """Create a mock light entity.""" return MockConfigEntry(domain=DOMAIN) @pytest.fixture -async def mock_light(hass, mock_entry): +async def mock_light( + hass: HomeAssistant, mock_entry: MockConfigEntry +) -> AsyncGenerator[MagicMock]: """Create a mock light entity.""" light = MagicMock(spec=pykulersky.Light) @@ -64,7 +67,7 @@ async def mock_light(hass, mock_entry): yield light -async def test_init(hass: HomeAssistant, mock_light) -> None: +async def test_init(hass: HomeAssistant, mock_light: MagicMock) -> None: """Test platform setup.""" state = hass.states.get("light.bedroom") assert state.state == STATE_OFF @@ -87,7 +90,9 @@ async def test_init(hass: HomeAssistant, mock_light) -> None: assert mock_light.disconnect.called -async def test_remove_entry(hass: HomeAssistant, mock_light, mock_entry) -> None: +async def test_remove_entry( + hass: HomeAssistant, mock_light: MagicMock, mock_entry: MockConfigEntry +) -> None: """Test platform setup.""" assert hass.data[DOMAIN][DATA_ADDRESSES] == {"AA:BB:CC:11:22:33"} assert DATA_DISCOVERY_SUBSCRIPTION in hass.data[DOMAIN] @@ -99,7 +104,7 @@ async def test_remove_entry(hass: HomeAssistant, mock_light, mock_entry) -> None async def test_remove_entry_exceptions_caught( - hass: HomeAssistant, mock_light, mock_entry + hass: HomeAssistant, mock_light: MagicMock, mock_entry: MockConfigEntry ) -> None: """Assert that disconnect exceptions are caught.""" mock_light.disconnect.side_effect = pykulersky.PykulerskyException("Mock error") @@ -108,7 +113,7 @@ async def test_remove_entry_exceptions_caught( assert mock_light.disconnect.called -async def test_update_exception(hass: HomeAssistant, mock_light) -> None: +async def test_update_exception(hass: HomeAssistant, mock_light: MagicMock) -> None: """Test platform setup.""" mock_light.get_color.side_effect = pykulersky.PykulerskyException @@ -118,7 +123,7 @@ async def test_update_exception(hass: HomeAssistant, mock_light) -> None: assert state.state == STATE_UNAVAILABLE -async def test_light_turn_on(hass: HomeAssistant, mock_light) -> None: +async def test_light_turn_on(hass: HomeAssistant, mock_light: MagicMock) -> None: """Test KulerSkyLight turn_on.""" mock_light.get_color.return_value = (255, 255, 255, 255) await hass.services.async_call( @@ -175,7 +180,7 @@ async def test_light_turn_on(hass: HomeAssistant, mock_light) -> None: mock_light.set_color.assert_called_with(50, 41, 0, 50) -async def test_light_turn_off(hass: HomeAssistant, mock_light) -> None: +async def test_light_turn_off(hass: HomeAssistant, mock_light: MagicMock) -> None: """Test KulerSkyLight turn_on.""" mock_light.get_color.return_value = (0, 0, 0, 0) await hass.services.async_call( @@ -188,7 +193,7 @@ async def test_light_turn_off(hass: HomeAssistant, mock_light) -> None: mock_light.set_color.assert_called_with(0, 0, 0, 0) -async def test_light_update(hass: HomeAssistant, mock_light) -> None: +async def test_light_update(hass: HomeAssistant, mock_light: MagicMock) -> None: """Test KulerSkyLight update.""" utcnow = dt_util.utcnow()