Added decorate option to configuration file to allow a user to set custom images for different entities.
This commit is contained in:
parent
24bb89df23
commit
f77b3dbd0a
3 changed files with 22 additions and 10 deletions
|
@ -24,7 +24,8 @@ from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_COMPONENT_LOADED, CONF_LATITUDE, CONF_LONGITUDE,
|
EVENT_COMPONENT_LOADED, CONF_LATITUDE, CONF_LONGITUDE,
|
||||||
CONF_TEMPERATURE_UNIT, CONF_NAME, CONF_TIME_ZONE, CONF_VISIBILITY,
|
CONF_TEMPERATURE_UNIT, CONF_NAME, CONF_TIME_ZONE, CONF_VISIBILITY,
|
||||||
TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
CONF_DECORATE, TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_ENTITY_PICTURE,
|
||||||
|
ATTR_HIDDEN)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -209,7 +210,10 @@ def process_ha_core_config(hass, config):
|
||||||
setattr(hass.config, attr, config[key])
|
setattr(hass.config, attr, config[key])
|
||||||
|
|
||||||
for entity_id, hidden in config.get(CONF_VISIBILITY, {}).items():
|
for entity_id, hidden in config.get(CONF_VISIBILITY, {}).items():
|
||||||
Entity.overwrite_hidden(entity_id, hidden == 'hide')
|
Entity.overwrite_attribute(entity_id, ATTR_HIDDEN, hidden == 'hide')
|
||||||
|
|
||||||
|
for entity_id, image in config.get(CONF_DECORATE, {}).items():
|
||||||
|
Entity.overwrite_attribute(entity_id, ATTR_ENTITY_PICTURE, image)
|
||||||
|
|
||||||
if CONF_TEMPERATURE_UNIT in config:
|
if CONF_TEMPERATURE_UNIT in config:
|
||||||
unit = config[CONF_TEMPERATURE_UNIT]
|
unit = config[CONF_TEMPERATURE_UNIT]
|
||||||
|
|
|
@ -12,6 +12,7 @@ CONF_TEMPERATURE_UNIT = "temperature_unit"
|
||||||
CONF_NAME = "name"
|
CONF_NAME = "name"
|
||||||
CONF_TIME_ZONE = "time_zone"
|
CONF_TIME_ZONE = "time_zone"
|
||||||
CONF_VISIBILITY = "visibility"
|
CONF_VISIBILITY = "visibility"
|
||||||
|
CONF_DECORATE = "decorate"
|
||||||
|
|
||||||
CONF_PLATFORM = "platform"
|
CONF_PLATFORM = "platform"
|
||||||
CONF_HOST = "host"
|
CONF_HOST = "host"
|
||||||
|
|
|
@ -5,14 +5,17 @@ homeassistant.helpers.entity
|
||||||
Provides ABC for entities in HA.
|
Provides ABC for entities in HA.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from homeassistant import NoEntitySpecifiedError
|
from homeassistant import NoEntitySpecifiedError
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT, ATTR_HIDDEN, STATE_ON,
|
ATTR_FRIENDLY_NAME, ATTR_UNIT_OF_MEASUREMENT, ATTR_HIDDEN,
|
||||||
STATE_OFF, DEVICE_DEFAULT_NAME, TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
ATTR_ENTITY_PICTURE, STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME,
|
||||||
|
TEMP_CELCIUS, TEMP_FAHRENHEIT)
|
||||||
|
|
||||||
# Dict mapping entity_id to a boolean that overwrites the hidden property
|
# Dict mapping entity_id to a boolean that overwrites the hidden property
|
||||||
_OVERWRITE_HIDDEN = {}
|
_OVERWRITE = defaultdict(dict)
|
||||||
|
|
||||||
|
|
||||||
class Entity(object):
|
class Entity(object):
|
||||||
|
@ -121,9 +124,13 @@ class Entity(object):
|
||||||
if ATTR_UNIT_OF_MEASUREMENT not in attr and self.unit_of_measurement:
|
if ATTR_UNIT_OF_MEASUREMENT not in attr and self.unit_of_measurement:
|
||||||
attr[ATTR_UNIT_OF_MEASUREMENT] = self.unit_of_measurement
|
attr[ATTR_UNIT_OF_MEASUREMENT] = self.unit_of_measurement
|
||||||
|
|
||||||
if _OVERWRITE_HIDDEN.get(self.entity_id, self.hidden):
|
if _OVERWRITE[ATTR_HIDDEN].get(self.entity_id, self.hidden):
|
||||||
attr[ATTR_HIDDEN] = True
|
attr[ATTR_HIDDEN] = True
|
||||||
|
|
||||||
|
if _OVERWRITE[ATTR_ENTITY_PICTURE].get(self.entity_id, False):
|
||||||
|
attr[ATTR_ENTITY_PICTURE] = \
|
||||||
|
_OVERWRITE[ATTR_ENTITY_PICTURE][self.entity_id]
|
||||||
|
|
||||||
# Convert temperature if we detect one
|
# Convert temperature if we detect one
|
||||||
if attr.get(ATTR_UNIT_OF_MEASUREMENT) in (TEMP_CELCIUS,
|
if attr.get(ATTR_UNIT_OF_MEASUREMENT) in (TEMP_CELCIUS,
|
||||||
TEMP_FAHRENHEIT):
|
TEMP_FAHRENHEIT):
|
||||||
|
@ -143,15 +150,15 @@ class Entity(object):
|
||||||
return "<Entity {}: {}>".format(self.name, self.state)
|
return "<Entity {}: {}>".format(self.name, self.state)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def overwrite_hidden(entity_id, hidden):
|
def overwrite_attribute(entity_id, attr, val):
|
||||||
"""
|
"""
|
||||||
Overwrite the hidden property of an entity.
|
Overwrite the hidden property of an entity.
|
||||||
Set hidden to None to remove any overwritten value in place.
|
Set hidden to None to remove any overwritten value in place.
|
||||||
"""
|
"""
|
||||||
if hidden is None:
|
if val is None:
|
||||||
_OVERWRITE_HIDDEN.pop(entity_id, None)
|
_OVERWRITE[attr].pop(entity_id, None)
|
||||||
else:
|
else:
|
||||||
_OVERWRITE_HIDDEN[entity_id.lower()] = hidden
|
_OVERWRITE[attr][entity_id.lower()] = val
|
||||||
|
|
||||||
|
|
||||||
class ToggleEntity(Entity):
|
class ToggleEntity(Entity):
|
||||||
|
|
Loading…
Add table
Reference in a new issue