hass-core/tests/components/smartthings/test_scene.py
Paulus Schoutsen 9e07910ab0
Mark entities as unavailable when they are removed but are still registered (#45528)
* Mark entities as unavailable when they are removed but are still registered

* Add sync_entity_lifecycle to collection helper

* Remove debug print

* Lint

* Fix tests

* Fix tests

* Update zha

* Update zone

* Fix tests

* Update hyperion

* Update rfxtrx

* Fix tests

* Pass force_remove=True from integrations

Co-authored-by: Erik <erik@montnemery.com>
2021-02-08 10:45:46 +01:00

49 lines
1.7 KiB
Python

"""
Test for the SmartThings scene platform.
The only mocking required is of the underlying SmartThings API object so
real HTTP calls are not initiated during testing.
"""
from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_UNAVAILABLE
from .conftest import setup_platform
async def test_entity_and_device_attributes(hass, scene):
"""Test the attributes of the entity are correct."""
# Arrange
entity_registry = await hass.helpers.entity_registry.async_get_registry()
# Act
await setup_platform(hass, SCENE_DOMAIN, scenes=[scene])
# Assert
entry = entity_registry.async_get("scene.test_scene")
assert entry
assert entry.unique_id == scene.scene_id
async def test_scene_activate(hass, scene):
"""Test the scene is activated."""
await setup_platform(hass, SCENE_DOMAIN, scenes=[scene])
await hass.services.async_call(
SCENE_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "scene.test_scene"},
blocking=True,
)
state = hass.states.get("scene.test_scene")
assert state.attributes["icon"] == scene.icon
assert state.attributes["color"] == scene.color
assert state.attributes["location_id"] == scene.location_id
# pylint: disable=protected-access
assert scene.execute.call_count == 1 # type: ignore
async def test_unload_config_entry(hass, scene):
"""Test the scene is removed when the config entry is unloaded."""
# Arrange
config_entry = await setup_platform(hass, SCENE_DOMAIN, scenes=[scene])
# Act
await hass.config_entries.async_forward_entry_unload(config_entry, SCENE_DOMAIN)
# Assert
assert hass.states.get("scene.test_scene").state == STATE_UNAVAILABLE