From e03b3e231071cba376f8b53d9de5c58f7fa9289d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 9 Oct 2020 01:37:27 -0500 Subject: [PATCH] Restore group support to plant entities (#41519) --- homeassistant/components/plant/group.py | 15 ++++++ tests/components/group/test_init.py | 63 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 homeassistant/components/plant/group.py diff --git a/homeassistant/components/plant/group.py b/homeassistant/components/plant/group.py new file mode 100644 index 00000000000..5d6edfa2b9a --- /dev/null +++ b/homeassistant/components/plant/group.py @@ -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) diff --git a/tests/components/group/test_init.py b/tests/components/group/test_init.py index ec3a8ccf242..0004719b28d 100644 --- a/tests/components/group/test_init.py +++ b/tests/components/group/test_init.py @@ -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"