Skip to content

Commit

Permalink
Added support for entity pictures
Browse files Browse the repository at this point in the history
balloob committed Nov 2, 2014
1 parent f946261 commit 1bab576
Showing 8 changed files with 259 additions and 143 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/__init__.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@
# String with a friendly name for the entity
ATTR_FRIENDLY_NAME = "friendly_name"

# A picture to represent entity
ATTR_ENTITY_PICTURE = "entity_picture"

STATE_ON = 'on'
STATE_OFF = 'off'
STATE_HOME = 'home'
13 changes: 9 additions & 4 deletions homeassistant/components/demo.py
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
import homeassistant as ha
import homeassistant.components.group as group
from homeassistant.components import (SERVICE_TURN_ON, SERVICE_TURN_OFF,
STATE_ON, STATE_OFF, get_component,
extract_entity_ids)
STATE_ON, STATE_OFF, ATTR_ENTITY_PICTURE,
get_component, extract_entity_ids)
from homeassistant.components.light import (ATTR_XY_COLOR, ATTR_BRIGHTNESS,
GROUP_NAME_ALL_LIGHTS)
from homeassistant.util import split_entity_id
@@ -92,8 +92,13 @@ def mock_turn_off(service):
hass.states.set("process.XBMC", STATE_ON)

# Setup device tracker
hass.states.set("device_tracker.Paulus", "home")
hass.states.set("device_tracker.Anne_Therese", "not_home")
hass.states.set("device_tracker.Paulus", "home",
{ATTR_ENTITY_PICTURE:
"http://graph.facebook.com/schoutsen/picture"})
hass.states.set("device_tracker.Anne_Therese", "not_home",
{ATTR_ENTITY_PICTURE:
"http://graph.facebook.com/anne.t.frederiksen/picture"})

hass.states.set("group.all_devices", "home",
{
"auto": True,
25 changes: 19 additions & 6 deletions homeassistant/components/device_tracker.py
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ def setup(hass, config):

conf = config[DOMAIN]

if not ha.CONF_TYPE in conf:
if ha.CONF_TYPE not in conf:
logger.error(
'Missing required configuration item in {}: {}'.format(
DOMAIN, ha.CONF_TYPE))
@@ -175,7 +175,8 @@ def update_devices(self, found_devices=None):
known_dev[device]['last_seen'] = now

self.states.set(
known_dev[device]['entity_id'], components.STATE_HOME)
known_dev[device]['entity_id'], components.STATE_HOME,
known_dev[device]['default_state_attr'])

# For all devices we did not find, set state to NH
# But only if they have been gone for longer then the error time span
@@ -185,7 +186,8 @@ def update_devices(self, found_devices=None):
if now - known_dev[device]['last_seen'] > self.error_scanning:

self.states.set(known_dev[device]['entity_id'],
components.STATE_NOT_HOME)
components.STATE_NOT_HOME,
known_dev[device]['default_state_attr'])

# If we come along any unknown devices we will write them to the
# known devices file but only if we did not encounter an invalid
@@ -211,17 +213,19 @@ def update_devices(self, found_devices=None):
writer = csv.writer(outp)

if is_new_file:
writer.writerow(("device", "name", "track"))
writer.writerow((
"device", "name", "track", "picture"))

for device in unknown_devices:
# See if the device scanner knows the name
# else defaults to unknown device
name = (self.device_scanner.get_device_name(device)
or "unknown_device")

writer.writerow((device, name, 0))
writer.writerow((device, name, 0, ""))
known_dev[device] = {'name': name,
'track': False}
'track': False,
'picture': ""}

except IOError:
self.logger.exception((
@@ -253,6 +257,13 @@ def _read_known_devices_file(self):

row['track'] = True if row['track'] == '1' else False

if row['picture']:
row['default_state_attr'] = {
components.ATTR_ENTITY_PICTURE: row['picture']}

else:
row['default_state_attr'] = None

# If we track this device setup tracking variables
if row['track']:
row['last_seen'] = default_last_seen
@@ -276,6 +287,8 @@ def _read_known_devices_file(self):
row['entity_id'] = entity_id
used_entity_ids.append(entity_id)

row['picture'] = row['picture']

known_devices[device] = row

if not known_devices:
2 changes: 1 addition & 1 deletion homeassistant/components/http/frontend.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_polymer script """
VERSION = "0be01a612c785f83a9631d97b54d069a"
VERSION = "a460b05ee24f1e2372c820c552e815c3"
Loading

0 comments on commit 1bab576

Please sign in to comment.