예제 #1
0
    def _resolve_entity(self, entity_id) -> None:
        """Resolve an entity."""
        # Extra: Find automations and scripts that reference this entity.

        for entity in scene.scenes_with_entity(self.hass, entity_id):
            self._add_or_resolve("entity", entity)

        for entity in group.groups_with_entity(self.hass, entity_id):
            self._add_or_resolve("entity", entity)

        for entity in automation.automations_with_entity(self.hass, entity_id):
            self._add_or_resolve("entity", entity)

        for entity in script.scripts_with_entity(self.hass, entity_id):
            self._add_or_resolve("entity", entity)

        # Find devices
        entity_entry = self._entity_reg.async_get(entity_id)
        if entity_entry is not None:
            if entity_entry.device_id:
                self._add_or_resolve("device", entity_entry.device_id)

            if entity_entry.config_entry_id is not None:
                self._add_or_resolve("config_entry", entity_entry.config_entry_id)

        domain = split_entity_id(entity_id)[0]

        if domain in self.EXIST_AS_ENTITY:
            self._add_or_resolve(domain, entity_id)
예제 #2
0
async def test_scenes_with_entity(hass):
    """Test finding scenes with a specific entity."""
    assert await async_setup_component(
        hass,
        "scene",
        {
            "scene": [
                {
                    "name": "scene_1",
                    "entities": {
                        "light.kitchen": "on"
                    }
                },
                {
                    "name": "scene_2",
                    "entities": {
                        "light.living_room": "off"
                    }
                },
                {
                    "name": "scene_3",
                    "entities": {
                        "light.kitchen": "on",
                        "light.living_room": "off"
                    },
                },
            ]
        },
    )
    await hass.async_block_till_done()

    assert sorted(ha_scene.scenes_with_entity(hass, "light.kitchen")) == [
        "scene.scene_1",
        "scene.scene_3",
    ]