mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Restore group support to plant entities (#41519)
This commit is contained in:
parent
68e1c70b14
commit
e03b3e2310
15
homeassistant/components/plant/group.py
Normal file
15
homeassistant/components/plant/group.py
Normal file
@ -0,0 +1,15 @@
|
||||
"""Describe group states."""
|
||||
|
||||
|
||||
from homeassistant.components.group import GroupIntegrationRegistry
|
||||
from homeassistant.const import STATE_OK, STATE_PROBLEM
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
|
||||
@callback
|
||||
def async_describe_on_off_states(
|
||||
hass: HomeAssistantType, registry: GroupIntegrationRegistry
|
||||
) -> None:
|
||||
"""Describe group on off states."""
|
||||
registry.on_off_states({STATE_PROBLEM}, STATE_OK)
|
@ -1219,3 +1219,66 @@ async def test_group_that_references_two_types_of_groups(hass):
|
||||
assert hass.states.get("group.covers").state == "closed"
|
||||
assert hass.states.get("group.device_trackers").state == "home"
|
||||
assert hass.states.get("group.grouped_group").state == "on"
|
||||
|
||||
|
||||
async def test_plant_group(hass):
|
||||
"""Test plant states can be grouped."""
|
||||
|
||||
entity_ids = [
|
||||
"plant.upstairs",
|
||||
"plant.downstairs",
|
||||
]
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"plant",
|
||||
{
|
||||
"plant": {
|
||||
"plantname": {
|
||||
"sensors": {
|
||||
"moisture": "sensor.mqtt_plant_moisture",
|
||||
"battery": "sensor.mqtt_plant_battery",
|
||||
"temperature": "sensor.mqtt_plant_temperature",
|
||||
"conductivity": "sensor.mqtt_plant_conductivity",
|
||||
"brightness": "sensor.mqtt_plant_brightness",
|
||||
},
|
||||
"min_moisture": 20,
|
||||
"max_moisture": 60,
|
||||
"min_battery": 17,
|
||||
"min_conductivity": 500,
|
||||
"min_temperature": 15,
|
||||
"min_brightness": 500,
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"group",
|
||||
{
|
||||
"group": {
|
||||
"plants": {"entities": entity_ids},
|
||||
"plant_with_binary_sensors": {
|
||||
"entities": [*entity_ids, "binary_sensor.planter"]
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.states.async_set("binary_sensor.planter", "off")
|
||||
for entity_id in entity_ids:
|
||||
hass.states.async_set(entity_id, "ok")
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("group.plants").state == "ok"
|
||||
assert hass.states.get("group.plant_with_binary_sensors").state == "off"
|
||||
|
||||
hass.states.async_set("binary_sensor.planter", "on")
|
||||
for entity_id in entity_ids:
|
||||
hass.states.async_set(entity_id, "problem")
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get("group.plants").state == "problem"
|
||||
assert hass.states.get("group.plant_with_binary_sensors").state == "on"
|
||||
|
Loading…
x
Reference in New Issue
Block a user