commit
9bf8835190
|
@ -12,6 +12,7 @@ import threading
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
|
from homeassistant.exceptions import TemplateError
|
||||||
from homeassistant.helpers.state import TrackStates
|
from homeassistant.helpers.state import TrackStates
|
||||||
import homeassistant.remote as rem
|
import homeassistant.remote as rem
|
||||||
from homeassistant.util import template
|
from homeassistant.util import template
|
||||||
|
@ -377,11 +378,16 @@ def _handle_post_api_template(handler, path_match, data):
|
||||||
""" Log user out. """
|
""" Log user out. """
|
||||||
template_string = data.get('template', '')
|
template_string = data.get('template', '')
|
||||||
|
|
||||||
handler.send_response(HTTP_OK)
|
try:
|
||||||
handler.send_header(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_TEXT_PLAIN)
|
rendered = template.render(handler.server.hass, template_string)
|
||||||
handler.end_headers()
|
|
||||||
handler.wfile.write(
|
handler.send_response(HTTP_OK)
|
||||||
template.render(handler.server.hass, template_string).encode('utf-8'))
|
handler.send_header(HTTP_HEADER_CONTENT_TYPE, CONTENT_TYPE_TEXT_PLAIN)
|
||||||
|
handler.end_headers()
|
||||||
|
handler.wfile.write(rendered.encode('utf-8'))
|
||||||
|
except TemplateError as e:
|
||||||
|
handler.write_json_message(str(e), HTTP_UNPROCESSABLE_ENTITY)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def _services_json(hass):
|
def _services_json(hass):
|
||||||
|
|
|
@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
FRONTEND_URLS = [
|
FRONTEND_URLS = [
|
||||||
URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState',
|
URL_ROOT, '/logbook', '/history', '/map', '/devService', '/devState',
|
||||||
'/devEvent', '/devInfo', '/states']
|
'/devEvent', '/devInfo', '/devTemplate', '/states']
|
||||||
|
|
||||||
_FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
|
_FINGERPRINT = re.compile(r'^(\w+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<meta name='viewport' content='width=device-width, user-scalable=no'>
|
<meta name='viewport' content='width=device-width, user-scalable=no'>
|
||||||
<meta name='theme-color' content='#03a9f4'>
|
<meta name='theme-color' content='#03a9f4'>
|
||||||
<style>
|
<style>
|
||||||
#init {
|
#ha-init-skeleton {
|
||||||
display: -webkit-flex;
|
display: -webkit-flex;
|
||||||
display: flex;
|
display: flex;
|
||||||
-webkit-flex-direction: column;
|
-webkit-flex-direction: column;
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
<link rel='import' href='/static/{{ app_url }}' async>
|
<link rel='import' href='/static/{{ app_url }}' async>
|
||||||
</head>
|
</head>
|
||||||
<body fullbleed>
|
<body fullbleed>
|
||||||
<div id='init'><img src='/static/favicon-192x192.png' height='192'></div>
|
<div id='ha-init-skeleton'><img src='/static/favicon-192x192.png' height='192'></div>
|
||||||
<script>
|
<script>
|
||||||
var webComponentsSupported = ('registerElement' in document &&
|
var webComponentsSupported = ('registerElement' in document &&
|
||||||
'import' in document.createElement('link') &&
|
'import' in document.createElement('link') &&
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||||
VERSION = "0d8516cd9a13ee2ae3f27c702777e028"
|
VERSION = "be08c5a3ce12040bbdba2db83cb1a568"
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
Subproject commit e19f3c5e34bc2f5e5bd2dcc1444bb569fb1c0c68
|
Subproject commit 50aadaf880a9cb36bf144540171ff5fa029e9eaf
|
File diff suppressed because one or more lines are too long
|
@ -337,10 +337,20 @@ class TestAPI(unittest.TestCase):
|
||||||
'{{ states.sensor.temperature.state }}'}),
|
'{{ states.sensor.temperature.state }}'}),
|
||||||
headers=HA_HEADERS)
|
headers=HA_HEADERS)
|
||||||
|
|
||||||
hass.pool.block_till_done()
|
|
||||||
|
|
||||||
self.assertEqual('10', req.text)
|
self.assertEqual('10', req.text)
|
||||||
|
|
||||||
|
def test_api_template_error(self):
|
||||||
|
""" Test template API. """
|
||||||
|
hass.states.set('sensor.temperature', 10)
|
||||||
|
|
||||||
|
req = requests.post(
|
||||||
|
_url(const.URL_API_TEMPLATE),
|
||||||
|
data=json.dumps({"template":
|
||||||
|
'{{ states.sensor.temperature.state'}),
|
||||||
|
headers=HA_HEADERS)
|
||||||
|
|
||||||
|
self.assertEqual(422, req.status_code)
|
||||||
|
|
||||||
def test_api_event_forward(self):
|
def test_api_event_forward(self):
|
||||||
""" Test setting up event forwarding. """
|
""" Test setting up event forwarding. """
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue