Add service to change visibility of a group (#3998)
This commit is contained in:
1 parent
3f6a5564ad
commit
33e46b484f
7 files changed
+106
-9
No files matched your search
@@ -352,3 +352,23 @@ class TestComponentsGroup(unittest.TestCase):
|
||||
assert self.hass.states.entity_ids() == ['group.light']
|
||||
grp.stop()
|
||||
assert self.hass.states.entity_ids() == []
|
||||
|
||||
def test_changing_group_visibility(self):
|
||||
"""Test that a group can be hidden and shown."""
|
||||
setup_component(self.hass, 'group', {
|
||||
'group': {
|
||||
'test_group': 'hello.world,sensor.happy'
|
||||
}
|
||||
})
|
||||
|
||||
group_entity_id = group.ENTITY_ID_FORMAT.format('test_group')
|
||||
|
||||
# Hide the group
|
||||
group.set_visibility(self.hass, group_entity_id, False)
|
||||
group_state = self.hass.states.get(group_entity_id)
|
||||
self.assertTrue(group_state.attributes.get(ATTR_HIDDEN))
|
||||
|
||||
# Show it again
|
||||
group.set_visibility(self.hass, group_entity_id, True)
|
||||
group_state = self.hass.states.get(group_entity_id)
|
||||
self.assertIsNone(group_state.attributes.get(ATTR_HIDDEN))
|
||||
@@ -7,6 +7,7 @@ from unittest.mock import patch, Mock
|
||||
|
||||
import homeassistant.core as ha
|
||||
import homeassistant.loader as loader
|
||||
from homeassistant.components import group
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers import discovery
|
||||
@@ -205,6 +206,20 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
||||
assert ['test_domain.test_2'] == \
|
||||
[ent.entity_id for ent in component.extract_from_service(call)]
|
||||
|
||||
def test_extract_from_service_no_group_expand(self):
|
||||
"""Test not expanding a group."""
|
||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||
test_group = group.Group.create_group(
|
||||
self.hass, 'test_group', ['light.Ceiling', 'light.Kitchen'])
|
||||
component.add_entities([test_group])
|
||||
|
||||
call = ha.ServiceCall('test', 'service', {
|
||||
'entity_id': ['group.test_group']
|
||||
})
|
||||
|
||||
extracted = component.extract_from_service(call, expand_group=False)
|
||||
self.assertEqual([test_group], extracted)
|
||||
|
||||
def test_setup_loads_platforms(self):
|
||||
"""Test the loading of the platforms."""
|
||||
component_setup = Mock(return_value=True)
|
||||
|
||||
@@ -153,3 +153,6 @@ class TestServiceHelpers(unittest.TestCase):
|
||||
|
||||
self.assertEqual(['light.ceiling', 'light.kitchen'],
|
||||
service.extract_entity_ids(self.hass, call))
|
||||
|
||||
self.assertEqual(['group.test'], service.extract_entity_ids(
|
||||
self.hass, call, expand_group=False))
|
||||
Reference in new issue
Block a user