From ef7316d8d9d462e9b2d57dd9333f4a181bc53a4c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 11 Jan 2022 21:28:13 +0100 Subject: [PATCH] Update typing (5) [tests] (#63926) --- .../components/hue/device_trigger.py | 7 ++++--- tests/components/amberelectric/test_sensor.py | 6 +++--- tests/components/greeneye_monitor/conftest.py | 4 ++-- tests/components/nina/test_binary_sensor.py | 10 +++++----- tests/components/nina/test_init.py | 6 +++--- tests/components/picnic/test_sensor.py | 3 +-- tests/components/tplink/test_light.py | 4 ++-- tests/components/upnp/conftest.py | 20 ++++++++++--------- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/hue/device_trigger.py b/homeassistant/components/hue/device_trigger.py index 76fb8cd6c96..ee0453c9da6 100644 --- a/homeassistant/components/hue/device_trigger.py +++ b/homeassistant/components/hue/device_trigger.py @@ -1,4 +1,5 @@ """Provides device automations for Philips Hue events.""" +from __future__ import annotations from typing import TYPE_CHECKING @@ -47,7 +48,7 @@ async def async_validate_trigger_config(hass: "HomeAssistant", config: ConfigTyp for conf_entry_id in device_entry.config_entries: if conf_entry_id not in hass.data[DOMAIN]: continue - bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id] + bridge: HueBridge = hass.data[DOMAIN][conf_entry_id] if bridge.api_version == 1: return await async_validate_trigger_config_v1(bridge, device_entry, config) return await async_validate_trigger_config_v2(bridge, device_entry, config) @@ -70,7 +71,7 @@ async def async_attach_trigger( for conf_entry_id in device_entry.config_entries: if conf_entry_id not in hass.data[DOMAIN]: continue - bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id] + bridge: HueBridge = hass.data[DOMAIN][conf_entry_id] if bridge.api_version == 1: return await async_attach_trigger_v1( bridge, device_entry, config, action, automation_info @@ -98,7 +99,7 @@ async def async_get_triggers(hass: "HomeAssistant", device_id: str): for conf_entry_id in device_entry.config_entries: if conf_entry_id not in hass.data[DOMAIN]: continue - bridge: "HueBridge" = hass.data[DOMAIN][conf_entry_id] + bridge: HueBridge = hass.data[DOMAIN][conf_entry_id] if bridge.api_version == 1: return await async_get_triggers_v1(bridge, device_entry) diff --git a/tests/components/amberelectric/test_sensor.py b/tests/components/amberelectric/test_sensor.py index deafcb70fb7..300b825cb7a 100644 --- a/tests/components/amberelectric/test_sensor.py +++ b/tests/components/amberelectric/test_sensor.py @@ -1,5 +1,5 @@ """Test the Amber Electric Sensors.""" -from typing import AsyncGenerator, List +from typing import AsyncGenerator from unittest.mock import Mock, patch from amberelectric.model.current_interval import CurrentInterval @@ -121,7 +121,7 @@ async def test_general_price_sensor(hass: HomeAssistant, setup_general: Mock) -> assert attributes.get("range_min") is None assert attributes.get("range_max") is None - with_range: List[CurrentInterval] = GENERAL_CHANNEL + with_range: list[CurrentInterval] = GENERAL_CHANNEL with_range[0].range = Range(7.8, 12.4) setup_general.get_current_price.return_value = with_range @@ -208,7 +208,7 @@ async def test_general_forecast_sensor( assert first_forecast.get("range_min") is None assert first_forecast.get("range_max") is None - with_range: List[CurrentInterval] = GENERAL_CHANNEL + with_range: list[CurrentInterval] = GENERAL_CHANNEL with_range[1].range = Range(7.8, 12.4) setup_general.get_current_price.return_value = with_range diff --git a/tests/components/greeneye_monitor/conftest.py b/tests/components/greeneye_monitor/conftest.py index a1ef0a9d89d..00b534bb06d 100644 --- a/tests/components/greeneye_monitor/conftest.py +++ b/tests/components/greeneye_monitor/conftest.py @@ -1,5 +1,5 @@ """Common fixtures for testing greeneye_monitor.""" -from typing import Any, Dict +from typing import Any from unittest.mock import AsyncMock, MagicMock, patch import pytest @@ -20,7 +20,7 @@ def assert_sensor_state( hass: HomeAssistant, entity_id: str, expected_state: str, - attributes: Dict[str, Any] = {}, + attributes: dict[str, Any] = {}, ) -> None: """Assert that the given entity has the expected state and at least the provided attributes.""" state = hass.states.get(entity_id) diff --git a/tests/components/nina/test_binary_sensor.py b/tests/components/nina/test_binary_sensor.py index 9b2bfd17cfb..ebdd7ed4105 100644 --- a/tests/components/nina/test_binary_sensor.py +++ b/tests/components/nina/test_binary_sensor.py @@ -1,6 +1,6 @@ """Test the Nina binary sensor.""" import json -from typing import Any, Dict +from typing import Any from unittest.mock import patch from homeassistant.components.binary_sensor import BinarySensorDeviceClass @@ -19,13 +19,13 @@ from homeassistant.helpers import entity_registry as er from tests.common import MockConfigEntry, load_fixture -ENTRY_DATA: Dict[str, Any] = { +ENTRY_DATA: dict[str, Any] = { "slots": 5, "corona_filter": True, "regions": {"083350000000": "Aach, Stadt"}, } -ENTRY_DATA_NO_CORONA: Dict[str, Any] = { +ENTRY_DATA_NO_CORONA: dict[str, Any] = { "slots": 5, "corona_filter": False, "regions": {"083350000000": "Aach, Stadt"}, @@ -35,7 +35,7 @@ ENTRY_DATA_NO_CORONA: Dict[str, Any] = { async def test_sensors(hass: HomeAssistant) -> None: """Test the creation and values of the NINA sensors.""" - dummy_response: Dict[str, Any] = json.loads( + dummy_response: dict[str, Any] = json.loads( load_fixture("sample_warnings.json", "nina") ) @@ -125,7 +125,7 @@ async def test_sensors(hass: HomeAssistant) -> None: async def test_sensors_without_corona_filter(hass: HomeAssistant) -> None: """Test the creation and values of the NINA sensors without the corona filter.""" - dummy_response: Dict[str, Any] = json.loads( + dummy_response: dict[str, Any] = json.loads( load_fixture("nina/sample_warnings.json") ) diff --git a/tests/components/nina/test_init.py b/tests/components/nina/test_init.py index 2f60c5d8e89..455d7465a87 100644 --- a/tests/components/nina/test_init.py +++ b/tests/components/nina/test_init.py @@ -1,6 +1,6 @@ """Test the Nina init file.""" import json -from typing import Any, Dict +from typing import Any from unittest.mock import patch from pynina import ApiError @@ -12,7 +12,7 @@ from homeassistant.setup import async_setup_component from tests.common import MockConfigEntry, load_fixture -ENTRY_DATA: Dict[str, Any] = { +ENTRY_DATA: dict[str, Any] = { "slots": 5, "corona_filter": True, "regions": {"083350000000": "Aach, Stadt"}, @@ -22,7 +22,7 @@ ENTRY_DATA: Dict[str, Any] = { async def init_integration(hass) -> MockConfigEntry: """Set up the NINA integration in Home Assistant.""" - dummy_response: Dict[str, Any] = json.loads( + dummy_response: dict[str, Any] = json.loads( load_fixture("sample_warnings.json", "nina") ) diff --git a/tests/components/picnic/test_sensor.py b/tests/components/picnic/test_sensor.py index 201ac563ff4..a4a52e50453 100644 --- a/tests/components/picnic/test_sensor.py +++ b/tests/components/picnic/test_sensor.py @@ -1,7 +1,6 @@ """The tests for the Picnic sensor platform.""" import copy from datetime import timedelta -from typing import Dict import unittest from unittest.mock import patch @@ -324,7 +323,7 @@ class TestPicnicSensor(unittest.IsolatedAsyncioTestCase): await self._setup_platform(use_default_responses=True) # Set non-datetime strings as eta - eta_dates: Dict[str, str] = { + eta_dates: dict[str, str] = { "start": "wrong-time", "end": "other-malformed-datetime", } diff --git a/tests/components/tplink/test_light.py b/tests/components/tplink/test_light.py index 1017ad38eae..c3b82045ef0 100644 --- a/tests/components/tplink/test_light.py +++ b/tests/components/tplink/test_light.py @@ -1,6 +1,6 @@ """Tests for light platform.""" +from __future__ import annotations -from typing import Optional from unittest.mock import PropertyMock import pytest @@ -48,7 +48,7 @@ async def test_light_unique_id(hass: HomeAssistant) -> None: @pytest.mark.parametrize("transition", [2.0, None]) -async def test_color_light(hass: HomeAssistant, transition: Optional[float]) -> None: +async def test_color_light(hass: HomeAssistant, transition: float | None) -> None: """Test a color light and that all transitions are correctly passed.""" already_migrated_config_entry = MockConfigEntry( domain=DOMAIN, data={}, unique_id=MAC_ADDRESS diff --git a/tests/components/upnp/conftest.py b/tests/components/upnp/conftest.py index 791df72ca81..f7a42551c34 100644 --- a/tests/components/upnp/conftest.py +++ b/tests/components/upnp/conftest.py @@ -1,5 +1,7 @@ """Configuration for SSDP tests.""" -from typing import Optional, Sequence +from __future__ import annotations + +from typing import Sequence from unittest.mock import AsyncMock, MagicMock, patch from urllib.parse import urlparse @@ -148,26 +150,26 @@ class MockIgdDevice: """Get the device type of this device.""" return self.profile_device.device_type - async def async_get_total_bytes_received(self) -> Optional[int]: + async def async_get_total_bytes_received(self) -> int | None: """Get total bytes received.""" self.traffic_times_polled += 1 return self.traffic_data[BYTES_RECEIVED] - async def async_get_total_bytes_sent(self) -> Optional[int]: + async def async_get_total_bytes_sent(self) -> int | None: """Get total bytes sent.""" return self.traffic_data[BYTES_SENT] - async def async_get_total_packets_received(self) -> Optional[int]: + async def async_get_total_packets_received(self) -> int | None: """Get total packets received.""" return self.traffic_data[PACKETS_RECEIVED] - async def async_get_total_packets_sent(self) -> Optional[int]: + async def async_get_total_packets_sent(self) -> int | None: """Get total packets sent.""" return self.traffic_data[PACKETS_SENT] async def async_get_external_ip_address( - self, services: Optional[Sequence[str]] = None - ) -> Optional[str]: + self, services: Sequence[str] | None = None + ) -> str | None: """ Get the external IP address. @@ -176,8 +178,8 @@ class MockIgdDevice: return self.status_data[ROUTER_IP] async def async_get_status_info( - self, services: Optional[Sequence[str]] = None - ) -> Optional[StatusInfo]: + self, services: Sequence[str] | None = None + ) -> StatusInfo | None: """ Get status info.