Debug interface now has JS to help call services
parent
bb337fa0a9
commit
69882ff4cf
|
@ -87,6 +87,8 @@ from urllib.parse import urlparse, parse_qs
|
||||||
import homeassistant as ha
|
import homeassistant as ha
|
||||||
import homeassistant.remote as rem
|
import homeassistant.remote as rem
|
||||||
import homeassistant.util as util
|
import homeassistant.util as util
|
||||||
|
from homeassistant.components import (STATE_ON, STATE_OFF,
|
||||||
|
SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
||||||
|
|
||||||
HTTP_OK = 200
|
HTTP_OK = 200
|
||||||
HTTP_CREATED = 201
|
HTTP_CREATED = 201
|
||||||
|
@ -122,7 +124,8 @@ def setup(hass, api_password, server_port=None, server_host=None):
|
||||||
|
|
||||||
# If no local api set, set one with known information
|
# If no local api set, set one with known information
|
||||||
if isinstance(hass, rem.HomeAssistant) and hass.local_api is None:
|
if isinstance(hass, rem.HomeAssistant) and hass.local_api is None:
|
||||||
hass.local_api = rem.API(util.get_local_ip(), api_password, server_port)
|
hass.local_api = \
|
||||||
|
rem.API(util.get_local_ip(), api_password, server_port)
|
||||||
|
|
||||||
|
|
||||||
class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
|
class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
|
||||||
|
@ -328,6 +331,10 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||||
" href='/static/style.css'>"
|
" href='/static/style.css'>"
|
||||||
"<link rel='icon' href='/static/favicon.ico' "
|
"<link rel='icon' href='/static/favicon.ico' "
|
||||||
" type='image/x-icon' />"
|
" type='image/x-icon' />"
|
||||||
|
"<script src='http://code.jquery.com/jquery-2.1.1.min.js'>"
|
||||||
|
" </script>"
|
||||||
|
"<script type='text/javascript' src='/static/script.js'>"
|
||||||
|
" </script>"
|
||||||
"</head>"
|
"</head>"
|
||||||
"<body>"
|
"<body>"
|
||||||
"<div class='container'>"
|
"<div class='container'>"
|
||||||
|
@ -363,13 +370,20 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||||
["{}: {}".format(attr, state.attributes[attr])
|
["{}: {}".format(attr, state.attributes[attr])
|
||||||
for attr in state.attributes])
|
for attr in state.attributes])
|
||||||
|
|
||||||
write(("<tr>"
|
write("<tr><td>{}</td><td>{}".format(entity_id, state.state))
|
||||||
"<td>{}</td><td>{}</td><td>{}</td><td>{}</td>"
|
|
||||||
"</tr>").format(
|
if state.state == STATE_ON or state.state == STATE_OFF:
|
||||||
entity_id,
|
if state.state == STATE_ON:
|
||||||
state.state,
|
action = SERVICE_TURN_OFF
|
||||||
attributes,
|
else:
|
||||||
util.datetime_to_str(state.last_changed)))
|
action = SERVICE_TURN_ON
|
||||||
|
|
||||||
|
write((" (<a data-service='homeassistant/{}' "
|
||||||
|
"data-entity_id='{}' data-service-autofire='1' "
|
||||||
|
"href='#'>change</a>)").format(action, state.entity_id))
|
||||||
|
|
||||||
|
write("</td><td>{}</td><td>{}</td></tr>".format(
|
||||||
|
attributes, util.datetime_to_str(state.last_changed)))
|
||||||
|
|
||||||
# Change state form
|
# Change state form
|
||||||
write(("<tr><td><input name='entity_id' class='form-control' "
|
write(("<tr><td><input name='entity_id' class='form-control' "
|
||||||
|
@ -397,8 +411,16 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
for domain, services in sorted(
|
for domain, services in sorted(
|
||||||
self.server.hass.services.services.items()):
|
self.server.hass.services.services.items()):
|
||||||
write("<tr><td>{}</td><td>{}</td></tr>".format(
|
write("<tr><td>{}</td><td>".format(domain))
|
||||||
domain, ", ".join(services)))
|
|
||||||
|
for index, service in enumerate(services):
|
||||||
|
if index > 0:
|
||||||
|
write(", ")
|
||||||
|
|
||||||
|
write("<a href='#' data-service='{0}/{1}'>{1}</a>".format(
|
||||||
|
domain, service))
|
||||||
|
|
||||||
|
write("</td></tr>")
|
||||||
|
|
||||||
write(("</table></div></div>"
|
write(("</table></div></div>"
|
||||||
|
|
||||||
|
@ -408,7 +430,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||||
" Call Service</h2></div>"
|
" Call Service</h2></div>"
|
||||||
"<div class='panel-body'>"
|
"<div class='panel-body'>"
|
||||||
"<form method='post' action='/call_service' "
|
"<form method='post' action='/call_service' "
|
||||||
" class='form-horizontal form-fire-event'>"
|
" class='form-horizontal form-call-service'>"
|
||||||
"<input type='hidden' name='api_password' value='{}'>"
|
"<input type='hidden' name='api_password' value='{}'>"
|
||||||
|
|
||||||
"<div class='form-group'>"
|
"<div class='form-group'>"
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
// from http://stackoverflow.com/questions/1403888/get-escaped-url-parameter
|
||||||
|
function getURLParameter(name) {
|
||||||
|
return decodeURI(
|
||||||
|
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
$("[data-service]").click(function() {
|
||||||
|
var form = $(".form-call-service");
|
||||||
|
|
||||||
|
var el = $(this);
|
||||||
|
var parts = el.attr("data-service").split("/");
|
||||||
|
|
||||||
|
form.find("#domain").val(parts[0]);
|
||||||
|
form.find("#service").val(parts[1]);
|
||||||
|
|
||||||
|
var entity_id = el.attr("data-entity_id");
|
||||||
|
|
||||||
|
if(entity_id) {
|
||||||
|
form.find("#service_data").val(JSON.stringify({entity_id: entity_id}));
|
||||||
|
} else {
|
||||||
|
form.find("#service_data").val("");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(el.attr("data-service-autofire")) {
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}).css('cursor', 'pointer')
|
||||||
|
})
|
|
@ -30,10 +30,14 @@
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-fire-event {
|
.form-fire-event, .form-call-service {
|
||||||
margin-bottom: 0px;
|
margin-bottom: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-fire-event .form-group:last-child {
|
.form-fire-event .form-group:last-child {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
*[data-service] {
|
||||||
|
text-decoration: dashed;
|
||||||
}
|
}
|
Loading…
Reference in New Issue