Expose loaded components on the API

This commit is contained in:
Paulus Schoutsen 2015-01-31 19:08:50 -08:00
parent 3709840327
commit c75447bc66
4 changed files with 35 additions and 2 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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";

View File

@ -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"