mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Address review comments on switch_as_x tests (#67951)
* Address review comments on switch_as_x tests * Correct test * Move test instead of duplicating it
This commit is contained in:
parent
14b5847da8
commit
3d212b868e
27
tests/components/switch_as_x/test_init.py
Normal file
27
tests/components/switch_as_x/test_init.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"""Tests for the Switch as X."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from homeassistant.components.switch_as_x import DOMAIN
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("target_domain", ("light",))
|
||||||
|
async def test_config_entry_unregistered_uuid(hass: HomeAssistant, target_domain):
|
||||||
|
"""Test light switch setup from config entry with unknown entity registry id."""
|
||||||
|
fake_uuid = "a266a680b608c32770e6c45bfe6b8411"
|
||||||
|
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
data={},
|
||||||
|
domain=DOMAIN,
|
||||||
|
options={"entity_id": fake_uuid, "target_domain": target_domain},
|
||||||
|
title="ABC",
|
||||||
|
)
|
||||||
|
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert len(hass.states.async_all()) == 0
|
@ -1,4 +1,4 @@
|
|||||||
"""The tests for the Light Switch platform."""
|
"""Tests for the Switch as X Light platform."""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
@ -106,6 +106,34 @@ async def test_switch_service_calls(hass):
|
|||||||
assert hass.states.get("light.decorative_lights").state == "on"
|
assert hass.states.get("light.decorative_lights").state == "on"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("target_domain", ("light",))
|
||||||
|
async def test_config_entry_entity_id(hass: HomeAssistant, target_domain):
|
||||||
|
"""Test light switch setup from config entry with entity id."""
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
data={},
|
||||||
|
domain=DOMAIN,
|
||||||
|
options={"entity_id": "switch.abc", "target_domain": target_domain},
|
||||||
|
title="ABC",
|
||||||
|
)
|
||||||
|
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert DOMAIN in hass.config.components
|
||||||
|
|
||||||
|
state = hass.states.get(f"{target_domain}.abc")
|
||||||
|
assert state.state == "unavailable"
|
||||||
|
# Name copied from config entry title
|
||||||
|
assert state.name == "ABC"
|
||||||
|
|
||||||
|
# Check the light is added to the entity registry
|
||||||
|
registry = er.async_get(hass)
|
||||||
|
entity_entry = registry.async_get(f"{target_domain}.abc")
|
||||||
|
assert entity_entry.unique_id == config_entry.entry_id
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("target_domain", ("light",))
|
@pytest.mark.parametrize("target_domain", ("light",))
|
||||||
async def test_config_entry_uuid(hass: HomeAssistant, target_domain):
|
async def test_config_entry_uuid(hass: HomeAssistant, target_domain):
|
||||||
"""Test light switch setup from config entry with entity registry id."""
|
"""Test light switch setup from config entry with entity registry id."""
|
||||||
@ -125,22 +153,3 @@ async def test_config_entry_uuid(hass: HomeAssistant, target_domain):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(f"{target_domain}.abc")
|
assert hass.states.get(f"{target_domain}.abc")
|
||||||
|
|
||||||
|
|
||||||
async def test_config_entry_unregistered_uuid(hass: HomeAssistant):
|
|
||||||
"""Test light switch setup from config entry with unknown entity registry id."""
|
|
||||||
fake_uuid = "a266a680b608c32770e6c45bfe6b8411"
|
|
||||||
|
|
||||||
config_entry = MockConfigEntry(
|
|
||||||
data={},
|
|
||||||
domain=DOMAIN,
|
|
||||||
options={"entity_id": fake_uuid},
|
|
||||||
title="ABC",
|
|
||||||
)
|
|
||||||
|
|
||||||
config_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
assert not await hass.config_entries.async_setup(config_entry.entry_id)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert len(hass.states.async_all()) == 0
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user