diff --git a/README.md b/README.md index a73adf4..f55ac23 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pytest-homeassistant-custom-component -![HA core version](https://img.shields.io/static/v1?label=HA+core+version&message=2024.9.3&labelColor=blue) +![HA core version](https://img.shields.io/static/v1?label=HA+core+version&message=2024.10.0b0&labelColor=blue) [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/MatthewFlamm/pytest-homeassistant-custom-component) diff --git a/ha_version b/ha_version index 5a02c33..cd03ec5 100644 --- a/ha_version +++ b/ha_version @@ -1 +1 @@ -2024.9.3 \ No newline at end of file +2024.10.0b0 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt index 8643999..0eef85e 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,22 +1,22 @@ # This file is originally from homeassistant/core and modified by pytest-homeassistant-custom-component. -astroid==3.2.4 -mypy-dev==1.12.0a2 -pre-commit==3.7.1 -pylint==3.2.6 -types-aiofiles==23.2.0.20240623 +astroid==3.3.4 +mypy-dev==1.12.0a3 +pre-commit==3.8.0 +pylint==3.3.1 +types-aiofiles==24.1.0.20240626 types-atomicwrites==1.4.5.1 types-croniter==2.0.0.20240423 -types-beautifulsoup4==4.12.0.20240511 -types-caldav==1.3.0.20240331 +types-beautifulsoup4==4.12.0.20240907 +types-caldav==1.3.0.20240824 types-chardet==0.1.5 types-decorator==5.1.8.20240310 types-paho-mqtt==1.6.0.20240321 -types-pillow==10.2.0.20240520 -types-protobuf==4.24.0.20240106 -types-psutil==6.0.0.20240621 -types-python-dateutil==2.9.0.20240316 +types-pillow==10.2.0.20240822 +types-protobuf==4.25.0.20240417 +types-psutil==6.0.0.20240901 +types-python-dateutil==2.9.0.20240906 types-python-slugify==8.0.2.20240310 -types-pytz==2024.1.0.20240417 -types-PyYAML==6.0.12.20240311 +types-pytz==2024.2.0.20240913 +types-PyYAML==6.0.12.20240917 types-requests==2.31.0.3 types-xmltodict==0.13.0.3 diff --git a/requirements_test.txt b/requirements_test.txt index 8dc16fb..ffaa2cd 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -8,14 +8,14 @@ -c homeassistant/package_constraints.txt -r requirements_test_pre_commit.txt -coverage==7.6.0 +coverage==7.6.1 freezegun==1.5.1 mock-open==1.4.0 pydantic==1.10.17 pylint-per-file-ignores==1.3.2 -pipdeptree==2.23.1 -pip-licenses==4.5.1 -pytest-asyncio==0.23.8 +pipdeptree==2.23.4 +pip-licenses==5.0.0 +pytest-asyncio==0.24.0 pytest-aiohttp==1.0.5 pytest-cov==5.0.0 pytest-freezer==0.4.8 @@ -26,16 +26,15 @@ pytest-timeout==2.3.1 pytest-unordered==0.6.1 pytest-picked==0.5.0 pytest-xdist==3.6.1 -pytest==8.3.1 +pytest==8.3.3 requests-mock==1.12.1 respx==0.21.1 -syrupy==4.6.1 -tqdm==4.66.4 -uv==0.2.27 -homeassistant==2024.9.3 +syrupy==4.7.1 +tqdm==4.66.5 +homeassistant==2024.10.0b0 SQLAlchemy==2.0.31 paho-mqtt==1.6.1 -numpy==1.26.0 +numpy==1.26.4 diff --git a/src/pytest_homeassistant_custom_component/common.py b/src/pytest_homeassistant_custom_component/common.py index bccc856..8ebf67f 100644 --- a/src/pytest_homeassistant_custom_component/common.py +++ b/src/pytest_homeassistant_custom_component/common.py @@ -424,7 +424,7 @@ def async_fire_mqtt_message( from paho.mqtt.client import MQTTMessage # pylint: disable-next=import-outside-toplevel - from homeassistant.components.mqtt.models import MqttData + from homeassistant.components.mqtt import MqttData if isinstance(payload, str): payload = payload.encode("utf-8") @@ -996,6 +996,7 @@ def __init__( *, data=None, disabled_by=None, + discovery_keys=None, domain="test", entry_id=None, minor_version=1, @@ -1010,9 +1011,11 @@ def __init__( version=1, ) -> None: """Initialize a mock config entry.""" + discovery_keys = discovery_keys or {} kwargs = { "data": data or {}, "disabled_by": disabled_by, + "discovery_keys": discovery_keys, "domain": domain, "entry_id": entry_id or ulid_util.ulid_now(), "minor_version": minor_version, diff --git a/src/pytest_homeassistant_custom_component/const.py b/src/pytest_homeassistant_custom_component/const.py index bd3075a..8c94508 100644 --- a/src/pytest_homeassistant_custom_component/const.py +++ b/src/pytest_homeassistant_custom_component/const.py @@ -5,7 +5,7 @@ """ from typing import TYPE_CHECKING, Final MAJOR_VERSION: Final = 2024 -MINOR_VERSION: Final = 9 -PATCH_VERSION: Final = "3" +MINOR_VERSION: Final = 10 +PATCH_VERSION: Final = "0b0" __short_version__: Final = f"{MAJOR_VERSION}.{MINOR_VERSION}" __version__: Final = f"{__short_version__}.{PATCH_VERSION}" diff --git a/src/pytest_homeassistant_custom_component/plugins.py b/src/pytest_homeassistant_custom_component/plugins.py index bc53f02..314df54 100644 --- a/src/pytest_homeassistant_custom_component/plugins.py +++ b/src/pytest_homeassistant_custom_component/plugins.py @@ -55,11 +55,15 @@ from homeassistant.auth.models import Credentials from homeassistant.auth.providers import homeassistant from homeassistant.components.device_tracker.legacy import Device + +# pylint: disable-next=hass-component-root-import from homeassistant.components.websocket_api.auth import ( TYPE_AUTH, TYPE_AUTH_OK, TYPE_AUTH_REQUIRED, ) + +# pylint: disable-next=hass-component-root-import from homeassistant.components.websocket_api.http import URL from homeassistant.config import YAML_CONFIG_FILE from homeassistant.config_entries import ConfigEntries, ConfigEntry, ConfigEntryState @@ -418,7 +422,7 @@ def reset_hass_threading_local_object() -> Generator[None]: ha._hass.__dict__.clear() -@pytest.fixture(scope="session", autouse=True) +@pytest.fixture(autouse=True, scope="session") def bcrypt_cost() -> Generator[None]: """Run with reduced rounds during tests, to speed up uses.""" gensalt_orig = bcrypt.gensalt @@ -1297,11 +1301,21 @@ def enable_nightly_purge() -> bool: @pytest.fixture -def enable_migrate_context_ids() -> bool: +def enable_migrate_event_context_ids() -> bool: + """Fixture to control enabling of recorder's context id migration. + + To enable context id migration, tests can be marked with: + @pytest.mark.parametrize("enable_migrate_event_context_ids", [True]) + """ + return False + + +@pytest.fixture +def enable_migrate_state_context_ids() -> bool: """Fixture to control enabling of recorder's context id migration. To enable context id migration, tests can be marked with: - @pytest.mark.parametrize("enable_migrate_context_ids", [True]) + @pytest.mark.parametrize("enable_migrate_state_context_ids", [True]) """ return False @@ -1469,7 +1483,8 @@ async def async_test_recorder( enable_statistics: bool, enable_missing_statistics: bool, enable_schema_validation: bool, - enable_migrate_context_ids: bool, + enable_migrate_event_context_ids: bool, + enable_migrate_state_context_ids: bool, enable_migrate_event_type_ids: bool, enable_migrate_entity_ids: bool, enable_migrate_event_ids: bool, @@ -1531,12 +1546,12 @@ def debug_session_scope( ) migrate_states_context_ids = ( migration.StatesContextIDMigration.migrate_data - if enable_migrate_context_ids + if enable_migrate_state_context_ids else None ) migrate_events_context_ids = ( migration.EventsContextIDMigration.migrate_data - if enable_migrate_context_ids + if enable_migrate_event_context_ids else None ) migrate_event_type_ids = ( @@ -1704,7 +1719,7 @@ async def mock_enable_bluetooth( await hass.async_block_till_done() -@pytest.fixture(scope="session") +@pytest.fixture(autouse=True, scope="session") def mock_bluetooth_adapters() -> Generator[None]: """Fixture to mock bluetooth adapters.""" with ( diff --git a/src/pytest_homeassistant_custom_component/test_util/aiohttp.py b/src/pytest_homeassistant_custom_component/test_util/aiohttp.py index eb3e6c4..5e63c33 100644 --- a/src/pytest_homeassistant_custom_component/test_util/aiohttp.py +++ b/src/pytest_homeassistant_custom_component/test_util/aiohttp.py @@ -9,6 +9,7 @@ from contextlib import contextmanager from http import HTTPStatus import re +from types import TracebackType from typing import Any from unittest import mock from urllib.parse import parse_qs @@ -170,7 +171,7 @@ class AiohttpClientMockResponse: def __init__( self, method, - url, + url: URL, status=HTTPStatus.OK, response=None, json=None, @@ -301,6 +302,18 @@ def response(self): raise ClientConnectionError("Connection closed") return self._response + async def __aenter__(self): + """Enter the context manager.""" + return self + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc_val: BaseException | None, + exc_tb: TracebackType | None, + ) -> None: + """Exit the context manager.""" + @contextmanager def mock_aiohttp_client() -> Iterator[AiohttpClientMocker]: diff --git a/version b/version index fac5c7b..821203b 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.13.164 +0.13.165