Remove deprecated history WS API (#82136)

This commit is contained in:
Erik Montnemery 2022-11-16 12:54:03 +01:00 committed by GitHub
parent 7999f109d1
commit 1582d88957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 120 deletions

View file

@ -10,10 +10,6 @@ import pytest
from homeassistant.components import history
from homeassistant.components.recorder.history import get_significant_states
from homeassistant.components.recorder.models import process_timestamp
from homeassistant.components.recorder.websocket_api import (
ws_handle_get_statistics_during_period,
ws_handle_list_statistic_ids,
)
from homeassistant.const import CONF_DOMAINS, CONF_ENTITIES, CONF_EXCLUDE, CONF_INCLUDE
import homeassistant.core as ha
from homeassistant.helpers.json import JSONEncoder
@ -844,76 +840,6 @@ async def test_entity_ids_limit_via_api_with_skip_initial_state(
assert response_json[1][0]["entity_id"] == "light.cow"
async def test_statistics_during_period(recorder_mock, hass, hass_ws_client, caplog):
"""Test history/statistics_during_period forwards to recorder."""
now = dt_util.utcnow()
await async_setup_component(hass, "history", {})
client = await hass_ws_client()
# Test the WS API works and issues a warning
await client.send_json(
{
"id": 1,
"type": "history/statistics_during_period",
"start_time": now.isoformat(),
"end_time": now.isoformat(),
"statistic_ids": ["sensor.test"],
"period": "hour",
}
)
response = await client.receive_json()
assert response["success"]
assert response["result"] == {}
assert (
"WS API 'history/statistics_during_period' is deprecated and will be removed in "
"Home Assistant Core 2022.12. Use 'recorder/statistics_during_period' instead"
) in caplog.text
# Test the WS API forwards to recorder
with patch(
"homeassistant.components.history.recorder_ws.ws_handle_get_statistics_during_period",
wraps=ws_handle_get_statistics_during_period,
) as ws_mock:
await client.send_json(
{
"id": 2,
"type": "history/statistics_during_period",
"start_time": now.isoformat(),
"end_time": now.isoformat(),
"statistic_ids": ["sensor.test"],
"period": "hour",
}
)
await client.receive_json()
ws_mock.assert_awaited_once()
async def test_list_statistic_ids(recorder_mock, hass, hass_ws_client, caplog):
"""Test history/list_statistic_ids forwards to recorder."""
await async_setup_component(hass, "history", {})
client = await hass_ws_client()
# Test the WS API works and issues a warning
await client.send_json({"id": 1, "type": "history/list_statistic_ids"})
response = await client.receive_json()
assert response["success"]
assert response["result"] == []
assert (
"WS API 'history/list_statistic_ids' is deprecated and will be removed in "
"Home Assistant Core 2022.12. Use 'recorder/list_statistic_ids' instead"
) in caplog.text
with patch(
"homeassistant.components.history.recorder_ws.ws_handle_list_statistic_ids",
wraps=ws_handle_list_statistic_ids,
) as ws_mock:
await client.send_json({"id": 2, "type": "history/list_statistic_ids"})
await client.receive_json()
ws_mock.assert_called_once()
async def test_history_during_period(recorder_mock, hass, hass_ws_client):
"""Test history_during_period."""
now = dt_util.utcnow()