* Add cloud webhook support * Simplify payload * Add cloud http api tests * Fix tests * Lint * Handle cloud webhooks * Fix things * Fix name * Rename it to cloudhook * Final rename * Final final rename? * Fix docstring * More tests * Lint * Add types * Fix things
25 lines
693 B
Python
25 lines
693 B
Python
"""Cloud APIs."""
|
|
from functools import wraps
|
|
|
|
from . import auth_api
|
|
|
|
|
|
def _check_token(func):
|
|
"""Decorate a function to verify valid token."""
|
|
@wraps(func)
|
|
async def check_token(cloud, *args):
|
|
"""Validate token, then call func."""
|
|
await cloud.hass.async_add_executor_job(auth_api.check_token, cloud)
|
|
return await func(cloud, *args)
|
|
|
|
return check_token
|
|
|
|
|
|
@_check_token
|
|
async def async_create_cloudhook(cloud):
|
|
"""Create a cloudhook."""
|
|
websession = cloud.hass.helpers.aiohttp_client.async_get_clientsession()
|
|
return await websession.post(
|
|
cloud.cloudhook_create_url, headers={
|
|
'authorization': cloud.id_token
|
|
})
|