Expose loaded components on the API
This commit is contained in:
parent
3709840327
commit
c75447bc66
4 changed files with 35 additions and 2 deletions
|
@ -12,7 +12,7 @@ from homeassistant.helpers import TrackStates
|
||||||
import homeassistant.remote as rem
|
import homeassistant.remote as rem
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
URL_API, URL_API_STATES, URL_API_EVENTS, URL_API_SERVICES,
|
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_OK = 200
|
||||||
HTTP_CREATED = 201
|
HTTP_CREATED = 201
|
||||||
|
@ -73,6 +73,10 @@ def setup(hass, config):
|
||||||
hass.http.register_path(
|
hass.http.register_path(
|
||||||
'DELETE', URL_API_EVENT_FORWARD, _handle_delete_api_event_forward)
|
'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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,3 +251,9 @@ def _handle_delete_api_event_forward(handler, path_match, data):
|
||||||
handler.server.event_forwarder.disconnect(api)
|
handler.server.event_forwarder.disconnect(api)
|
||||||
|
|
||||||
handler.write_json_message("Event forwarding cancelled.")
|
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)
|
||||||
|
|
|
@ -179,6 +179,10 @@
|
||||||
return found.length > 0;
|
return found.length > 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
hasComponent: function(component) {
|
||||||
|
return this.components.indexOf(component) !== -1;
|
||||||
|
},
|
||||||
|
|
||||||
getCustomGroups: function() {
|
getCustomGroups: function() {
|
||||||
return this.states.filter(function(state) { return state.isCustomGroup;});
|
return this.states.filter(function(state) { return state.isCustomGroup;});
|
||||||
},
|
},
|
||||||
|
@ -267,6 +271,7 @@
|
||||||
this.fetchStates();
|
this.fetchStates();
|
||||||
this.fetchServices();
|
this.fetchServices();
|
||||||
this.fetchEvents();
|
this.fetchEvents();
|
||||||
|
this.fetchComponents();
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchState: function(entityId) {
|
fetchState: function(entityId) {
|
||||||
|
@ -322,6 +327,22 @@
|
||||||
"GET", "services", null, successServicesUpdated.bind(this), onError);
|
"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) {
|
turn_on: function(entity_id, options) {
|
||||||
this.call_service(
|
this.call_service(
|
||||||
"homeassistant", "turn_on", {entity_id: entity_id}, options);
|
"homeassistant", "turn_on", {entity_id: entity_id}, options);
|
||||||
|
|
|
@ -127,8 +127,9 @@
|
||||||
this.$.hideKeyboardOnFocus.focus();
|
this.$.hideKeyboardOnFocus.focus();
|
||||||
|
|
||||||
var passwordValid = function(result) {
|
var passwordValid = function(result) {
|
||||||
this.$.validatemessage.innerHTML = "Loading data...";
|
this.$.validatemessage.innerHTML = "Loading data…";
|
||||||
this.api.fetchEvents();
|
this.api.fetchEvents();
|
||||||
|
this.api.fetchComponents();
|
||||||
|
|
||||||
this.api.fetchStates(function() {
|
this.api.fetchStates(function() {
|
||||||
this.state = "valid_auth";
|
this.state = "valid_auth";
|
||||||
|
|
|
@ -99,3 +99,4 @@ URL_API_EVENTS_EVENT = "/api/events/{}"
|
||||||
URL_API_SERVICES = "/api/services"
|
URL_API_SERVICES = "/api/services"
|
||||||
URL_API_SERVICES_SERVICE = "/api/services/{}/{}"
|
URL_API_SERVICES_SERVICE = "/api/services/{}/{}"
|
||||||
URL_API_EVENT_FORWARD = "/api/event_forwarding"
|
URL_API_EVENT_FORWARD = "/api/event_forwarding"
|
||||||
|
URL_API_COMPONENTS = "/api/components"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue