11"""Init file for HassIO supervisor rest api."""
22import logging
33
4- from .util import api_process , api_process_hostcontroll , json_loads
4+ import voluptuous as vol
5+
6+ from .util import api_process , api_process_hostcontroll , api_validate
57from ..const import ATTR_VERSION , ATTR_CURRENT , ATTR_BETA , HASSIO_VERSION
68
79_LOGGER = logging .getLogger (__name__ )
810
11+ SCHEMA_OPTIONS = vol .Schema ({
12+ # pylint: disable=no-value-for-parameter
13+ vol .Optional (ATTR_BETA ): vol .Boolean (),
14+ })
15+
16+ SCHEMA_VERSION = vol .Schema ({
17+ vol .Optional (ATTR_VERSION ): vol .Coerce (str ),
18+ })
19+
920
1021class APISupervisor (object ):
1122 """Handle rest api for supervisor functions."""
@@ -16,6 +27,11 @@ def __init__(self, config, loop, host_controll):
1627 self .loop = loop
1728 self .host_controll = host_controll
1829
30+ @api_process
31+ async def ping (self , request ):
32+ """Return ok for signal that the api is ready."""
33+ return True
34+
1935 @api_process
2036 async def info (self , request ):
2137 """Return host information."""
@@ -30,7 +46,7 @@ async def info(self, request):
3046 @api_process
3147 async def options (self , request ):
3248 """Set supervisor options."""
33- body = await request . json ( loads = json_loads )
49+ body = await api_validate ( SCHEMA_OPTIONS , request )
3450
3551 if ATTR_BETA in body :
3652 self .config .upstream_beta = body [ATTR_BETA ]
@@ -40,7 +56,7 @@ async def options(self, request):
4056 @api_process_hostcontroll
4157 async def update (self , request ):
4258 """Update host OS."""
43- body = await request . json ( loads = json_loads )
59+ body = await api_validate ( SCHEMA_VERSION , request )
4460 version = body .get (ATTR_VERSION , self .config .current_hassio )
4561
4662 if version == HASSIO_VERSION :
0 commit comments