diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index 4c0e9c315f1..2bbb9516517 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -12,7 +12,7 @@ from homeassistant.helpers import TrackStates import homeassistant.remote as rem from homeassistant.const import ( URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES, - URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY) + URL_API_EVENT_FORWARD, URL_API_STATES_ENTITY, URL_API_COMPONENTS) HTTP_OK = 200 HTTP_CREATED = 201 @@ -73,6 +73,10 @@ def setup(hass, config): hass.http.register_path( 'DELETE', URL_API_EVENT_FORWARD, _handle_delete_api_event_forward) + # /components + hass.http.register_path( + 'GET', URL_API_COMPONENTS, _handle_get_api_components) + return True @@ -247,3 +251,9 @@ def _handle_delete_api_event_forward(handler, path_match, data): handler.server.event_forwarder.disconnect(api) handler.write_json_message("Event forwarding cancelled.") + + +def _handle_get_api_components(handler, path_match, data): + """ Returns all the loaded components. """ + + handler.write_json(handler.server.hass.components) diff --git a/homeassistant/components/frontend/www_static/polymer/home-assistant-api.html b/homeassistant/components/frontend/www_static/polymer/home-assistant-api.html index 901b0e444ac..11f8a7959c5 100644 --- a/homeassistant/components/frontend/www_static/polymer/home-assistant-api.html +++ b/homeassistant/components/frontend/www_static/polymer/home-assistant-api.html @@ -179,6 +179,10 @@ return found.length > 0; }, + hasComponent: function(component) { + return this.components.indexOf(component) !== -1; + }, + getCustomGroups: function() { return this.states.filter(function(state) { return state.isCustomGroup;}); }, @@ -267,6 +271,7 @@ this.fetchStates(); this.fetchServices(); this.fetchEvents(); + this.fetchComponents(); }, fetchState: function(entityId) { @@ -322,6 +327,22 @@ "GET", "services", null, successServicesUpdated.bind(this), onError); }, + fetchComponents: function(onSuccess, onError) { + var successComponentsUpdated = function(components) { + this.components = components; + + this.fire('components-updated'); + + if(onSuccess) { + onSuccess(this.components); + } + }; + + this.call_api( + "GET", "components", null, + successComponentsUpdated.bind(this), onError); + }, + turn_on: function(entity_id, options) { this.call_service( "homeassistant", "turn_on", {entity_id: entity_id}, options); diff --git a/homeassistant/components/frontend/www_static/polymer/splash-login.html b/homeassistant/components/frontend/www_static/polymer/splash-login.html index 9062d2a966d..2dd7c9f0d47 100644 --- a/homeassistant/components/frontend/www_static/polymer/splash-login.html +++ b/homeassistant/components/frontend/www_static/polymer/splash-login.html @@ -127,8 +127,9 @@ this.$.hideKeyboardOnFocus.focus(); var passwordValid = function(result) { - this.$.validatemessage.innerHTML = "Loading data..."; + this.$.validatemessage.innerHTML = "Loading data…"; this.api.fetchEvents(); + this.api.fetchComponents(); this.api.fetchStates(function() { this.state = "valid_auth"; diff --git a/homeassistant/const.py b/homeassistant/const.py index 31c575b96c7..d4ca0009d83 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -99,3 +99,4 @@ URL_API_EVENTS_EVENT = "/api/events/{}" URL_API_SERVICES = "/api/services" URL_API_SERVICES_SERVICE = "/api/services/{}/{}" URL_API_EVENT_FORWARD = "/api/event_forwarding" +URL_API_COMPONENTS = "/api/components"