From 7a2eeb68b23bdc436a526018de28395266971b4e Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 2 Sep 2020 22:58:43 +0200 Subject: [PATCH 1/2] add function entity_ids that returns all entities --- custom_components/pyscript/handler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/custom_components/pyscript/handler.py b/custom_components/pyscript/handler.py index 8a846d6..a5be45b 100644 --- a/custom_components/pyscript/handler.py +++ b/custom_components/pyscript/handler.py @@ -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, } # @@ -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)) From 581bd4e382b0d7c7d4f81eb2d4456a20b8b5102d Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 2 Sep 2020 23:22:12 +0200 Subject: [PATCH 2/2] add paragraph to the README about entity_ids function --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 21afe8e..36857e6 100644 --- a/README.md +++ b/README.md @@ -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.