diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index a87deaa76d5..17e8cb3391b 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -20,7 +20,7 @@ import homeassistant import homeassistant.loader as loader import homeassistant.components as core_components import homeassistant.components.group as group -from homeassistant.helpers.entity import Entity +from homeassistant.helpers.entity import VisibilityABC from homeassistant.const import ( EVENT_COMPONENT_LOADED, CONF_LATITUDE, CONF_LONGITUDE, CONF_TEMPERATURE_UNIT, CONF_NAME, CONF_TIME_ZONE, TEMP_CELCIUS, @@ -208,7 +208,7 @@ def process_ha_core_config(hass, config): if key in config: setattr(hass.config, attr, config[key]) - Entity.visibility.update(config.get('visibility', {})) + VisibilityABC.visibility.update(config.get('visibility', {})) if CONF_TEMPERATURE_UNIT in config: unit = config[CONF_TEMPERATURE_UNIT] diff --git a/homeassistant/components/group.py b/homeassistant/components/group.py index 5c1e8268865..d3b4d628842 100644 --- a/homeassistant/components/group.py +++ b/homeassistant/components/group.py @@ -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 diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 7d6ef65e1a7..737a0e5e359 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -12,7 +12,40 @@ from homeassistant.const import ( STATE_OFF, DEVICE_DEFAULT_NAME, TEMP_CELCIUS, TEMP_FAHRENHEIT) -class Entity(object): +class VisibilityABC(object): + """ + Abstract Class for including visibility logic. This class includes the + necessary methods and properties to consider a visibility suggestion form + the component and then determine visibility based on the options in the + configuration file. When using this abstract class, the value for the + hidden property must still be included in the attributes disctionary. The + Entity class takes care of this automatically. + """ + + entity_id = None + visibility = {} + _hidden = False + + @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) + + +class Entity(VisibilityABC): """ ABC for Home Assistant entities. """ # pylint: disable=no-self-use @@ -20,8 +53,6 @@ class Entity(object): # The properties and methods here are safe to overwrite when inherting this # class. These may be used to customize the behavior of the entity. - _hidden = False # suggestion as to whether the entity should be hidden - @property def should_poll(self): """ @@ -83,7 +114,6 @@ class Entity(object): hass = None entity_id = None - visibility = {} def update_ha_state(self, force_refresh=False): """ @@ -130,24 +160,6 @@ class Entity(object): def __repr__(self): return "".format(self.name, self.state) - @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) - class ToggleEntity(Entity): """ ABC for entities that can be turned on and off. """