diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index fe87a4e9a6bc..90f7a97c985f 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -1114,7 +1114,6 @@ async def handle_test_condition( vol.Required("condition"): cv.CONDITION_SCHEMA, } ) -@decorators.require_admin @decorators.async_response async def handle_subscribe_condition( hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any] diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 1b145c38c5ff..925a33fe3572 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -2945,6 +2945,32 @@ async def test_test_condition( assert msg["result"]["result"] is False +async def test_test_condition_requires_admin( + hass: HomeAssistant, + websocket_client: MockHAClientWebSocket, + hass_admin_user: MockUser, +) -> None: + """Test testing a condition requires admin.""" + hass_admin_user.groups = [] + hass.states.async_set("hello.world", "paulus") + + await websocket_client.send_json_auto_id( + { + "type": "test_condition", + "condition": { + "condition": "state", + "entity_id": "hello.world", + "state": "paulus", + }, + } + ) + + msg = await websocket_client.receive_json() + assert msg["type"] == const.TYPE_RESULT + assert not msg["success"] + assert msg["error"]["code"] == const.ERR_UNAUTHORIZED + + @pytest.mark.parametrize( ("value_template", "expected_template_errors"), [ @@ -3114,6 +3140,36 @@ async def test_subscribe_condition( } +async def test_subscribe_condition_non_admin( + hass: HomeAssistant, + websocket_client: MockHAClientWebSocket, + hass_admin_user: MockUser, +) -> None: + """Test subscribing to a condition does not require admin.""" + hass_admin_user.groups = [] + hass.states.async_set("hello.world", "paulus") + + await websocket_client.send_json_auto_id( + { + "type": "subscribe_condition", + "condition": { + "condition": "state", + "entity_id": "hello.world", + "state": "paulus", + }, + } + ) + + msg = await websocket_client.receive_json() + assert msg["type"] == const.TYPE_RESULT + assert msg["success"] + + subscription_id = msg["id"] + + msg = await websocket_client.receive_json() + assert msg == {"id": subscription_id, "type": "event", "event": {"result": True}} + + @pytest.mark.parametrize( ("value_template", "expected_event"), [