Skip to content

Commit 716ffd7

Browse files
committed
directly access hass.data[DATA_RESTORE_STATE] to avoid deprecated api
see #473. This is a hack; should re-implement using RestoreEntity.
1 parent 3225f41 commit 716ffd7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

custom_components/pyscript/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from homeassistant.exceptions import HomeAssistantError
2626
import homeassistant.helpers.config_validation as cv
2727
from homeassistant.helpers.event import Event as HAEvent
28-
from homeassistant.helpers.restore_state import RestoreStateData
28+
from homeassistant.helpers.restore_state import DATA_RESTORE_STATE
2929
from homeassistant.loader import bind_hass
3030

3131
from .const import (
@@ -80,7 +80,8 @@ async def async_setup(hass: HomeAssistant, config: Config) -> bool:
8080

8181
async def restore_state(hass: HomeAssistant) -> None:
8282
"""Restores the persisted pyscript state."""
83-
restore_data = await RestoreStateData.async_get_instance(hass)
83+
# this is a hack accessing hass internals; should re-implement using RestoreEntity
84+
restore_data = hass.data[DATA_RESTORE_STATE]
8485
for entity_id, value in restore_data.last_states.items():
8586
if entity_id.startswith("pyscript."):
8687
last_state = value.state

custom_components/pyscript/state.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55

66
from homeassistant.core import Context
7-
from homeassistant.helpers.restore_state import RestoreStateData
7+
from homeassistant.helpers.restore_state import DATA_RESTORE_STATE
88
from homeassistant.helpers.service import async_get_all_descriptions
99

1010
from .const import LOGGER_PATH
@@ -217,7 +217,8 @@ def setattr(cls, var_attr_name, value):
217217
async def register_persist(cls, var_name):
218218
"""Register pyscript state variable to be persisted with RestoreState."""
219219
if var_name.startswith("pyscript.") and var_name not in cls.persisted_vars:
220-
restore_data = await RestoreStateData.async_get_instance(cls.hass)
220+
# this is a hack accessing hass internals; should re-implement using RestoreEntity
221+
restore_data = cls.hass.data[DATA_RESTORE_STATE]
221222
this_entity = PyscriptEntity()
222223
this_entity.entity_id = var_name
223224
cls.persisted_vars[var_name] = this_entity

0 commit comments

Comments
 (0)