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 75e5ddfe30
.
* Changed hide_switch to control
This commit is contained in:
parent
97cc76b43e
commit
cf0ff54d14
2 changed files with 20 additions and 6 deletions
|
@ -29,11 +29,13 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
|||
|
||||
CONF_ENTITIES = 'entities'
|
||||
CONF_VIEW = 'view'
|
||||
CONF_CONTROL = 'control'
|
||||
|
||||
ATTR_AUTO = 'auto'
|
||||
ATTR_ORDER = 'order'
|
||||
ATTR_VIEW = 'view'
|
||||
ATTR_VISIBLE = 'visible'
|
||||
ATTR_CONTROL = 'control'
|
||||
|
||||
SERVICE_SET_VISIBILITY = 'set_visibility'
|
||||
SET_VISIBILITY_SERVICE_SCHEMA = vol.Schema({
|
||||
|
@ -61,6 +63,7 @@ CONFIG_SCHEMA = vol.Schema({
|
|||
CONF_VIEW: cv.boolean,
|
||||
CONF_NAME: cv.string,
|
||||
CONF_ICON: cv.icon,
|
||||
CONF_CONTROL: cv.string,
|
||||
}, cv.match_all))
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
|
@ -206,11 +209,13 @@ def _async_process_config(hass, config, component):
|
|||
entity_ids = conf.get(CONF_ENTITIES) or []
|
||||
icon = conf.get(CONF_ICON)
|
||||
view = conf.get(CONF_VIEW)
|
||||
control = conf.get(CONF_CONTROL)
|
||||
|
||||
# Don't create tasks and await them all. The order is important as
|
||||
# groups get a number based on creation order.
|
||||
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)
|
||||
|
||||
if groups:
|
||||
|
@ -221,7 +226,7 @@ class Group(Entity):
|
|||
"""Track a group of entity ids."""
|
||||
|
||||
def __init__(self, hass, name, order=None, user_defined=True, icon=None,
|
||||
view=False):
|
||||
view=False, control=None):
|
||||
"""Initialize a group.
|
||||
|
||||
This Object has factory function for creation.
|
||||
|
@ -239,20 +244,22 @@ class Group(Entity):
|
|||
self._assumed_state = False
|
||||
self._async_unsub_state_changed = None
|
||||
self._visible = True
|
||||
self._control = control
|
||||
|
||||
@staticmethod
|
||||
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."""
|
||||
return run_coroutine_threadsafe(
|
||||
Group.async_create_group(hass, name, entity_ids, user_defined,
|
||||
icon, view, object_id),
|
||||
icon, view, control, object_id),
|
||||
hass.loop).result()
|
||||
|
||||
@staticmethod
|
||||
@asyncio.coroutine
|
||||
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.
|
||||
|
||||
This method must be run in the event loop.
|
||||
|
@ -260,7 +267,8 @@ class Group(Entity):
|
|||
group = Group(
|
||||
hass, name,
|
||||
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(
|
||||
ENTITY_ID_FORMAT, object_id or name, hass=hass)
|
||||
|
@ -319,6 +327,8 @@ class Group(Entity):
|
|||
data[ATTR_AUTO] = True
|
||||
if self._view:
|
||||
data[ATTR_VIEW] = True
|
||||
if self._control:
|
||||
data[ATTR_CONTROL] = self._control
|
||||
return data
|
||||
|
||||
@property
|
||||
|
|
|
@ -228,6 +228,7 @@ class TestComponentsGroup(unittest.TestCase):
|
|||
'entities': 'light.Bowl, ' + test_group.entity_id,
|
||||
'icon': 'mdi:work',
|
||||
'view': True,
|
||||
'control': 'hidden',
|
||||
}
|
||||
group_conf['test_group'] = 'hello.world,sensor.happy'
|
||||
group_conf['empty_group'] = {'name': 'Empty Group', 'entities': None}
|
||||
|
@ -243,6 +244,8 @@ class TestComponentsGroup(unittest.TestCase):
|
|||
self.assertEqual('mdi:work',
|
||||
group_state.attributes.get(ATTR_ICON))
|
||||
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.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(ATTR_ICON))
|
||||
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.assertEqual(2, group_state.attributes.get(group.ATTR_ORDER))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue