From acc4b001cd3cb2fa5eb6d14fd537f15e0fe625ab Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 29 Apr 2023 14:02:34 +0200 Subject: [PATCH] Fix history YAML deprecation (#92238) --- homeassistant/components/history/__init__.py | 21 ++++++++++---------- tests/components/history/test_init.py | 15 ++++++++++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/history/__init__.py b/homeassistant/components/history/__init__.py index 71200b93f3f..f5b97a7fb13 100644 --- a/homeassistant/components/history/__init__.py +++ b/homeassistant/components/history/__init__.py @@ -12,6 +12,7 @@ from homeassistant.components import frontend from homeassistant.components.http import HomeAssistantView from homeassistant.components.recorder import get_instance, history from homeassistant.components.recorder.util import session_scope +from homeassistant.const import CONF_EXCLUDE, CONF_INCLUDE from homeassistant.core import HomeAssistant, valid_entity_id import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entityfilter import INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA @@ -27,16 +28,16 @@ CONF_ORDER = "use_include_order" _ONE_DAY = timedelta(days=1) CONFIG_SCHEMA = vol.Schema( - vol.All( - cv.deprecated(DOMAIN), - { - DOMAIN: vol.All( - INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend( - {vol.Optional(CONF_ORDER, default=False): cv.boolean} - ), - ) - }, - ), + { + DOMAIN: vol.All( + cv.deprecated(CONF_INCLUDE), + cv.deprecated(CONF_EXCLUDE), + cv.deprecated(CONF_ORDER), + INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA.extend( + {vol.Optional(CONF_ORDER, default=False): cv.boolean} + ), + ) + }, extra=vol.ALLOW_EXTRA, ) diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index 46b5773bfaa..30c84c56f00 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -406,7 +406,10 @@ async def test_fetch_period_api( async def test_fetch_period_api_with_use_include_order( - recorder_mock: Recorder, hass: HomeAssistant, hass_client: ClientSessionGenerator + recorder_mock: Recorder, + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + caplog: pytest.LogCaptureFixture, ) -> None: """Test the fetch period view for history with include order.""" await async_setup_component( @@ -418,6 +421,8 @@ async def test_fetch_period_api_with_use_include_order( ) assert response.status == HTTPStatus.OK + assert "The 'use_include_order' option is deprecated" in caplog.text + async def test_fetch_period_api_with_minimal_response( recorder_mock: Recorder, hass: HomeAssistant, hass_client: ClientSessionGenerator @@ -472,7 +477,10 @@ async def test_fetch_period_api_with_no_timestamp( async def test_fetch_period_api_with_include_order( - recorder_mock: Recorder, hass: HomeAssistant, hass_client: ClientSessionGenerator + recorder_mock: Recorder, + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + caplog: pytest.LogCaptureFixture, ) -> None: """Test the fetch period view for history.""" await async_setup_component( @@ -492,6 +500,9 @@ async def test_fetch_period_api_with_include_order( ) assert response.status == HTTPStatus.OK + assert "The 'use_include_order' option is deprecated" in caplog.text + assert "The 'include' option is deprecated" in caplog.text + async def test_entity_ids_limit_via_api( recorder_mock: Recorder, hass: HomeAssistant, hass_client: ClientSessionGenerator