From 72b4212b19b32b3afa399ba087497ca9096b7061 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 3 Nov 2015 00:19:28 -0800 Subject: [PATCH 1/4] Demo uses device tracker demo platform --- homeassistant/components/demo.py | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/demo.py b/homeassistant/components/demo.py index 388a869ae0c..7c873e834bd 100644 --- a/homeassistant/components/demo.py +++ b/homeassistant/components/demo.py @@ -10,14 +10,15 @@ import homeassistant.core as ha import homeassistant.bootstrap as bootstrap import homeassistant.loader as loader from homeassistant.const import ( - CONF_PLATFORM, ATTR_ENTITY_PICTURE, ATTR_ENTITY_ID, ATTR_FRIENDLY_NAME) + CONF_PLATFORM, ATTR_ENTITY_ID) DOMAIN = "demo" -DEPENDENCIES = ['introduction', 'conversation'] +DEPENDENCIES = ['conversation', 'introduction', 'zone'] COMPONENTS_WITH_DEMO_PLATFORM = [ - 'switch', 'light', 'sensor', 'thermostat', 'media_player', 'notify'] + 'device_tracker', 'light', 'media_player', 'notify', 'switch', 'sensor', + 'thermostat'] def setup(hass, config): @@ -110,25 +111,6 @@ def setup(hass, config): }}, ]}) - # Setup fake device tracker - hass.states.set("device_tracker.paulus", "home", - {ATTR_ENTITY_PICTURE: - "http://graph.facebook.com/297400035/picture", - ATTR_FRIENDLY_NAME: 'Paulus'}) - hass.states.set("device_tracker.anne_therese", "not_home", - {ATTR_FRIENDLY_NAME: 'Anne Therese', - 'latitude': hass.config.latitude + 0.002, - 'longitude': hass.config.longitude + 0.002}) - - hass.states.set("group.all_devices", "home", - { - "auto": True, - ATTR_ENTITY_ID: [ - "device_tracker.paulus", - "device_tracker.anne_therese" - ] - }) - # Setup configurator configurator_ids = [] From 77f4fc8c2228e5acdb579161307dee181eacbe2f Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 3 Nov 2015 00:20:20 -0800 Subject: [PATCH 2/4] Frontend: Add materialdesignicons --- homeassistant/components/frontend/__init__.py | 3 +- .../components/frontend/index.html.template | 2 +- .../components/frontend/mdi_version.py | 2 + .../components/frontend/www_static/mdi.html | 1 + script/update_mdi.py | 92 +++++++++++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 homeassistant/components/frontend/mdi_version.py create mode 100644 homeassistant/components/frontend/www_static/mdi.html create mode 100755 script/update_mdi.py diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index a15244ac52f..d51a7623767 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -8,7 +8,7 @@ import re import os import logging -from . import version +from . import version, mdi_version import homeassistant.util as util from homeassistant.const import URL_ROOT, HTTP_OK from homeassistant.config import get_default_config_dir @@ -74,6 +74,7 @@ def _handle_get_root(handler, path_match, data): template_html = template_html.replace('{{ app_url }}', app_url) template_html = template_html.replace('{{ auth }}', auth) + template_html = template_html.replace('{{ icons }}', mdi_version.VERSION) handler.wfile.write(template_html.encode("UTF-8")) diff --git a/homeassistant/components/frontend/index.html.template b/homeassistant/components/frontend/index.html.template index 8906e8902a0..409ea6752db 100644 --- a/homeassistant/components/frontend/index.html.template +++ b/homeassistant/components/frontend/index.html.template @@ -46,6 +46,6 @@ - + diff --git a/homeassistant/components/frontend/mdi_version.py b/homeassistant/components/frontend/mdi_version.py new file mode 100644 index 00000000000..c9d06a4b300 --- /dev/null +++ b/homeassistant/components/frontend/mdi_version.py @@ -0,0 +1,2 @@ +""" DO NOT MODIFY. Auto-generated by update_mdi script """ +VERSION = "38EF63D0474411E4B3CF842B2B6CFE1B" diff --git a/homeassistant/components/frontend/www_static/mdi.html b/homeassistant/components/frontend/www_static/mdi.html new file mode 100644 index 00000000000..42212a3a301 --- /dev/null +++ b/homeassistant/components/frontend/www_static/mdi.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/script/update_mdi.py b/script/update_mdi.py new file mode 100755 index 00000000000..f7899be3964 --- /dev/null +++ b/script/update_mdi.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +""" +Downloads the latest Polymer v1 iconset version for materialdesignicons.com +""" + +import os +import re +import requests +import sys + +GETTING_STARTED_URL = ('https://raw.githubusercontent.com/Templarian/' + 'MaterialDesign/master/site/getting-started.savvy') +DOWNLOAD_LINK = re.compile(r'(/api/download/polymer/v1/([A-Z0-9-]{36}))') +START_ICONSET = ' Date: Tue, 3 Nov 2015 00:20:48 -0800 Subject: [PATCH 3/4] Add icon support to entity --- homeassistant/components/switch/demo.py | 12 +++++++++--- homeassistant/components/zone.py | 16 ++++++++-------- homeassistant/const.py | 3 +++ homeassistant/helpers/entity.py | 10 +++++++++- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/switch/demo.py b/homeassistant/components/switch/demo.py index 4ee1dc82413..16676cb239e 100644 --- a/homeassistant/components/switch/demo.py +++ b/homeassistant/components/switch/demo.py @@ -12,16 +12,17 @@ from homeassistant.const import DEVICE_DEFAULT_NAME def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Find and return demo switches. """ add_devices_callback([ - DemoSwitch('Decorative Lights', True), - DemoSwitch('AC', False) + DemoSwitch('Decorative Lights', True, None), + DemoSwitch('AC', False, 'mdi:air-conditioner') ]) class DemoSwitch(SwitchDevice): """ Provides a demo switch. """ - def __init__(self, name, state): + def __init__(self, name, state, icon): self._name = name or DEVICE_DEFAULT_NAME self._state = state + self._icon = icon @property def should_poll(self): @@ -33,6 +34,11 @@ class DemoSwitch(SwitchDevice): """ Returns the name of the device if any. """ return self._name + @property + def icon(self): + """ Returns the icon to use for device if any. """ + return self._icon + @property def current_power_mwh(self): """ Current power usage in mwh. """ diff --git a/homeassistant/components/zone.py b/homeassistant/components/zone.py index 9ec7829316d..e978d963c5a 100644 --- a/homeassistant/components/zone.py +++ b/homeassistant/components/zone.py @@ -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 diff --git a/homeassistant/const.py b/homeassistant/const.py index 49825cee094..7762f4acc6a 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -74,6 +74,9 @@ ATTR_FRIENDLY_NAME = "friendly_name" # A picture to represent entity ATTR_ENTITY_PICTURE = "entity_picture" +# Icon to use in the frontend +ATTR_ICON = "icon" + # The unit of measurement if applicable ATTR_UNIT_OF_MEASUREMENT = "unit_of_measurement" diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 82dafac5576..fd2611889c9 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -10,7 +10,7 @@ from collections import defaultdict from homeassistant.exceptions import NoEntitySpecifiedError from homeassistant.const import ( - ATTR_FRIENDLY_NAME, ATTR_HIDDEN, ATTR_UNIT_OF_MEASUREMENT, + ATTR_FRIENDLY_NAME, ATTR_HIDDEN, ATTR_UNIT_OF_MEASUREMENT, ATTR_ICON, DEVICE_DEFAULT_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, TEMP_CELCIUS, TEMP_FAHRENHEIT) @@ -61,6 +61,11 @@ class Entity(object): """ Unit of measurement of this entity, if any. """ return None + @property + def icon(self): + """ Icon to use in the frontend, if any. """ + return None + @property def hidden(self): """ Suggestion if the entity should be hidden from UIs. """ @@ -102,6 +107,9 @@ class Entity(object): if ATTR_UNIT_OF_MEASUREMENT not in attr and self.unit_of_measurement: attr[ATTR_UNIT_OF_MEASUREMENT] = self.unit_of_measurement + if ATTR_ICON not in attr and self.icon: + attr[ATTR_ICON] = self.icon + if self.hidden: attr[ATTR_HIDDEN] = self.hidden From be6dd2023617603495f654299820c9d2cfd7af81 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 3 Nov 2015 00:20:59 -0800 Subject: [PATCH 4/4] Update frontend with new icons --- homeassistant/components/frontend/version.py | 2 +- .../frontend/www_static/frontend.html | 1546 +++++++++-------- .../www_static/home-assistant-polymer | 2 +- 3 files changed, 784 insertions(+), 766 deletions(-) diff --git a/homeassistant/components/frontend/version.py b/homeassistant/components/frontend/version.py index 1c753d1638e..1012508d53f 100644 --- a/homeassistant/components/frontend/version.py +++ b/homeassistant/components/frontend/version.py @@ -1,2 +1,2 @@ """ DO NOT MODIFY. Auto-generated by build_frontend script """ -VERSION = "beb922c55bb26ea576581b453f6d7c04" +VERSION = "5e61b80689feebb3a7043de07fc01971" diff --git a/homeassistant/components/frontend/www_static/frontend.html b/homeassistant/components/frontend/www_static/frontend.html index 7343bd3afd0..5d68c878b66 100644 --- a/homeassistant/components/frontend/www_static/frontend.html +++ b/homeassistant/components/frontend/www_static/frontend.html @@ -1,6 +1,6 @@ -