Skip to content

Commit d16df0c

Browse files
committed
add virtual attribute StateVal.entity_id
1 parent 9ba1f43 commit d16df0c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

custom_components/pyscript/state.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
_LOGGER = logging.getLogger(LOGGER_PATH + ".state")
1515

16-
STATE_VIRTUAL_ATTRS = {"last_changed", "last_updated"}
16+
STATE_VIRTUAL_ATTRS = {"entity_id", "last_changed", "last_updated"}
1717

1818

1919
class StateVal(str):
@@ -23,6 +23,7 @@ def __new__(cls, state):
2323
"""Create a new instance given a state variable."""
2424
new_var = super().__new__(cls, state.state)
2525
new_var.__dict__ = state.attributes.copy()
26+
new_var.entity_id = state.entity_id
2627
new_var.last_updated = state.last_updated
2728
new_var.last_changed = state.last_changed
2829
return new_var

docs/reference.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ Here's an example using ``input_number``, assuming it has been configured to cre
258258
input_number.test.set_value(value=13)
259259
input_number.test.set_value(13)
260260
261-
Two additional virtual attribute values are available when you use a variable directly as
261+
Three additional virtual attribute values are available when you use a variable directly as
262262
``DOMAIN.entity.attr`` or call ``state.get("DOMAIN.entity.attr")``:
263263

264+
- ``entity_id`` is the DOMAIN.entity as string
264265
- ``last_changed`` is the last UTC time the state value was changed (not the attributes)
265266
- ``last_updated`` is the last UTC time the state entity was updated
266267

0 commit comments

Comments
 (0)