mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add remove entity in group.set service (#79401)
* Group set remove entities * simplify * Add test * Fix test
This commit is contained in:
parent
74a76c6fe7
commit
68dd2802a1
@ -58,6 +58,7 @@ ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
|||||||
CONF_ALL = "all"
|
CONF_ALL = "all"
|
||||||
|
|
||||||
ATTR_ADD_ENTITIES = "add_entities"
|
ATTR_ADD_ENTITIES = "add_entities"
|
||||||
|
ATTR_REMOVE_ENTITIES = "remove_entities"
|
||||||
ATTR_AUTO = "auto"
|
ATTR_AUTO = "auto"
|
||||||
ATTR_ENTITIES = "entities"
|
ATTR_ENTITIES = "entities"
|
||||||
ATTR_OBJECT_ID = "object_id"
|
ATTR_OBJECT_ID = "object_id"
|
||||||
@ -367,6 +368,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
entity_ids = set(group.tracking) | set(delta)
|
entity_ids = set(group.tracking) | set(delta)
|
||||||
await group.async_update_tracked_entity_ids(entity_ids)
|
await group.async_update_tracked_entity_ids(entity_ids)
|
||||||
|
|
||||||
|
if ATTR_REMOVE_ENTITIES in service.data:
|
||||||
|
delta = service.data[ATTR_REMOVE_ENTITIES]
|
||||||
|
entity_ids = set(group.tracking) - set(delta)
|
||||||
|
await group.async_update_tracked_entity_ids(entity_ids)
|
||||||
|
|
||||||
if ATTR_ENTITIES in service.data:
|
if ATTR_ENTITIES in service.data:
|
||||||
entity_ids = service.data[ATTR_ENTITIES]
|
entity_ids = service.data[ATTR_ENTITIES]
|
||||||
await group.async_update_tracked_entity_ids(entity_ids)
|
await group.async_update_tracked_entity_ids(entity_ids)
|
||||||
@ -405,6 +411,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
vol.Optional(ATTR_ALL): cv.boolean,
|
vol.Optional(ATTR_ALL): cv.boolean,
|
||||||
vol.Exclusive(ATTR_ENTITIES, "entities"): cv.entity_ids,
|
vol.Exclusive(ATTR_ENTITIES, "entities"): cv.entity_ids,
|
||||||
vol.Exclusive(ATTR_ADD_ENTITIES, "entities"): cv.entity_ids,
|
vol.Exclusive(ATTR_ADD_ENTITIES, "entities"): cv.entity_ids,
|
||||||
|
vol.Exclusive(ATTR_REMOVE_ENTITIES, "entities"): cv.entity_ids,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
@ -38,6 +38,12 @@ set:
|
|||||||
example: domain.entity_id1, domain.entity_id2
|
example: domain.entity_id1, domain.entity_id2
|
||||||
selector:
|
selector:
|
||||||
object:
|
object:
|
||||||
|
remove_entities:
|
||||||
|
name: Remove Entities
|
||||||
|
description: List of members that will be removed from group listening.
|
||||||
|
example: domain.entity_id1, domain.entity_id2
|
||||||
|
selector:
|
||||||
|
object:
|
||||||
all:
|
all:
|
||||||
name: All
|
name: All
|
||||||
description: Enable this option if the group should only turn on when all entities are on.
|
description: Enable this option if the group should only turn on when all entities are on.
|
||||||
|
@ -549,6 +549,62 @@ async def test_service_group_services(hass):
|
|||||||
assert hass.services.has_service("group", group.SERVICE_REMOVE)
|
assert hass.services.has_service("group", group.SERVICE_REMOVE)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_service_group_services_add_remove_entities(hass: HomeAssistant) -> None:
|
||||||
|
"""Check if we can add and remove entities from group."""
|
||||||
|
|
||||||
|
hass.states.async_set("person.one", "Work")
|
||||||
|
hass.states.async_set("person.two", "Work")
|
||||||
|
hass.states.async_set("person.three", "home")
|
||||||
|
|
||||||
|
assert await async_setup_component(hass, "person", {})
|
||||||
|
with assert_setup_component(0, "group"):
|
||||||
|
await async_setup_component(hass, "group", {"group": {}})
|
||||||
|
|
||||||
|
assert hass.services.has_service("group", group.SERVICE_SET)
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
group.DOMAIN,
|
||||||
|
group.SERVICE_SET,
|
||||||
|
{
|
||||||
|
"object_id": "new_group",
|
||||||
|
"name": "New Group",
|
||||||
|
"entities": ["person.one", "person.two"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
group_state = hass.states.get("group.new_group")
|
||||||
|
assert group_state.state == "not_home"
|
||||||
|
assert group_state.attributes["friendly_name"] == "New Group"
|
||||||
|
assert list(group_state.attributes["entity_id"]) == ["person.one", "person.two"]
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
group.DOMAIN,
|
||||||
|
group.SERVICE_SET,
|
||||||
|
{
|
||||||
|
"object_id": "new_group",
|
||||||
|
"add_entities": "person.three",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
group_state = hass.states.get("group.new_group")
|
||||||
|
assert group_state.state == "home"
|
||||||
|
assert "person.three" in list(group_state.attributes["entity_id"])
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
group.DOMAIN,
|
||||||
|
group.SERVICE_SET,
|
||||||
|
{
|
||||||
|
"object_id": "new_group",
|
||||||
|
"remove_entities": "person.one",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
group_state = hass.states.get("group.new_group")
|
||||||
|
assert group_state.state == "home"
|
||||||
|
assert "person.one" not in list(group_state.attributes["entity_id"])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=invalid-name
|
# pylint: disable=invalid-name
|
||||||
async def test_service_group_set_group_remove_group(hass):
|
async def test_service_group_set_group_remove_group(hass):
|
||||||
"""Check if service are available."""
|
"""Check if service are available."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user