slashback100 / presence_simulation

Home Assistant Presence Simulation
423 stars 22 forks source link

Not working at all if one entity is Unavailable #57

Closed bob-tm closed 2 years ago

bob-tm commented 2 years ago

custom_components\presence_simulation__init__.py I just commented line 115 raise Exception("Entity is not known by HA, see log for more details")

If one entity is Unavailable - then loop breaks by raise Exception, so presence simulation not working. Please check all code for this situation.

for entity in entities:
            #to make it asyncable, not sure it is needed
            await asyncio.sleep(0)
            if hass.states.get(entity) is None:
                _LOGGER.error("Error when trying to identify entity %s, it seems it doesn't exist", entity)
                # raise Exception("Entity is not known by HA, see log for more details")
            else:
                if 'entity_id' in  hass.states.get(entity).attributes:
                    #get the list of the associated entities
                    #the entity_id attribute will be filled for groups or light groups
                    group_entities = hass.states.get(entity).attributes["entity_id"]
                    #and call recursively, in case a group contains a group
                    group_entities_expanded = await async_expand_entities(group_entities)
                    _LOGGER.debug("State %s", group_entities_expanded)
                    entities_new += group_entities_expanded
                else:
                    _LOGGER.debug("Entity %s has no attribute entity_id, it is not a group nor a light group", entity)
                    entities_new.append(entity)
        return entities_new
slashback100 commented 2 years ago

This should only occur of you reference an entity that doesn't exist, not if the entity was just Unavailable

slashback100 commented 2 years ago

Could you please verify that the entity identifier you use in the presence simulation does exist in : Open your Home Assistant instance and show your state developer tools. ?

bob-tm commented 2 years ago

It's exists, but unavailable. Wled entity. Anyway, if it doesn't exists - it will break any presence simulation. If groups were created long time ago - it is very difficulty to identify what is broken, because HA UI do not show any problems with presence simulation group.

slashback100 commented 2 years ago

Ok I understand. I can keep the ERROR log, remove the Exception, and just check that there is at least a valid entity before launching the simulation