Simplify zwave_js code (#87235)

This commit is contained in:
Raman Gupta 2023-02-04 19:20:17 -05:00 committed by GitHub
parent 2f3b509513
commit e3b820d9db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 15 deletions

View File

@ -254,17 +254,15 @@ class DriverEvents:
self.dev_reg.async_remove_device(device.id) self.dev_reg.async_remove_device(device.id)
# run discovery on controller node # run discovery on controller node
c_node_id = controller.own_node_id if controller.own_node:
controller_node = controller.nodes.get(c_node_id) if c_node_id else None await self.controller_events.async_on_node_added(controller.own_node)
if controller_node:
await self.controller_events.async_on_node_added(controller_node)
# run discovery on all other ready nodes # run discovery on all other ready nodes
await asyncio.gather( await asyncio.gather(
*( *(
self.controller_events.async_on_node_added(node) self.controller_events.async_on_node_added(node)
for node in controller.nodes.values() for node in controller.nodes.values()
if controller_node is None or node != controller_node if node != controller.own_node
) )
) )
@ -396,13 +394,8 @@ class ControllerEvents:
via_device_id = None via_device_id = None
controller = driver.controller controller = driver.controller
# Get the controller node device ID if this node is not the controller # Get the controller node device ID if this node is not the controller
if ( if controller.own_node and controller.own_node != node:
controller.own_node_id is not None via_device_id = get_device_id(driver, controller.own_node)
and controller.own_node_id != node.node_id
):
via_device_id = get_device_id(
driver, controller.nodes[controller.own_node_id]
)
# Replace the device if it can be determined that this node is not the # Replace the device if it can be determined that this node is not the
# same product as it was previously. # same product as it was previously.

View File

@ -150,7 +150,7 @@ async def async_get_actions(
node = async_get_node_from_device_id(hass, device_id) node = async_get_node_from_device_id(hass, device_id)
if node.client.driver and node.client.driver.controller.own_node_id == node.node_id: if node.client.driver and node.client.driver.controller.own_node == node:
return actions return actions
base_action = { base_action = {

View File

@ -134,7 +134,7 @@ async def async_get_conditions(
} }
node = async_get_node_from_device_id(hass, device_id) node = async_get_node_from_device_id(hass, device_id)
if node.client.driver and node.client.driver.controller.own_node_id == node.node_id: if node.client.driver and node.client.driver.controller.own_node == node:
return conditions return conditions
# Any value's value condition # Any value's value condition

View File

@ -258,7 +258,7 @@ async def async_get_triggers(
dev_reg = device_registry.async_get(hass) dev_reg = device_registry.async_get(hass)
node = async_get_node_from_device_id(hass, device_id, dev_reg) node = async_get_node_from_device_id(hass, device_id, dev_reg)
if node.client.driver and node.client.driver.controller.own_node_id == node.node_id: if node.client.driver and node.client.driver.controller.own_node == node:
return triggers return triggers
# We can add a node status trigger if the node status sensor is enabled # We can add a node status trigger if the node status sensor is enabled