Add icon support to entity

This commit is contained in:
Paulus Schoutsen committed 2015-11-03 00:20:48 -08:00
1 parent 77f4fc8c22
commit 4d069323f4
4 files changed
+29 -12

No files matched your search

+8 -8
View File
@@ -9,7 +9,7 @@ https://home-assistant.io/components/zone.html
import logging
from homeassistant.const import (
ATTR_HIDDEN, ATTR_LATITUDE, ATTR_LONGITUDE, CONF_NAME)
ATTR_HIDDEN, ATTR_ICON, ATTR_LATITUDE, ATTR_LONGITUDE, CONF_NAME)
from homeassistant.helpers import extract_domain_configs, generate_entity_id
from homeassistant.helpers.entity import Entity
from homeassistant.util.location import distance
@@ -25,8 +25,7 @@ DEFAULT_NAME = 'Unnamed zone'
ATTR_RADIUS = 'radius'
DEFAULT_RADIUS = 100
ATTR_ICON = 'icon'
ICON_HOME = 'home'
ICON_HOME = 'mdi:home'
def active_zone(hass, latitude, longitude, radius=0):
@@ -110,7 +109,7 @@ class Zone(Entity):
self.latitude = latitude
self.longitude = longitude
self.radius = radius
self.icon = icon
self._icon = icon
def should_poll(self):
return False
@@ -124,14 +123,15 @@ class Zone(Entity):
""" The state property really does nothing for a zone. """
return STATE
@property
def icon(self):
return self._icon
@property
def state_attributes(self):
attr = {
return {
ATTR_HIDDEN: True,
ATTR_LATITUDE: self.latitude,
ATTR_LONGITUDE: self.longitude,
ATTR_RADIUS: self.radius,
}
if self.icon:
attr[ATTR_ICON] = self.icon
return attr