mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Create zwave_js ping button at the right time (#66848)
* Create zwave_js ping button at the right time * fix tests
This commit is contained in:
parent
fd24d9b1ad
commit
4ff1f5c788
@ -261,12 +261,6 @@ async def async_setup_entry( # noqa: C901
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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
|
|
||||||
)
|
|
||||||
|
|
||||||
# add listeners to handle new values that get added later
|
# add listeners to handle new values that get added later
|
||||||
for event in ("value added", "value updated", "metadata updated"):
|
for event in ("value added", "value updated", "metadata updated"):
|
||||||
entry.async_on_unload(
|
entry.async_on_unload(
|
||||||
@ -295,13 +289,18 @@ async def async_setup_entry( # noqa: C901
|
|||||||
|
|
||||||
async def async_on_node_added(node: ZwaveNode) -> None:
|
async def async_on_node_added(node: ZwaveNode) -> None:
|
||||||
"""Handle node added event."""
|
"""Handle node added event."""
|
||||||
await async_setup_platform(SENSOR_DOMAIN)
|
|
||||||
|
|
||||||
# Create a node status sensor for each device
|
# Create a node status sensor for each device
|
||||||
|
await async_setup_platform(SENSOR_DOMAIN)
|
||||||
async_dispatcher_send(
|
async_dispatcher_send(
|
||||||
hass, f"{DOMAIN}_{entry.entry_id}_add_node_status_sensor", node
|
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,
|
# we only want to run discovery when the node has reached ready state,
|
||||||
# otherwise we'll have all kinds of missing info issues.
|
# otherwise we'll have all kinds of missing info issues.
|
||||||
if node.ready:
|
if node.ready:
|
||||||
|
@ -211,8 +211,8 @@ async def test_on_node_added_not_ready(
|
|||||||
client.driver.receive_event(event)
|
client.driver.receive_event(event)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# the only entity is the node status sensor
|
# the only entities are the node status sensor and ping button
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 2
|
||||||
|
|
||||||
device = dev_reg.async_get_device(identifiers={(DOMAIN, device_id)})
|
device = dev_reg.async_get_device(identifiers={(DOMAIN, device_id)})
|
||||||
assert device
|
assert device
|
||||||
@ -254,8 +254,8 @@ async def test_existing_node_not_ready(hass, zp3111_not_ready, client, integrati
|
|||||||
assert not device.model
|
assert not device.model
|
||||||
assert not device.sw_version
|
assert not device.sw_version
|
||||||
|
|
||||||
# the only entity is the node status sensor
|
# the only entities are the node status sensor and ping button
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 2
|
||||||
|
|
||||||
device = dev_reg.async_get_device(identifiers={(DOMAIN, device_id)})
|
device = dev_reg.async_get_device(identifiers={(DOMAIN, device_id)})
|
||||||
assert device
|
assert device
|
||||||
|
Loading…
x
Reference in New Issue
Block a user