diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 907033ae52c..e8af836422e 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -87,6 +87,8 @@ from urllib.parse import urlparse, parse_qs import homeassistant as ha import homeassistant.remote as rem import homeassistant.util as util +from homeassistant.components import (STATE_ON, STATE_OFF, + SERVICE_TURN_ON, SERVICE_TURN_OFF) HTTP_OK = 200 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 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): @@ -328,6 +331,10 @@ class RequestHandler(BaseHTTPRequestHandler): " href='/static/style.css'>" "" + "" + "" "" "" "
" @@ -363,13 +370,20 @@ class RequestHandler(BaseHTTPRequestHandler): ["{}: {}".format(attr, state.attributes[attr]) for attr in state.attributes]) - write(("" - "{}{}{}{}" - "").format( - entity_id, - state.state, - attributes, - util.datetime_to_str(state.last_changed))) + write("{}{}".format(entity_id, state.state)) + + if state.state == STATE_ON or state.state == STATE_OFF: + if state.state == STATE_ON: + action = SERVICE_TURN_OFF + else: + action = SERVICE_TURN_ON + + write((" (change)").format(action, state.entity_id)) + + write("{}{}".format( + attributes, util.datetime_to_str(state.last_changed))) # Change state form write(("{}{}".format( - domain, ", ".join(services))) + write("{}".format(domain)) + + for index, service in enumerate(services): + if index > 0: + write(", ") + + write("{1}".format( + domain, service)) + + write("") write(("
" @@ -408,7 +430,7 @@ class RequestHandler(BaseHTTPRequestHandler): " Call Service" "
" "
" + " class='form-horizontal form-call-service'>" "" "
" diff --git a/homeassistant/components/http/www_static/script.js b/homeassistant/components/http/www_static/script.js new file mode 100644 index 00000000000..8f1ccd6b06d --- /dev/null +++ b/homeassistant/components/http/www_static/script.js @@ -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') +}) \ No newline at end of file diff --git a/homeassistant/components/http/www_static/style.css b/homeassistant/components/http/www_static/style.css index 2cfabf2ff88..f116e2cb763 100644 --- a/homeassistant/components/http/www_static/style.css +++ b/homeassistant/components/http/www_static/style.css @@ -30,10 +30,14 @@ border-top-right-radius: 0; } -.form-fire-event { +.form-fire-event, .form-call-service { margin-bottom: 0px; } .form-fire-event .form-group:last-child { margin-bottom: 0; +} + +*[data-service] { + text-decoration: dashed; } \ No newline at end of file