Skip to content

add function entity_ids that returns all entities #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ In cases where you need to compute the name of the state variable dynamically, o
set the state attributes, you can use the built-in functions `state.get(name)` and
`state.set(name, value, attr=None)`; see below.

The function `entity_ids(domain=None)` returns a list of all `entity_id`s of a domain. If domain
is not specified, it returns all entities.

Also, service names (which are called as functions) take priority over state variable names,
so if a component has a state variable name that collides with one of its services, you'll
need to use `state.get(name)` to access that state variable.
Expand Down
4 changes: 4 additions & 0 deletions custom_components/pyscript/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def init(hass):
"task.unique": Handler.task_unique,
"service.call": Handler.service_call,
"service.has_service": Handler.service_has_service,
"entity_ids": Handler.entity_ids,
}

#
Expand All @@ -57,6 +58,9 @@ def init(hass):
#
Handler.loggers = {}

async def entity_ids(domain=None):
return Handler.hass.states.async_entity_ids(domain)

async def async_sleep(duration):
"""Implement task.sleep()."""
await asyncio.sleep(float(duration))
Expand Down