Skip to content

Commit 2f0995f

Browse files
authored
Merge pull request #13 from basnijholt/states
add function entity_ids that returns all entities
2 parents f502fe8 + 581bd4e commit 2f0995f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ In cases where you need to compute the name of the state variable dynamically, o
265265
set the state attributes, you can use the built-in functions `state.get(name)` and
266266
`state.set(name, value, attr=None)`; see below.
267267

268+
The function `entity_ids(domain=None)` returns a list of all `entity_id`s of a domain. If domain
269+
is not specified, it returns all entities.
270+
268271
Also, service names (which are called as functions) take priority over state variable names,
269272
so if a component has a state variable name that collides with one of its services, you'll
270273
need to use `state.get(name)` to access that state variable.

custom_components/pyscript/handler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def init(hass):
3434
"task.unique": Handler.task_unique,
3535
"service.call": Handler.service_call,
3636
"service.has_service": Handler.service_has_service,
37+
"entity_ids": Handler.entity_ids,
3738
}
3839

3940
#
@@ -57,6 +58,9 @@ def init(hass):
5758
#
5859
Handler.loggers = {}
5960

61+
async def entity_ids(domain=None):
62+
return Handler.hass.states.async_entity_ids(domain)
63+
6064
async def async_sleep(duration):
6165
"""Implement task.sleep()."""
6266
await asyncio.sleep(float(duration))

0 commit comments

Comments
 (0)