mirror of
https://github.com/home-assistant/core.git
synced 2025-05-02 05:07:52 +00:00
update html5 to async/await (#12895)
This commit is contained in:
parent
53cc3262bd
commit
ae257651bf
@ -4,7 +4,6 @@ HTML5 Push Messaging notification service.
|
|||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/notify.html5/
|
https://home-assistant.io/components/notify.html5/
|
||||||
"""
|
"""
|
||||||
import asyncio
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -155,11 +154,10 @@ class HTML5PushRegistrationView(HomeAssistantView):
|
|||||||
self.registrations = registrations
|
self.registrations = registrations
|
||||||
self.json_path = json_path
|
self.json_path = json_path
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def post(self, request):
|
||||||
def post(self, request):
|
|
||||||
"""Accept the POST request for push registrations from a browser."""
|
"""Accept the POST request for push registrations from a browser."""
|
||||||
try:
|
try:
|
||||||
data = yield from request.json()
|
data = await request.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
@ -177,8 +175,8 @@ class HTML5PushRegistrationView(HomeAssistantView):
|
|||||||
try:
|
try:
|
||||||
hass = request.app['hass']
|
hass = request.app['hass']
|
||||||
|
|
||||||
yield from hass.async_add_job(save_json, self.json_path,
|
await hass.async_add_job(save_json, self.json_path,
|
||||||
self.registrations)
|
self.registrations)
|
||||||
return self.json_message(
|
return self.json_message(
|
||||||
'Push notification subscriber registered.')
|
'Push notification subscriber registered.')
|
||||||
except HomeAssistantError:
|
except HomeAssistantError:
|
||||||
@ -199,11 +197,10 @@ class HTML5PushRegistrationView(HomeAssistantView):
|
|||||||
return key
|
return key
|
||||||
return ensure_unique_string('unnamed device', self.registrations)
|
return ensure_unique_string('unnamed device', self.registrations)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def delete(self, request):
|
||||||
def delete(self, request):
|
|
||||||
"""Delete a registration."""
|
"""Delete a registration."""
|
||||||
try:
|
try:
|
||||||
data = yield from request.json()
|
data = await request.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
@ -225,8 +222,8 @@ class HTML5PushRegistrationView(HomeAssistantView):
|
|||||||
try:
|
try:
|
||||||
hass = request.app['hass']
|
hass = request.app['hass']
|
||||||
|
|
||||||
yield from hass.async_add_job(save_json, self.json_path,
|
await hass.async_add_job(save_json, self.json_path,
|
||||||
self.registrations)
|
self.registrations)
|
||||||
except HomeAssistantError:
|
except HomeAssistantError:
|
||||||
self.registrations[found] = reg
|
self.registrations[found] = reg
|
||||||
return self.json_message(
|
return self.json_message(
|
||||||
@ -296,15 +293,14 @@ class HTML5PushCallbackView(HomeAssistantView):
|
|||||||
status_code=HTTP_UNAUTHORIZED)
|
status_code=HTTP_UNAUTHORIZED)
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def post(self, request):
|
||||||
def post(self, request):
|
|
||||||
"""Accept the POST request for push registrations event callback."""
|
"""Accept the POST request for push registrations event callback."""
|
||||||
auth_check = self.check_authorization_header(request)
|
auth_check = self.check_authorization_header(request)
|
||||||
if not isinstance(auth_check, dict):
|
if not isinstance(auth_check, dict):
|
||||||
return auth_check
|
return auth_check
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = yield from request.json()
|
data = await request.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
return self.json_message('Invalid JSON', HTTP_BAD_REQUEST)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user