Return specific group state if there is one (#115866)

* Return specific group state if there is one

* Refactor

* Additional test cases

* Refactor

* Break out if more than one on state

* tweaks

* Remove log, add comment

* add comment

* Apply suggestions from code review

Co-authored-by: J. Nick Koston <nick@koston.org>

* Refactor and improve comments

* Refactor to class method

* More filtering

* Apply suggestions from code review

* Only active if not excluded

* Do not use a set

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
Jan Bouwhuis 2024-04-24 15:12:29 +02:00 committed by GitHub
parent 1f4585cc9e
commit 350ca48d4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 109 additions and 24 deletions

View file

@ -9,7 +9,7 @@ from unittest.mock import patch
import pytest
from homeassistant.components import group
from homeassistant.components import group, vacuum
from homeassistant.const import (
ATTR_ASSUMED_STATE,
ATTR_FRIENDLY_NAME,
@ -659,6 +659,24 @@ async def test_is_on(hass: HomeAssistant) -> None:
(STATE_ON, True),
(STATE_OFF, False),
),
(
("vacuum", "vacuum"),
# Cleaning is the only on state
(vacuum.STATE_DOCKED, vacuum.STATE_CLEANING),
# Returning is the only on state
(vacuum.STATE_RETURNING, vacuum.STATE_PAUSED),
(vacuum.STATE_CLEANING, True),
(vacuum.STATE_RETURNING, True),
),
(
("vacuum", "vacuum"),
# Multiple on states, so group state will be STATE_ON
(vacuum.STATE_RETURNING, vacuum.STATE_CLEANING),
# Only off states, so group state will be off
(vacuum.STATE_PAUSED, vacuum.STATE_IDLE),
(STATE_ON, True),
(STATE_OFF, False),
),
],
)
async def test_is_on_and_state_mixed_domains(
@ -1220,7 +1238,7 @@ async def test_group_climate_all_cool(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert hass.states.get("group.group_zero").state == STATE_ON
assert hass.states.get("group.group_zero").state == "cool"
async def test_group_climate_all_off(hass: HomeAssistant) -> None:
@ -1334,7 +1352,7 @@ async def test_group_vacuum_on(hass: HomeAssistant) -> None:
)
await hass.async_block_till_done()
assert hass.states.get("group.group_zero").state == STATE_ON
assert hass.states.get("group.group_zero").state == "cleaning"
async def test_device_tracker_not_home(hass: HomeAssistant) -> None: