Пример #1
0
    def referenced_devices(self):
        """Return a set of referenced devices."""
        if self._referenced_devices is not None:
            return self._referenced_devices

        referenced: set[str] = set()

        for step in self.sequence:
            action = cv.determine_script_action(step)

            if action == cv.SCRIPT_ACTION_CALL_SERVICE:
                for data in (
                        step.get(CONF_TARGET),
                        step.get(service.CONF_SERVICE_DATA),
                        step.get(service.CONF_SERVICE_DATA_TEMPLATE),
                ):
                    _referenced_extract_ids(data, ATTR_DEVICE_ID, referenced)

            elif action == cv.SCRIPT_ACTION_CHECK_CONDITION:
                referenced |= condition.async_extract_devices(step)

            elif action == cv.SCRIPT_ACTION_DEVICE_AUTOMATION:
                referenced.add(step[CONF_DEVICE_ID])

        self._referenced_devices = referenced
        return referenced
Пример #2
0
async def test_extract_devices():
    """Test extracting devices."""
    condition.async_extract_devices({
        "condition":
        "and",
        "conditions": [
            {
                "condition": "device",
                "device_id": "abcd",
                "domain": "light"
            },
            {
                "condition": "device",
                "device_id": "qwer",
                "domain": "switch"
            },
        ],
    }) == {"abcd", "qwer"}
Пример #3
0
async def test_extract_devices():
    """Test extracting devices."""
    assert (condition.async_extract_devices({
        "condition":
        "and",
        "conditions": [
            {
                "condition": "device",
                "device_id": "abcd",
                "domain": "light"
            },
            {
                "condition": "device",
                "device_id": "qwer",
                "domain": "switch"
            },
            {
                "condition": "state",
                "entity_id": "sensor.not_a_device",
                "state": "100",
            },
            {
                "condition":
                "not",
                "conditions": [
                    {
                        "condition": "device",
                        "device_id": "abcd_not",
                        "domain": "light",
                    },
                    {
                        "condition": "device",
                        "device_id": "qwer_not",
                        "domain": "switch",
                    },
                ],
            },
            {
                "condition":
                "or",
                "conditions": [
                    {
                        "condition": "device",
                        "device_id": "abcd_or",
                        "domain": "light",
                    },
                    {
                        "condition": "device",
                        "device_id": "qwer_or",
                        "domain": "switch",
                    },
                ],
            },
            Template("{{ is_state('light.example', 'on') }}"),
        ],
    }) == {"abcd", "qwer", "abcd_not", "qwer_not", "abcd_or", "qwer_or"})
Пример #4
0
    def referenced_devices(self):
        """Return a set of referenced devices."""
        if self._referenced_devices is not None:
            return self._referenced_devices

        referenced = self.action_script.referenced_devices

        if self._cond_func is not None:
            for conf in self._cond_func.config:
                referenced |= condition.async_extract_devices(conf)

        for conf in self._trigger_config:
            referenced |= set(_trigger_extract_devices(conf))

        self._referenced_devices = referenced
        return referenced
Пример #5
0
    def referenced_devices(self):
        """Return a set of referenced devices."""
        if self._referenced_devices is not None:
            return self._referenced_devices

        referenced = set()

        for step in self.sequence:
            action = cv.determine_script_action(step)

            if action == cv.SCRIPT_ACTION_CHECK_CONDITION:
                referenced |= condition.async_extract_devices(step)

            elif action == cv.SCRIPT_ACTION_DEVICE_AUTOMATION:
                referenced.add(step[CONF_DEVICE_ID])

        self._referenced_devices = referenced
        return referenced