Accessing entity attributes in AppDaemon

I am trying to write an AppDaemon app that processes Google Calendar events (from the google calendar component). I have a callback fired on state change, and I need to access an attribute of the entity that called it (the calendar). The attribute is “message” (which holds the title of the GCal event). The following code works, but seems to be incredibly kludgy. Is there a cleaner way to get this?

def Callback_On_State_Change(self, entity, attribute, old, new, kwargs):
	self.log("message: {} ".format(self.get_state(entity, attribute = "all")["attributes"].get("message")))

Do I really have to do a get_state and then chain through all those dictionaries like that? Surely there’s a cleaner way?

self.get_state(entity, attribute="message")

should be enough.

3 Likes