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:
Erik Montnemery 2022-03-10 17:23:16 +01:00 committed by GitHub
parent 14b5847da8
commit 3d212b868e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 20 deletions

View 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

View file

@ -1,4 +1,4 @@
"""The tests for the Light Switch platform."""
"""Tests for the Switch as X Light platform."""
import pytest
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"
@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",))
async def test_config_entry_uuid(hass: HomeAssistant, target_domain):
"""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()
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