Notify users when zwave device gets reset (#101362)

* Notify users when zwave device gets reset

* review comments
This commit is contained in:
Raman Gupta 2023-10-04 04:18:48 -04:00 committed by GitHub
parent cd175f679f
commit d3c5b9777b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 14 deletions

View file

@ -1644,3 +1644,61 @@ async def test_server_logging(hass: HomeAssistant, client) -> None:
assert len(client.async_send_command.call_args_list) == 0
assert not client.enable_server_logging.called
assert not client.disable_server_logging.called
async def test_factory_reset_node(
hass: HomeAssistant, client, multisensor_6, multisensor_6_state, integration
) -> None:
"""Test when a node is removed because it was reset."""
# One config entry scenario
remove_event = Event(
type="node removed",
data={
"source": "controller",
"event": "node removed",
"reason": 5,
"node": deepcopy(multisensor_6_state),
},
)
dev_id = get_device_id(client.driver, multisensor_6)
msg_id = f"{DOMAIN}.node_reset_and_removed.{dev_id[1]}"
client.driver.controller.receive_event(remove_event)
notifications = async_get_persistent_notifications(hass)
assert len(notifications) == 1
assert list(notifications)[0] == msg_id
assert notifications[msg_id]["message"].startswith("`Multisensor 6`")
assert "with the home ID" not in notifications[msg_id]["message"]
async_dismiss(hass, msg_id)
# Add mock config entry to simulate having multiple entries
new_entry = MockConfigEntry(domain=DOMAIN)
new_entry.add_to_hass(hass)
# Re-add the node then remove it again
client.driver.controller.nodes[multisensor_6_state["nodeId"]] = Node(
client, deepcopy(multisensor_6_state)
)
remove_event.data["node"] = deepcopy(multisensor_6_state)
client.driver.controller.receive_event(remove_event)
# Test case where config entry title and home ID don't match
notifications = async_get_persistent_notifications(hass)
assert len(notifications) == 1
assert list(notifications)[0] == msg_id
assert (
"network `Mock Title`, with the home ID `3245146787`."
in notifications[msg_id]["message"]
)
async_dismiss(hass, msg_id)
# Test case where config entry title and home ID do match
hass.config_entries.async_update_entry(integration, title="3245146787")
client.driver.controller.nodes[multisensor_6_state["nodeId"]] = Node(
client, deepcopy(multisensor_6_state)
)
remove_event.data["node"] = deepcopy(multisensor_6_state)
client.driver.controller.receive_event(remove_event)
notifications = async_get_persistent_notifications(hass)
assert len(notifications) == 1
assert list(notifications)[0] == msg_id
assert "network with the home ID `3245146787`" in notifications[msg_id]["message"]