mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Small tweaks of group tests (#68196)
This commit is contained in:
parent
f026245cb4
commit
b99934f62f
@ -8,6 +8,8 @@ from homeassistant.components.group import DOMAIN, async_setup_entry
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
from homeassistant.data_entry_flow import RESULT_TYPE_CREATE_ENTRY, RESULT_TYPE_FORM
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"group_type,group_state,member_state,member_attributes,extra_input,extra_options,extra_attrs",
|
"group_type,group_state,member_state,member_attributes,extra_input,extra_options,extra_attrs",
|
||||||
@ -122,46 +124,26 @@ async def test_options(
|
|||||||
for member in members2:
|
for member in members2:
|
||||||
hass.states.async_set(member, member_state, {})
|
hass.states.async_set(member, member_state, {})
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
switch_as_x_config_entry = MockConfigEntry(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
data={},
|
||||||
)
|
domain=DOMAIN,
|
||||||
assert result["type"] == RESULT_TYPE_FORM
|
options={
|
||||||
assert result["errors"] is None
|
|
||||||
|
|
||||||
assert get_suggested(result["data_schema"].schema, "group_type") is None
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"],
|
|
||||||
{"group_type": group_type},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert result["type"] == RESULT_TYPE_FORM
|
|
||||||
assert result["step_id"] == group_type
|
|
||||||
|
|
||||||
assert get_suggested(result["data_schema"].schema, "entities") is None
|
|
||||||
assert get_suggested(result["data_schema"].schema, "name") is None
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"],
|
|
||||||
{
|
|
||||||
"name": "Bed Room",
|
|
||||||
"entities": members1,
|
"entities": members1,
|
||||||
|
"group_type": group_type,
|
||||||
|
"name": "Bed Room",
|
||||||
|
**extra_options,
|
||||||
},
|
},
|
||||||
|
title="Bed Room",
|
||||||
)
|
)
|
||||||
|
switch_as_x_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_setup(switch_as_x_config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
|
||||||
state = hass.states.get(f"{group_type}.bed_room")
|
state = hass.states.get(f"{group_type}.bed_room")
|
||||||
assert state.attributes["entity_id"] == members1
|
assert state.attributes["entity_id"] == members1
|
||||||
|
|
||||||
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
assert config_entry.data == {}
|
|
||||||
assert config_entry.options == {
|
|
||||||
"group_type": group_type,
|
|
||||||
"entities": members1,
|
|
||||||
"name": "Bed Room",
|
|
||||||
**extra_options,
|
|
||||||
}
|
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
result = await hass.config_entries.options.async_init(config_entry.entry_id)
|
||||||
assert result["type"] == RESULT_TYPE_FORM
|
assert result["type"] == RESULT_TYPE_FORM
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
"""The tests for the Group components."""
|
"""The tests for the Group components."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -18,11 +21,12 @@ from homeassistant.const import (
|
|||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CoreState
|
from homeassistant.core import CoreState, HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.event import TRACK_STATE_CHANGE_CALLBACKS
|
from homeassistant.helpers.event import TRACK_STATE_CHANGE_CALLBACKS
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import assert_setup_component
|
from tests.common import MockConfigEntry, assert_setup_component
|
||||||
from tests.components.group import common
|
from tests.components.group import common
|
||||||
|
|
||||||
|
|
||||||
@ -1358,3 +1362,57 @@ async def test_plant_group(hass):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get("group.plants").state == "problem"
|
assert hass.states.get("group.plants").state == "problem"
|
||||||
assert hass.states.get("group.plant_with_binary_sensors").state == "on"
|
assert hass.states.get("group.plant_with_binary_sensors").state == "on"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"group_type,member_state,extra_options",
|
||||||
|
(
|
||||||
|
("binary_sensor", "on", {"all": False}),
|
||||||
|
("cover", "open", {}),
|
||||||
|
("fan", "on", {}),
|
||||||
|
("light", "on", {}),
|
||||||
|
("media_player", "on", {}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
async def test_setup_and_remove_config_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
group_type: str,
|
||||||
|
member_state: str,
|
||||||
|
extra_options: dict[str, Any],
|
||||||
|
) -> None:
|
||||||
|
"""Test removing a config entry."""
|
||||||
|
registry = er.async_get(hass)
|
||||||
|
|
||||||
|
members1 = [f"{group_type}.one", f"{group_type}.two"]
|
||||||
|
|
||||||
|
for member in members1:
|
||||||
|
hass.states.async_set(member, member_state, {})
|
||||||
|
|
||||||
|
# Setup the config entry
|
||||||
|
group_config_entry = MockConfigEntry(
|
||||||
|
data={},
|
||||||
|
domain=group.DOMAIN,
|
||||||
|
options={
|
||||||
|
"entities": members1,
|
||||||
|
"group_type": group_type,
|
||||||
|
"name": "Bed Room",
|
||||||
|
**extra_options,
|
||||||
|
},
|
||||||
|
title="Bed Room",
|
||||||
|
)
|
||||||
|
group_config_entry.add_to_hass(hass)
|
||||||
|
assert await hass.config_entries.async_setup(group_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Check the state and entity registry entry are present
|
||||||
|
state = hass.states.get(f"{group_type}.bed_room")
|
||||||
|
assert state.attributes["entity_id"] == members1
|
||||||
|
assert registry.async_get(f"{group_type}.bed_room") is not None
|
||||||
|
|
||||||
|
# Remove the config entry
|
||||||
|
assert await hass.config_entries.async_remove(group_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Check the state and entity registry entry are removed
|
||||||
|
assert hass.states.get(f"{group_type}.bed_room") is None
|
||||||
|
assert registry.async_get(f"{group_type}.bed_room") is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user