diff --git a/custom_components/pyscript/eval.py b/custom_components/pyscript/eval.py index c12f4f4..5d93d60 100644 --- a/custom_components/pyscript/eval.py +++ b/custom_components/pyscript/eval.py @@ -1310,8 +1310,8 @@ async def ast_with(self, arg, async_attr=""): } ) for ctx in ctx_list: + value = await self.call_func(ctx["enter"], enter_attr, ctx["manager"]) if ctx["target"]: - value = await self.call_func(ctx["enter"], enter_attr, ctx["manager"]) await self.recurse_assign(ctx["target"], value) for arg1 in arg.body: val = await self.aeval(arg1) diff --git a/custom_components/pyscript/state.py b/custom_components/pyscript/state.py index e01848a..c057936 100644 --- a/custom_components/pyscript/state.py +++ b/custom_components/pyscript/state.py @@ -13,7 +13,7 @@ _LOGGER = logging.getLogger(LOGGER_PATH + ".state") -STATE_VIRTUAL_ATTRS = {"last_changed", "last_updated"} +STATE_VIRTUAL_ATTRS = {"entity_id", "last_changed", "last_updated"} class StateVal(str): @@ -23,6 +23,7 @@ def __new__(cls, state): """Create a new instance given a state variable.""" new_var = super().__new__(cls, state.state) new_var.__dict__ = state.attributes.copy() + new_var.entity_id = state.entity_id new_var.last_updated = state.last_updated new_var.last_changed = state.last_changed return new_var diff --git a/docs/reference.rst b/docs/reference.rst index 9742682..05d32c8 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -258,9 +258,10 @@ Here's an example using ``input_number``, assuming it has been configured to cre input_number.test.set_value(value=13) input_number.test.set_value(13) -Two additional virtual attribute values are available when you use a variable directly as +Three additional virtual attribute values are available when you use a variable directly as ``DOMAIN.entity.attr`` or call ``state.get("DOMAIN.entity.attr")``: +- ``entity_id`` is the DOMAIN.entity as string - ``last_changed`` is the last UTC time the state value was changed (not the attributes) - ``last_updated`` is the last UTC time the state entity was updated