mirror of
https://github.com/home-assistant/core.git
synced 2025-11-06 17:40:11 +00:00
Add mysensors remove device support (#67128)
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
"""Test function in __init__.py."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
from collections.abc import Callable
|
||||
from typing import Any, Awaitable
|
||||
from unittest.mock import patch
|
||||
|
||||
from aiohttp import ClientWebSocketResponse
|
||||
from mysensors import BaseSyncGateway
|
||||
from mysensors.sensor import Sensor
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.mysensors import (
|
||||
@@ -27,9 +31,12 @@ from homeassistant.components.mysensors.const import (
|
||||
CONF_TOPIC_OUT_PREFIX,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config, expected_calls, expected_to_succeed, expected_config_entry_data",
|
||||
@@ -347,3 +354,51 @@ async def test_import(
|
||||
persistence_path = config_entry_data.pop(CONF_PERSISTENCE_FILE)
|
||||
assert persistence_path == expected_persistence_path
|
||||
assert config_entry_data == expected_config_entry_data[idx]
|
||||
|
||||
|
||||
async def test_remove_config_entry_device(
|
||||
hass: HomeAssistant,
|
||||
gps_sensor: Sensor,
|
||||
integration: tuple[MockConfigEntry, Callable[[str], None]],
|
||||
gateway: BaseSyncGateway,
|
||||
hass_ws_client: Callable[[HomeAssistant], Awaitable[ClientWebSocketResponse]],
|
||||
) -> None:
|
||||
"""Test that a device can be removed ok."""
|
||||
entity_id = "sensor.gps_sensor_1_1"
|
||||
node_id = 1
|
||||
config_entry, _ = integration
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device_registry = dr.async_get(hass)
|
||||
device_entry = device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, f"{config_entry.entry_id}-{node_id}")}
|
||||
)
|
||||
entity_registry = er.async_get(hass)
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert gateway.sensors
|
||||
assert gateway.sensors[node_id]
|
||||
assert device_entry
|
||||
assert state
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "config/device_registry/remove_config_entry",
|
||||
"config_entry_id": config_entry.entry_id,
|
||||
"device_id": device_entry.id,
|
||||
}
|
||||
)
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert node_id not in gateway.sensors
|
||||
assert gateway.tasks.persistence.need_save is True
|
||||
assert not device_registry.async_get_device(
|
||||
identifiers={(DOMAIN, f"{config_entry.entry_id}-1")}
|
||||
)
|
||||
assert not entity_registry.async_get(entity_id)
|
||||
assert not hass.states.get(entity_id)
|
||||
|
||||
Reference in New Issue
Block a user