示例#1
0
    async def async_on_node_added(node: ZwaveNode) -> None:
        """Handle node added event."""
        # No need for a ping button or node status sensor for controller nodes
        if not node.is_controller_node:
            # Create a node status sensor for each device
            await async_setup_platform(SENSOR_DOMAIN)
            async_dispatcher_send(
                hass, f"{DOMAIN}_{entry.entry_id}_add_node_status_sensor",
                node)

            # Create a ping button for each device
            await async_setup_platform(BUTTON_DOMAIN)
            async_dispatcher_send(
                hass, f"{DOMAIN}_{entry.entry_id}_add_ping_button_entity",
                node)

        # we only want to run discovery when the node has reached ready state,
        # otherwise we'll have all kinds of missing info issues.
        if node.ready:
            await async_on_node_ready(node)
            return
        # if node is not yet ready, register one-time callback for ready state
        LOGGER.debug("Node added: %s - waiting for it to become ready",
                     node.node_id)
        node.once(
            "ready",
            lambda event: hass.async_create_task(
                async_on_node_ready(event["node"])),
        )
        # we do submit the node to device registry so user has
        # some visual feedback that something is (in the process of) being added
        register_node_in_dev_reg(hass, entry, dev_reg, client, node,
                                 remove_device)
示例#2
0
    async def async_on_node_added(node: ZwaveNode) -> None:
        """Handle node added event."""
        platform_setup_tasks = entry_hass_data[DATA_PLATFORM_SETUP]

        # We need to set up the sensor platform if it hasn't already been setup in
        # order to create the node status sensor
        if SENSOR_DOMAIN not in platform_setup_tasks:
            platform_setup_tasks[SENSOR_DOMAIN] = hass.async_create_task(
                hass.config_entries.async_forward_entry_setup(entry, SENSOR_DOMAIN)
            )

        # This guard ensures that concurrent runs of this function all await the
        # platform setup task
        if not platform_setup_tasks[SENSOR_DOMAIN].done():
            await platform_setup_tasks[SENSOR_DOMAIN]

        # Create a node status sensor for each device
        async_dispatcher_send(
            hass, f"{DOMAIN}_{entry.entry_id}_add_node_status_sensor", node
        )

        # we only want to run discovery when the node has reached ready state,
        # otherwise we'll have all kinds of missing info issues.
        if node.ready:
            await async_on_node_ready(node)
            return
        # if node is not yet ready, register one-time callback for ready state
        LOGGER.debug("Node added: %s - waiting for it to become ready", node.node_id)
        node.once(
            "ready",
            lambda event: hass.async_create_task(async_on_node_ready(event["node"])),
        )
        # we do submit the node to device registry so user has
        # some visual feedback that something is (in the process of) being added
        register_node_in_dev_reg(hass, entry, dev_reg, client, node, remove_device)
示例#3
0
 def async_on_node_added(node: ZwaveNode) -> None:
     """Handle node added event."""
     # we only want to run discovery when the node has reached ready state,
     # otherwise we'll have all kinds of missing info issues.
     if node.ready:
         async_on_node_ready(node)
         return
     # if node is not yet ready, register one-time callback for ready state
     LOGGER.debug("Node added: %s - waiting for it to become ready.", node.node_id)
     node.once(
         "ready",
         lambda event: async_on_node_ready(event["node"]),
     )
     # we do submit the node to device registry so user has
     # some visual feedback that something is (in the process of) being added
     register_node_in_dev_reg(hass, entry, dev_reg, client, node)