mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Add option to hide the group card switch (#4631)
* Add option to hide the group card switch * Disallow control of hidden group switches * Revert "Disallow control of hidden group switches" This reverts commit 75e5ddfe3092327647e2873cb03ccf3b4a75b85a. * Changed hide_switch to control
This commit is contained in:
parent
97cc76b43e
commit
cf0ff54d14
@ -29,11 +29,13 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
|||||||
|
|
||||||
CONF_ENTITIES = 'entities'
|
CONF_ENTITIES = 'entities'
|
||||||
CONF_VIEW = 'view'
|
CONF_VIEW = 'view'
|
||||||
|
CONF_CONTROL = 'control'
|
||||||
|
|
||||||
ATTR_AUTO = 'auto'
|
ATTR_AUTO = 'auto'
|
||||||
ATTR_ORDER = 'order'
|
ATTR_ORDER = 'order'
|
||||||
ATTR_VIEW = 'view'
|
ATTR_VIEW = 'view'
|
||||||
ATTR_VISIBLE = 'visible'
|
ATTR_VISIBLE = 'visible'
|
||||||
|
ATTR_CONTROL = 'control'
|
||||||
|
|
||||||
SERVICE_SET_VISIBILITY = 'set_visibility'
|
SERVICE_SET_VISIBILITY = 'set_visibility'
|
||||||
SET_VISIBILITY_SERVICE_SCHEMA = vol.Schema({
|
SET_VISIBILITY_SERVICE_SCHEMA = vol.Schema({
|
||||||
@ -61,6 +63,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
CONF_VIEW: cv.boolean,
|
CONF_VIEW: cv.boolean,
|
||||||
CONF_NAME: cv.string,
|
CONF_NAME: cv.string,
|
||||||
CONF_ICON: cv.icon,
|
CONF_ICON: cv.icon,
|
||||||
|
CONF_CONTROL: cv.string,
|
||||||
}, cv.match_all))
|
}, cv.match_all))
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
@ -206,11 +209,13 @@ def _async_process_config(hass, config, component):
|
|||||||
entity_ids = conf.get(CONF_ENTITIES) or []
|
entity_ids = conf.get(CONF_ENTITIES) or []
|
||||||
icon = conf.get(CONF_ICON)
|
icon = conf.get(CONF_ICON)
|
||||||
view = conf.get(CONF_VIEW)
|
view = conf.get(CONF_VIEW)
|
||||||
|
control = conf.get(CONF_CONTROL)
|
||||||
|
|
||||||
# Don't create tasks and await them all. The order is important as
|
# Don't create tasks and await them all. The order is important as
|
||||||
# groups get a number based on creation order.
|
# groups get a number based on creation order.
|
||||||
group = yield from Group.async_create_group(
|
group = yield from Group.async_create_group(
|
||||||
hass, name, entity_ids, icon=icon, view=view, object_id=object_id)
|
hass, name, entity_ids, icon=icon, view=view,
|
||||||
|
control=control, object_id=object_id)
|
||||||
groups.append(group)
|
groups.append(group)
|
||||||
|
|
||||||
if groups:
|
if groups:
|
||||||
@ -221,7 +226,7 @@ class Group(Entity):
|
|||||||
"""Track a group of entity ids."""
|
"""Track a group of entity ids."""
|
||||||
|
|
||||||
def __init__(self, hass, name, order=None, user_defined=True, icon=None,
|
def __init__(self, hass, name, order=None, user_defined=True, icon=None,
|
||||||
view=False):
|
view=False, control=None):
|
||||||
"""Initialize a group.
|
"""Initialize a group.
|
||||||
|
|
||||||
This Object has factory function for creation.
|
This Object has factory function for creation.
|
||||||
@ -239,20 +244,22 @@ class Group(Entity):
|
|||||||
self._assumed_state = False
|
self._assumed_state = False
|
||||||
self._async_unsub_state_changed = None
|
self._async_unsub_state_changed = None
|
||||||
self._visible = True
|
self._visible = True
|
||||||
|
self._control = control
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_group(hass, name, entity_ids=None, user_defined=True,
|
def create_group(hass, name, entity_ids=None, user_defined=True,
|
||||||
icon=None, view=False, object_id=None):
|
icon=None, view=False, control=None, object_id=None):
|
||||||
"""Initialize a group."""
|
"""Initialize a group."""
|
||||||
return run_coroutine_threadsafe(
|
return run_coroutine_threadsafe(
|
||||||
Group.async_create_group(hass, name, entity_ids, user_defined,
|
Group.async_create_group(hass, name, entity_ids, user_defined,
|
||||||
icon, view, object_id),
|
icon, view, control, object_id),
|
||||||
hass.loop).result()
|
hass.loop).result()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_create_group(hass, name, entity_ids=None, user_defined=True,
|
def async_create_group(hass, name, entity_ids=None, user_defined=True,
|
||||||
icon=None, view=False, object_id=None):
|
icon=None, view=False, control=None,
|
||||||
|
object_id=None):
|
||||||
"""Initialize a group.
|
"""Initialize a group.
|
||||||
|
|
||||||
This method must be run in the event loop.
|
This method must be run in the event loop.
|
||||||
@ -260,7 +267,8 @@ class Group(Entity):
|
|||||||
group = Group(
|
group = Group(
|
||||||
hass, name,
|
hass, name,
|
||||||
order=len(hass.states.async_entity_ids(DOMAIN)),
|
order=len(hass.states.async_entity_ids(DOMAIN)),
|
||||||
user_defined=user_defined, icon=icon, view=view)
|
user_defined=user_defined, icon=icon, view=view,
|
||||||
|
control=control)
|
||||||
|
|
||||||
group.entity_id = async_generate_entity_id(
|
group.entity_id = async_generate_entity_id(
|
||||||
ENTITY_ID_FORMAT, object_id or name, hass=hass)
|
ENTITY_ID_FORMAT, object_id or name, hass=hass)
|
||||||
@ -319,6 +327,8 @@ class Group(Entity):
|
|||||||
data[ATTR_AUTO] = True
|
data[ATTR_AUTO] = True
|
||||||
if self._view:
|
if self._view:
|
||||||
data[ATTR_VIEW] = True
|
data[ATTR_VIEW] = True
|
||||||
|
if self._control:
|
||||||
|
data[ATTR_CONTROL] = self._control
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -228,6 +228,7 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
'entities': 'light.Bowl, ' + test_group.entity_id,
|
'entities': 'light.Bowl, ' + test_group.entity_id,
|
||||||
'icon': 'mdi:work',
|
'icon': 'mdi:work',
|
||||||
'view': True,
|
'view': True,
|
||||||
|
'control': 'hidden',
|
||||||
}
|
}
|
||||||
group_conf['test_group'] = 'hello.world,sensor.happy'
|
group_conf['test_group'] = 'hello.world,sensor.happy'
|
||||||
group_conf['empty_group'] = {'name': 'Empty Group', 'entities': None}
|
group_conf['empty_group'] = {'name': 'Empty Group', 'entities': None}
|
||||||
@ -243,6 +244,8 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
self.assertEqual('mdi:work',
|
self.assertEqual('mdi:work',
|
||||||
group_state.attributes.get(ATTR_ICON))
|
group_state.attributes.get(ATTR_ICON))
|
||||||
self.assertTrue(group_state.attributes.get(group.ATTR_VIEW))
|
self.assertTrue(group_state.attributes.get(group.ATTR_VIEW))
|
||||||
|
self.assertEqual('hidden',
|
||||||
|
group_state.attributes.get(group.ATTR_CONTROL))
|
||||||
self.assertTrue(group_state.attributes.get(ATTR_HIDDEN))
|
self.assertTrue(group_state.attributes.get(ATTR_HIDDEN))
|
||||||
self.assertEqual(1, group_state.attributes.get(group.ATTR_ORDER))
|
self.assertEqual(1, group_state.attributes.get(group.ATTR_ORDER))
|
||||||
|
|
||||||
@ -254,6 +257,7 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
self.assertIsNone(group_state.attributes.get(group.ATTR_AUTO))
|
self.assertIsNone(group_state.attributes.get(group.ATTR_AUTO))
|
||||||
self.assertIsNone(group_state.attributes.get(ATTR_ICON))
|
self.assertIsNone(group_state.attributes.get(ATTR_ICON))
|
||||||
self.assertIsNone(group_state.attributes.get(group.ATTR_VIEW))
|
self.assertIsNone(group_state.attributes.get(group.ATTR_VIEW))
|
||||||
|
self.assertIsNone(group_state.attributes.get(group.ATTR_CONTROL))
|
||||||
self.assertIsNone(group_state.attributes.get(ATTR_HIDDEN))
|
self.assertIsNone(group_state.attributes.get(ATTR_HIDDEN))
|
||||||
self.assertEqual(2, group_state.attributes.get(group.ATTR_ORDER))
|
self.assertEqual(2, group_state.attributes.get(group.ATTR_ORDER))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user