Add require_admin decorator to otbr WS API (#89385)

* Add require_admin decorator to otbr WS API

* Add require_admin decorator to forgotten otbr WS API
This commit is contained in:
Erik Montnemery 2023-03-08 19:21:04 +01:00 committed by GitHub
parent 7d97653895
commit 7232a0a786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,12 +3,7 @@ from typing import TYPE_CHECKING
import python_otbr_api
from homeassistant.components.websocket_api import (
ActiveConnection,
async_register_command,
async_response,
websocket_command,
)
from homeassistant.components import websocket_api
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
@ -21,18 +16,19 @@ if TYPE_CHECKING:
@callback
def async_setup(hass: HomeAssistant) -> None:
"""Set up the OTBR Websocket API."""
async_register_command(hass, websocket_info)
async_register_command(hass, websocket_create_network)
websocket_api.async_register_command(hass, websocket_info)
websocket_api.async_register_command(hass, websocket_create_network)
@websocket_command(
@websocket_api.websocket_command(
{
"type": "otbr/info",
}
)
@async_response
@websocket_api.require_admin
@websocket_api.async_response
async def websocket_info(
hass: HomeAssistant, connection: ActiveConnection, msg: dict
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
) -> None:
"""Get OTBR info."""
if DOMAIN not in hass.data:
@ -56,14 +52,15 @@ async def websocket_info(
)
@websocket_command(
@websocket_api.websocket_command(
{
"type": "otbr/create_network",
}
)
@async_response
@websocket_api.require_admin
@websocket_api.async_response
async def websocket_create_network(
hass: HomeAssistant, connection: ActiveConnection, msg: dict
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict
) -> None:
"""Create a new Thread network."""
if DOMAIN not in hass.data: