mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Drop restore_state backwards compatibility (#130411)
This commit is contained in:
parent
b24931c775
commit
b57b22f6e3
@ -17,7 +17,6 @@ from homeassistant.util.json import json_loads
|
|||||||
from . import start
|
from . import start
|
||||||
from .entity import Entity
|
from .entity import Entity
|
||||||
from .event import async_track_time_interval
|
from .event import async_track_time_interval
|
||||||
from .frame import report
|
|
||||||
from .json import JSONEncoder
|
from .json import JSONEncoder
|
||||||
from .singleton import singleton
|
from .singleton import singleton
|
||||||
from .storage import Store
|
from .storage import Store
|
||||||
@ -116,21 +115,6 @@ class RestoreStateData:
|
|||||||
"""Dump states now."""
|
"""Dump states now."""
|
||||||
await async_get(hass).async_dump_states()
|
await async_get(hass).async_dump_states()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
async def async_get_instance(cls, hass: HomeAssistant) -> RestoreStateData:
|
|
||||||
"""Return the instance of this class."""
|
|
||||||
# Nothing should actually be calling this anymore, but we'll keep it
|
|
||||||
# around for a while to avoid breaking custom components.
|
|
||||||
#
|
|
||||||
# In fact they should not be accessing this at all.
|
|
||||||
report(
|
|
||||||
"restore_state.RestoreStateData.async_get_instance is deprecated, "
|
|
||||||
"and not intended to be called by custom components; Please"
|
|
||||||
"refactor your code to use RestoreEntity instead;"
|
|
||||||
" restore_state.async_get(hass) can be used in the meantime",
|
|
||||||
)
|
|
||||||
return async_get(hass)
|
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant) -> None:
|
def __init__(self, hass: HomeAssistant) -> None:
|
||||||
"""Initialize the restore state data class."""
|
"""Initialize the restore state data class."""
|
||||||
self.hass: HomeAssistant = hass
|
self.hass: HomeAssistant = hass
|
||||||
|
@ -6,8 +6,6 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import CoreState, HomeAssistant, State
|
from homeassistant.core import CoreState, HomeAssistant, State
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
@ -94,20 +92,6 @@ async def test_caching_data(hass: HomeAssistant) -> None:
|
|||||||
assert mock_write_data.called
|
assert mock_write_data.called
|
||||||
|
|
||||||
|
|
||||||
async def test_async_get_instance_backwards_compatibility(hass: HomeAssistant) -> None:
|
|
||||||
"""Test async_get_instance backwards compatibility."""
|
|
||||||
await async_load(hass)
|
|
||||||
data = async_get(hass)
|
|
||||||
# When called from core it should raise
|
|
||||||
with pytest.raises(RuntimeError):
|
|
||||||
await RestoreStateData.async_get_instance(hass)
|
|
||||||
|
|
||||||
# When called from a component it should not raise
|
|
||||||
# but it should report
|
|
||||||
with patch("homeassistant.helpers.restore_state.report"):
|
|
||||||
assert data is await RestoreStateData.async_get_instance(hass)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_periodic_write(hass: HomeAssistant) -> None:
|
async def test_periodic_write(hass: HomeAssistant) -> None:
|
||||||
"""Test that we write periodiclly but not after stop."""
|
"""Test that we write periodiclly but not after stop."""
|
||||||
data = async_get(hass)
|
data = async_get(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user