Moved card visibility logic out of the Entity class and into a VisibilityABC. Then made the Group class inherit the VisibilityABC. No duplication of code now. This is definitely better.
This commit is contained in:
1 parent
8fcf814eb6
commit
ff3dacedc0
3 files changed
+38
-48
No files matched your search
@@ -7,7 +7,7 @@ Provides functionality to group devices that can be turned on or off.
|
||||
|
||||
import homeassistant as ha
|
||||
from homeassistant.helpers import generate_entity_id
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity import VisibilityABC
|
||||
import homeassistant.util as util
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME, STATE_ON, STATE_OFF,
|
||||
@@ -111,12 +111,8 @@ def setup(hass, config):
|
||||
return True
|
||||
|
||||
|
||||
class Group(object):
|
||||
class Group(VisibilityABC):
|
||||
""" Tracks a group of entity ids. """
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
|
||||
visibility = Entity.visibility
|
||||
_hidden = False
|
||||
|
||||
def __init__(self, hass, name, entity_ids=None, user_defined=True):
|
||||
self.hass = hass
|
||||
@@ -220,24 +216,6 @@ class Group(object):
|
||||
self.hass.states.set(
|
||||
self.entity_id, group_off, self.state_attr)
|
||||
|
||||
@property
|
||||
def hidden(self):
|
||||
"""
|
||||
Returns the official decision of whether the entity should be hidden.
|
||||
Any value set by the user in the configuration file will overwrite
|
||||
whatever the component sets for visibility.
|
||||
"""
|
||||
if self.entity_id is not None and \
|
||||
self.entity_id.lower() in self.visibility:
|
||||
return self.visibility[self.entity_id.lower()] == 'hide'
|
||||
else:
|
||||
return self._hidden
|
||||
|
||||
@hidden.setter
|
||||
def hidden(self, val):
|
||||
""" Sets the suggestion for visibility. """
|
||||
self._hidden = bool(val)
|
||||
|
||||
|
||||
def setup_group(hass, name, entity_ids, user_defined=True):
|
||||
""" Sets up a group state that is the combined state of
|
||||
|
||||
Reference in new issue
Block a user