appdaemon
appdaemon copied to clipboard
Feature request: get entity from name
It would be nice to have a utility method to get an entity from a name "a.b.c". I find myself doing this a lot in my apps where I want to keep a handle to the entity object.
def get_entity(self, name):
# Take 'foo.bar.baz' and return self.entities.foo.bar.baz.
# This makes it easy to convert a string to an arbitrary entity.
elems = name.split(".")
obj = self.entities
for e in elems:
obj = getattr(obj, e)
return obj
if you do things a lot you can create a general function for it. it seems to me that you use entities as object and you got self.entities in appdaemon entities are no objects and there is no self.entities, so then its hard to create something like that for general use.
Sorry, I'm confused. The page below seems to say to use self.entities as the correct way to access an entity (which is an object) https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html There are already similar utility methods on the hass plugin base class like verifying that an entity is real. Rather than checking if an entity exists (which is a hass base class method), it could just return the entity it none of it doesn't exist.
yeah sorry, sometimes i hang a bit in the past. i still use get_state ;)
i would probably use
device, entity = self.split_entity(name)
self.entities[device][entity]