Switch group to use None for the state unknown case (#40792)
This commit is contained in:
parent
082f866620
commit
42ad36e9f8
2 changed files with 6 additions and 7 deletions
|
@ -20,7 +20,6 @@ from homeassistant.const import (
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNKNOWN,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import CoreState, callback, split_entity_id
|
from homeassistant.core import CoreState, callback, split_entity_id
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -428,7 +427,7 @@ class Group(Entity):
|
||||||
"""
|
"""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = STATE_UNKNOWN
|
self._state = None
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
self._set_tracked(entity_ids)
|
self._set_tracked(entity_ids)
|
||||||
self._on_off = None
|
self._on_off = None
|
||||||
|
@ -621,7 +620,7 @@ class Group(Entity):
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Query all members and determine current group state."""
|
"""Query all members and determine current group state."""
|
||||||
self._state = STATE_UNKNOWN
|
self._state = None
|
||||||
self._async_update_group_state()
|
self._async_update_group_state()
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
|
@ -719,9 +718,9 @@ class Group(Entity):
|
||||||
if num_on_states == 1:
|
if num_on_states == 1:
|
||||||
on_state = list(self._on_states)[0]
|
on_state = list(self._on_states)[0]
|
||||||
# If we do not have an on state for any domains
|
# If we do not have an on state for any domains
|
||||||
# we use STATE_UNKNOWN
|
# we use None (which will be STATE_UNKNOWN)
|
||||||
elif num_on_states == 0:
|
elif num_on_states == 0:
|
||||||
self._state = STATE_UNKNOWN
|
self._state = None
|
||||||
return
|
return
|
||||||
# If the entity domains have more than one
|
# If the entity domains have more than one
|
||||||
# on state, we use STATE_ON/STATE_OFF
|
# on state, we use STATE_ON/STATE_OFF
|
||||||
|
|
|
@ -67,13 +67,13 @@ class TestComponentsGroup(unittest.TestCase):
|
||||||
self.hass, "chromecasts", ["cast.living_room", "cast.bedroom"]
|
self.hass, "chromecasts", ["cast.living_room", "cast.bedroom"]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert STATE_UNKNOWN == grp.state
|
assert grp.state is None
|
||||||
|
|
||||||
def test_setup_empty_group(self):
|
def test_setup_empty_group(self):
|
||||||
"""Try to set up an empty group."""
|
"""Try to set up an empty group."""
|
||||||
grp = group.Group.create_group(self.hass, "nothing", [])
|
grp = group.Group.create_group(self.hass, "nothing", [])
|
||||||
|
|
||||||
assert STATE_UNKNOWN == grp.state
|
assert grp.state is None
|
||||||
|
|
||||||
def test_monitor_group(self):
|
def test_monitor_group(self):
|
||||||
"""Test if the group keeps track of states."""
|
"""Test if the group keeps track of states."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue