mirror of
https://github.com/home-assistant/core.git
synced 2025-11-11 20:10:12 +00:00
Use mysensors config entry async_on_unload (#139978)
* Use config entry on unload in mysensors * Test mysensors config entry load and unload * Fix docstring
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from mysensors import BaseSyncGateway
|
||||
from mysensors.sensor import Sensor
|
||||
|
||||
from homeassistant.components.mysensors import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -14,6 +19,50 @@ from tests.common import MockConfigEntry
|
||||
from tests.typing import WebSocketGenerator
|
||||
|
||||
|
||||
async def test_load_unload(
|
||||
hass: HomeAssistant,
|
||||
door_sensor: Sensor,
|
||||
transport: MagicMock,
|
||||
integration: MockConfigEntry,
|
||||
receive_message: Callable[[str], None],
|
||||
) -> None:
|
||||
"""Test loading and unloading the MySensors config entry."""
|
||||
config_entry = integration
|
||||
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
entity_id = "binary_sensor.door_sensor_1_1"
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
receive_message("1;1;1;0;16;1\n")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state != STATE_UNAVAILABLE
|
||||
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
|
||||
assert transport.return_value.disconnect.call_count == 1
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
receive_message("1;1;1;0;16;1\n")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_remove_config_entry_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
|
||||
Reference in New Issue
Block a user