Skip to content

Commit 8fac6e8

Browse files
committed
more proper fix
1 parent af363ca commit 8fac6e8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from homeassistant.helpers.restore_state import RestoreEntity
2+
3+
4+
class PyscriptEntity(RestoreEntity):
5+
def set_state(self, state):
6+
self._attr_state = state
7+
8+
def set_attributes(self, attributes):
9+
self._attr_extra_state_attributes = attributes

custom_components/pyscript/state.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
import logging
55

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

1010
from .const import LOGGER_PATH
11+
from .entity import PyscriptEntity
1112
from .function import Function
1213

1314
_LOGGER = logging.getLogger(LOGGER_PATH + ".state")
@@ -199,8 +200,8 @@ def set(cls, var_name, value=None, new_attributes=None, **kwargs):
199200
cls.notify_var_last[var_name] = StateVal(cls.hass.states.get(var_name))
200201

201202
if var_name in cls.persisted_vars:
202-
cls.persisted_vars[var_name]._attr_state = value
203-
cls.persisted_vars[var_name]._attr_extra_state_attributes = new_attributes
203+
cls.persisted_vars[var_name].set_state(value)
204+
cls.persisted_vars[var_name].set_attributes(new_attributes)
204205

205206
@classmethod
206207
def setattr(cls, var_attr_name, value):
@@ -217,7 +218,7 @@ async def register_persist(cls, var_name):
217218
"""Register pyscript state variable to be persisted with RestoreState."""
218219
if var_name.startswith("pyscript.") and var_name not in cls.persisted_vars:
219220
restore_data = await RestoreStateData.async_get_instance(cls.hass)
220-
this_entity = RestoreEntity()
221+
this_entity = PyscriptEntity()
221222
this_entity.entity_id = var_name
222223
restore_data.async_restore_entity_added(this_entity)
223224
cls.persisted_vars[var_name] = this_entity

0 commit comments

Comments
 (0)