Skip to content

Commit

Permalink
Modify behavior of lock groups (home-assistant#74055)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Jun 28, 2022
1 parent 8328f9b commit 824de2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/group/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def async_update_group_state(self) -> None:
if (state := self.hass.states.get(entity_id)) is not None
]

valid_state = all(
valid_state = any(
state not in (STATE_UNKNOWN, STATE_UNAVAILABLE) for state in states
)

Expand Down
28 changes: 9 additions & 19 deletions tests/components/group/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,10 @@ async def test_state_reporting(hass):
await hass.async_block_till_done()
assert hass.states.get("lock.lock_group").state == STATE_UNAVAILABLE

# At least one member unknown or unavailable -> group unknown
# The group state is unknown if all group members are unknown or unavailable.
for state_1 in (
STATE_JAMMED,
STATE_LOCKED,
STATE_LOCKING,
STATE_UNKNOWN,
STATE_UNLOCKED,
STATE_UNLOCKING,
):
hass.states.async_set("lock.test1", state_1)
hass.states.async_set("lock.test2", STATE_UNAVAILABLE)
await hass.async_block_till_done()
assert hass.states.get("lock.lock_group").state == STATE_UNKNOWN

for state_1 in (
STATE_JAMMED,
STATE_LOCKED,
STATE_LOCKING,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
STATE_UNLOCKED,
STATE_UNLOCKING,
):
hass.states.async_set("lock.test1", state_1)
hass.states.async_set("lock.test2", STATE_UNKNOWN)
Expand All @@ -123,6 +105,8 @@ async def test_state_reporting(hass):
STATE_JAMMED,
STATE_LOCKED,
STATE_LOCKING,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
STATE_UNLOCKED,
STATE_UNLOCKING,
):
Expand All @@ -135,6 +119,8 @@ async def test_state_reporting(hass):
for state_1 in (
STATE_LOCKED,
STATE_LOCKING,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
STATE_UNLOCKED,
STATE_UNLOCKING,
):
Expand All @@ -146,6 +132,8 @@ async def test_state_reporting(hass):
# At least one member unlocking -> group unlocking
for state_1 in (
STATE_LOCKED,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
STATE_UNLOCKED,
STATE_UNLOCKING,
):
Expand All @@ -157,6 +145,8 @@ async def test_state_reporting(hass):
# At least one member unlocked -> group unlocked
for state_1 in (
STATE_LOCKED,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
STATE_UNLOCKED,
):
hass.states.async_set("lock.test1", state_1)
Expand Down

0 comments on commit 824de2e

Please sign in to comment.