Style fixes in home-assistant-api.html

pull/19/head
Paulus Schoutsen 2014-12-13 22:29:05 -08:00
parent e2b434b24e
commit f8223053bd
1 changed files with 20 additions and 20 deletions

View File

@ -112,7 +112,7 @@
} else { } else {
return 0; return 0;
} }
}) });
}, },
_pushNewState: function(new_state) { _pushNewState: function(new_state) {
@ -136,7 +136,7 @@
this._sortStates(this.states); this._sortStates(this.states);
} }
this.fire('states-updated') this.fire('states-updated');
}, },
// call api methods // call api methods
@ -149,7 +149,7 @@
fetchState: function(entityId) { fetchState: function(entityId) {
var successStateUpdate = function(new_state) { var successStateUpdate = function(new_state) {
this._pushNewState(new_state); this._pushNewState(new_state);
} };
this.call_api("GET", "states/" + entityId, null, successStateUpdate.bind(this)); this.call_api("GET", "states/" + entityId, null, successStateUpdate.bind(this));
}, },
@ -162,14 +162,14 @@
return new State(json, this); return new State(json, this);
}.bind(this)); }.bind(this));
this.fire('states-updated') this.fire('states-updated');
this._laterFetchStates(); this._laterFetchStates();
if(onSuccess) { if(onSuccess) {
onSuccess(this.states); onSuccess(this.states);
} }
} };
this.call_api( this.call_api(
"GET", "states", null, successStatesUpdate.bind(this), onError); "GET", "states", null, successStatesUpdate.bind(this), onError);
@ -179,12 +179,12 @@
var successEventsUpdated = function(events) { var successEventsUpdated = function(events) {
this.events = events; this.events = events;
this.fire('events-updated') this.fire('events-updated');
if(onSuccess) { if(onSuccess) {
onSuccess(events); onSuccess(events);
} }
} };
this.call_api( this.call_api(
"GET", "events", null, successEventsUpdated.bind(this), onError); "GET", "events", null, successEventsUpdated.bind(this), onError);
@ -194,12 +194,12 @@
var successServicesUpdated = function(services) { var successServicesUpdated = function(services) {
this.services = services; this.services = services;
this.fire('services-updated') this.fire('services-updated');
if(onSuccess) { if(onSuccess) {
onSuccess(this.services); onSuccess(this.services);
} }
} };
this.call_api( this.call_api(
"GET", "services", null, successServicesUpdated.bind(this), onError); "GET", "services", null, successServicesUpdated.bind(this), onError);
@ -210,11 +210,11 @@
}, },
turn_off: function(entity_id) { turn_off: function(entity_id) {
this.call_service("homeassistant", "turn_off", {entity_id: entity_id}) this.call_service("homeassistant", "turn_off", {entity_id: entity_id});
}, },
set_state: function(entity_id, state, attributes) { set_state: function(entity_id, state, attributes) {
var payload = {state: state} var payload = {state: state};
if(attributes) { if(attributes) {
payload.attributes = attributes; payload.attributes = attributes;
@ -223,7 +223,7 @@
var successToast = function(new_state) { var successToast = function(new_state) {
this.showToast("State of "+entity_id+" set to "+state+"."); this.showToast("State of "+entity_id+" set to "+state+".");
this._pushNewState(new_state); this._pushNewState(new_state);
} };
this.call_api("POST", "states/" + entity_id, this.call_api("POST", "states/" + entity_id,
payload, successToast.bind(this)); payload, successToast.bind(this));
@ -249,19 +249,19 @@
if(typeof(parameters.entity_id === "string")) { if(typeof(parameters.entity_id === "string")) {
// if it is a group, fetch all // if it is a group, fetch all
if(parameters.entity_id.slice(0,6) == "group.") { if(parameters.entity_id.slice(0,6) == "group.") {
update_func = this.fetchStates update_func = this.fetchStates;
} else { } else {
update_func = function() { update_func = function() {
this.fetchState(parameters.entity_id); this.fetchState(parameters.entity_id);
} };
} }
} else { } else {
update_func = this.fetchStates update_func = this.fetchStates;
} }
setTimeout(update_func.bind(this), 1000); setTimeout(update_func.bind(this), 1000);
} }
} };
this.call_api("POST", "services/" + domain + "/" + service, this.call_api("POST", "services/" + domain + "/" + service,
parameters, successToast.bind(this)); parameters, successToast.bind(this));
@ -272,7 +272,7 @@
var successToast = function() { var successToast = function() {
this.showToast("Event "+eventType+" fired."); this.showToast("Event "+eventType+" fired.");
} };
this.call_api("POST", "events/" + eventType, this.call_api("POST", "events/" + eventType,
eventData, successToast.bind(this)); eventData, successToast.bind(this));
@ -280,7 +280,7 @@
call_api: function(method, path, parameters, onSuccess, onError) { call_api: function(method, path, parameters, onSuccess, onError) {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open(method, "/api/" + path, true) req.open(method, "/api/" + path, true);
req.setRequestHeader("X-HA-access", this.auth); req.setRequestHeader("X-HA-access", this.auth);
req.onreadystatechange = function() { req.onreadystatechange = function() {
@ -299,7 +299,7 @@
} }
}.bind(this) }.bind(this);
if(parameters) { if(parameters) {
req.send(JSON.stringify(parameters)); req.send(JSON.stringify(parameters));
@ -312,7 +312,7 @@
showEditStateDialog: function(entityId) { showEditStateDialog: function(entityId) {
var state = this.getState(entityId); var state = this.getState(entityId);
this.showSetStateDialog(entityId, state.state, state.attributes) this.showSetStateDialog(entityId, state.state, state.attributes);
}, },
showSetStateDialog: function(entityId, state, stateAttributes) { showSetStateDialog: function(entityId, state, stateAttributes) {